Project language changes edge-cases and localStore#1482
Open
abcampo-iry wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a snapshot-based “project changed” check (based on initial components) and uses it to refine two behaviors: (1) when to persist projects to localStorage on initial load, and (2) when to reload/replace the current project during locale changes, to avoid overwriting local edits.
Changes:
- Add
projectHasChangedSinceInitialLoadutility (plus tests) to compare current components against an initial snapshot. - Update
useProjectPersistenceto readinitialComponentsfrom Redux and avoid saving/prompting onjustLoadedwhen the project is unchanged. - Update
useProjectto avoid replacing an edited in-memory project when locale changes (plus a regression test).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/projectHelpers.js | Adds projectHasChangedSinceInitialLoad helper for snapshot-based change detection. |
| src/utils/projectHelpers.test.js | Adds unit tests covering unchanged/changed component scenarios. |
| src/hooks/useProjectPersistence.js | Uses initialComponents to skip localStorage persistence on justLoaded when unchanged. |
| src/hooks/useProjectPersistence.test.js | Updates persistence tests to cover the new “don’t save on justLoaded unless changed” behavior. |
| src/hooks/useProject.js | Adds a locale-change early-return to avoid overwriting local edits when locale differs. |
| src/hooks/useProject.test.js | Adds test ensuring locale changes don’t replace an edited current project. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
76cb16e to
06589b3
Compare
06589b3 to
f812531
Compare
f812531 to
ba28ece
Compare
ba28ece to
f2a92c6
Compare
f2a92c6 to
5caffb6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/889
This fix makes the editor reload the project when the site language changes, but only if the project has not been edited.
For example, if a project has both Spanish and English versions, switching the site from Spanish to English now loads the English project code. If the user has already changed the code, the editor keeps their local work instead of replacing it with the other language version. I've found for french is not working but i think it's because of the fallback of the server.
Screen.Recording.2026-05-27.at.12.54.18.mov