Skip to content

Project language changes edge-cases and localStore#1482

Open
abcampo-iry wants to merge 1 commit into
mainfrom
issues/889-reload-unedited-project-when-language-changes
Open

Project language changes edge-cases and localStore#1482
abcampo-iry wants to merge 1 commit into
mainfrom
issues/889-reload-unedited-project-when-language-changes

Conversation

@abcampo-iry
Copy link
Copy Markdown
Contributor

@abcampo-iry abcampo-iry commented May 27, 2026

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

@abcampo-iry abcampo-iry temporarily deployed to previews/1482/merge May 27, 2026 08:22 — with GitHub Actions Inactive
@abcampo-iry abcampo-iry self-assigned this May 27, 2026
@abcampo-iry abcampo-iry marked this pull request as ready for review May 27, 2026 08:34
Copilot AI review requested due to automatic review settings May 27, 2026 08:34
@abcampo-iry abcampo-iry marked this pull request as draft May 27, 2026 08:34
Copy link
Copy Markdown
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 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 projectHasChangedSinceInitialLoad utility (plus tests) to compare current components against an initial snapshot.
  • Update useProjectPersistence to read initialComponents from Redux and avoid saving/prompting on justLoaded when the project is unchanged.
  • Update useProject to 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.

Comment thread src/utils/projectHelpers.js
Comment thread src/hooks/useProject.js Outdated
@abcampo-iry abcampo-iry force-pushed the issues/889-reload-unedited-project-when-language-changes branch from 76cb16e to 06589b3 Compare May 27, 2026 08:47
@abcampo-iry abcampo-iry temporarily deployed to previews/1482/merge May 27, 2026 08:47 — with GitHub Actions Inactive
@abcampo-iry abcampo-iry requested a review from Copilot May 27, 2026 08:53
Copy link
Copy Markdown
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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/utils/projectHelpers.js Outdated
Copy link
Copy Markdown
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

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@abcampo-iry abcampo-iry force-pushed the issues/889-reload-unedited-project-when-language-changes branch from f812531 to ba28ece Compare May 27, 2026 10:57
@abcampo-iry abcampo-iry temporarily deployed to previews/1482/merge May 27, 2026 10:57 — with GitHub Actions Inactive
@abcampo-iry abcampo-iry marked this pull request as ready for review May 27, 2026 10:59
@abcampo-iry abcampo-iry marked this pull request as draft May 27, 2026 11:13
@abcampo-iry abcampo-iry force-pushed the issues/889-reload-unedited-project-when-language-changes branch from ba28ece to f2a92c6 Compare May 27, 2026 11:16
@abcampo-iry abcampo-iry temporarily deployed to previews/1482/merge May 27, 2026 11:16 — with GitHub Actions Inactive
@abcampo-iry abcampo-iry requested a review from Copilot May 27, 2026 13:27
@abcampo-iry abcampo-iry marked this pull request as ready for review May 27, 2026 13:27
Copy link
Copy Markdown
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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/utils/projectHelpers.js Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants