Migrate legacy localStorage entries to new 2048-prefixed keys#71
Conversation
…ration Co-authored-by: Coteh <3276350+Coteh@users.noreply.github.com>
Deploying 2048-clone with
|
| Latest commit: |
d6c45ca
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://55f23532.2048-clone-33h.pages.dev |
| Branch Preview URL: | https://copilot-migrate-local-storag.2048-clone-33h.pages.dev |
| let animationManager = new AnimationManager(); | ||
| let undoManager = new UndoManager(); | ||
| let gameStorage = new BrowserGameStorage(); | ||
| migrateLocalStorage(); |
There was a problem hiding this comment.
Can you make the function return whether a migration was performed, and if it was, then pop up a dialog box saying that a migration was done and if there's any issues then contact me at my email. (Take a look at the error dialog template for the email) Make the message user-friendly. Because of the return value, the dialog should only ever appear once, when the migration moves stuff from the old local storage entries to the new one. It should not appear again.
There was a problem hiding this comment.
Done in f652bec. migrateLocalStorage now returns true when at least one entry was migrated, and false otherwise. When true is returned, a migration notification dialog is shown (only on that first load after migration, since subsequent loads won't trigger migration). The dialog uses a new #migration-dialog-content template with a user-friendly message and a mailto link to james.cote.730@gmail.com (same email as the error dialog).
…alStorage Co-authored-by: Coteh <3276350+Coteh@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
| [LEGACY_PREFERENCES_KEY]: PREFERENCES_KEY, | ||
| }; | ||
|
|
||
| export const migrateLocalStorage = (): boolean => { |
There was a problem hiding this comment.
To make this function more context-aware and to track migrations over time, can we update the migrateLocalStorage function name to include the current version of the application? For example, if the version in package.json is 1.2.3, the function should be named migrateLocalStorage_v1_2_3.
This will help:
• Indicate the version associated with the migration logic.
• Avoid confusion if additional migrations are implemented in future versions.
Let me know what you think!
There was a problem hiding this comment.
Done in ad9d0fe. The function has been renamed to migrateLocalStorage_v1_3_1 (version read from package.json), with all references updated in src/storage/browser.ts, src/index.ts, and test/browser_storage_test.ts.
Co-authored-by: Coteh <3276350+Coteh@users.noreply.github.com>
…n dialogs using document fragments Template elements have already been using document fragments under the hood. Explicitly allowing document fragments now allows any document fragment to be used, thereby allowing multiple elements to be rendered without needing them to be parented to another element. This was done to allow for a debug dialog with an OK button that is properly spaced, (the spacing isn't so great when the span and button are parented by a div) but is really something that should be allowed in general going forward. Other Changes: - Fix migration dialog replacing feather elements before initial setup replaces them, causing the game to not load and log an error
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

When the
2048-prefix was added to localStorage keys, existing players lost access to their saved high scores, preferences, and unlockables. This adds a one-time migration that copies legacy values into the new keys on startup, without touching unrelated localStorage entries from other games on the same origin. A notification dialog is shown to the player the first (and only) time the migration runs.Changes
src/storage/browser.tsLEGACY_GAME_STATE_KEY,LEGACY_PERSISTENT_STATE_KEY,LEGACY_PREFERENCES_KEY)migrateLocalStorage_v1_3_1()— iterates the legacy→new key map and copies each value only when the legacy key exists and the new key is absent, preventing overwrites of existing new saves; returnstrueif any migration was performed,falseotherwise. The function name is versioned to indicate which app version introduced this migration and to avoid conflicts with any future migrations.index.html#migration-dialog-contenttemplate with a user-friendly message informing the player their save data was migrated, and a mailto link to contact the developer if anything looks offsrc/index.tsmigrateLocalStorage_v1_3_1()immediately afterBrowserGameStorageis instantiated; if it returnstrue, shows the migration notification dialog before game initializationtest/browser_storage_test.tstrue), no-op when new key already exists (returnsfalse), no-op when no legacy keys present (returnsfalse), partial migration when only some legacy keys exist (returnstrue)Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.