Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 14, 2025

Loading saves from newer versions may contain unsupported elements, causing undefined errors. The dialog now warns users when attempting to load a save with version > CURRENT_VERSION.

Changes

  • Added parseVersionFromSave() in src/util/save.ts

    • Safely extracts version from save strings without full validation
    • Returns undefined for invalid JSON or non-integer versions
  • Enhanced ConfirmOverwriteDialog

    • Accepts required saveVersion prop (non-optional)
    • Displays orange warning text when version exceeds current (66)
    • Preserves existing button behavior
  • Updated callers with version state management

    • open-actions.tsx: Added versionToLoad state, parses version from uploaded files and sets state before opening dialog
    • rmp-gallery-app-clip.tsx: Added versionToLoad state, uses version from loaded work object and sets state before opening dialog
  • Added translations

    • newerVersion key in all 5 supported languages with version interpolation

Implementation

Version is now stored in dedicated state variables (versionToLoad) in both components and set just before opening the ConfirmOverwriteDialog:

// In open-actions.tsx
const [versionToLoad, setVersionToLoad] = React.useState<number>(0);
// ...
setVersionToLoad(parseVersionFromSave(paramStr) ?? 0);
onConfirmOpen();

// Dialog usage
<ConfirmOverwriteDialog
    saveVersion={versionToLoad}  // Always provided, e.g., 100
    // ... other props
/>

Warning appears when saveVersion (100) > CURRENT_VERSION (66):

⚠️ This save file is from a newer version (100) than the current version (66). Loading it may cause errors or undefined behavior.

Test coverage: 14 new tests for version parsing and dialog behavior.

Original prompt

This section details on the original issue you should resolve

<issue_title>Refuse to load save with newer version</issue_title>
<issue_description>The newer version may contain some elements that are not available in the current commit. Loading it will cause an undefined error.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@thekingofcity In ConfirmOverwriteDialog, show an additional warning text content that the save is newer than the current expected version. Buttons could be left the same.

To get the open save version, we should first parse the string and just get the version field. The CURRENT_VERSION is in src\util\save.ts


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add warning for loading newer save versions Warn when loading saves from newer versions Dec 14, 2025
Copilot AI requested a review from thekingofcity December 14, 2025 12:47
Copy link
Member

@thekingofcity thekingofcity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Set saveVersion in ConfirmOverwriteDialogProps to be not undefined. There should be a state in open-actions and rmp-gallery-app-clip that contains the version to be loaded and is set just before opening the ConfirmOverwriteDialog

- Made saveVersion required (not optional) in ConfirmOverwriteDialogProps
- Added versionToLoad state in both open-actions.tsx and rmp-gallery-app-clip.tsx
- Set version state just before opening the dialog in all call sites
- Updated tests to reflect non-optional saveVersion prop
- All 137 tests pass

Co-authored-by: thekingofcity <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 15, 2025

@copilot Set saveVersion in ConfirmOverwriteDialogProps to be not undefined. There should be a state in open-actions and rmp-gallery-app-clip that contains the version to be loaded and is set just bef...

Done in commit 1158f3c.

Changed:

  • saveVersion is now required (not optional) in ConfirmOverwriteDialogProps
  • Added versionToLoad state in both open-actions.tsx and rmp-gallery-app-clip.tsx
  • Version is set via setVersionToLoad() just before calling onConfirmOpen() in all locations:
    • handleUpload() - parses version from uploaded file
    • handleLoadTutorial() - parses version from tutorial
    • fetchAndApplyTemplate() - uses version from template object
    • fetchAndApplyShare() - uses version from shared work
  • Updated tests to pass saveVersion as required prop

@thekingofcity thekingofcity marked this pull request as ready for review December 15, 2025 06:00
Copy link
Member

@thekingofcity thekingofcity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds version checking to warn users when attempting to load save files from newer versions of the application. When a save file's version exceeds the current application version (66), an orange warning message is displayed in the confirmation dialog, alerting users that loading may cause errors or undefined behavior. The implementation extracts version information early in the load process and passes it to the dialog component for display.

Key Changes

  • Added parseVersionFromSave() utility function to extract version numbers from save strings before full validation
  • Enhanced ConfirmOverwriteDialog to accept a saveVersion prop and conditionally display a warning when the version is newer than CURRENT_VERSION
  • Integrated version checking into both file upload and gallery/share import flows with dedicated state management

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/util/save.ts Adds parseVersionFromSave() function to extract version from save strings
src/util/save-version.test.ts Comprehensive test suite for version parsing (14 test cases)
src/components/page-header/confirm-overwrite-dialog.tsx Adds saveVersion prop and conditional warning display for newer versions
src/components/page-header/confirm-overwrite-dialog.test.tsx Tests for warning display behavior in different version scenarios
src/components/page-header/open-actions.tsx Adds versionToLoad state and parses version from uploaded files and tutorial
src/components/page-header/rmp-gallery-app-clip.tsx Adds versionToLoad state and extracts version from gallery/share works
src/i18n/translations/*.json Adds newerVersion translation key with interpolation in all 5 languages

@thekingofcity thekingofcity changed the title Warn when loading saves from newer versions #398 Warn when loading saves from newer versions Dec 15, 2025
@thekingofcity thekingofcity merged commit cf18998 into main Dec 15, 2025
1 check passed
@thekingofcity thekingofcity deleted the copilot/add-new-save-version-warning branch December 15, 2025 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Refuse to load save with newer version

2 participants