Skip to content

Keep unsaved Scratch work when the locale changes - #1672

Merged
jamiebenstead merged 5 commits into
mainfrom
1804-students-lose-work-if-changing-locale-before-saving-scratch-work
Oct 8, 2026
Merged

jamiebenstead merged 5 commits into
mainfrom
1804-students-lose-work-if-changing-locale-before-saving-scratch-work

Conversation

@jamiebenstead

Copy link
Copy Markdown
Contributor

closes https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/1804

  • Don't reload the Scratch project when the locale changes, because the project's unsaved work only exists inside the Scratch iframe.
  • Keep the Scratch iframe loaded and send it the new locale instead.
  • The Scratch iframe switches language in place, the same way Scratch's own language menu does.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 09:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Locale updates can be lost during iframe startup and leave request metadata using the previous locale.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Keeps unsaved Scratch iframe work intact when changing locale.

Changes:

  • Prevents Scratch project reloads on locale changes.
  • Sends locale updates to the existing iframe.
  • Applies locale changes through Scratch GUI state.
File Description
src/​hooks/​useProject.js Prevents matching Scratch projects from reloading.
src/​hooks/​useProject.test.jsx Tests Scratch project preservation.
src/​components/​Editor/​Project/​ScratchContainer.jsx Sends locale updates without changing iframe URL.
src/​components/​Editor/​Project/​ScratchContainer.test.jsx Verifies in-place locale updates.
apps/​scratch-frame/​src/​ScratchIntegrationHOC.jsx Handles locale update messages.
apps/​scratch-frame/​src/​ScratchIntegrationHOC.test.jsx Tests Scratch locale selection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread apps/scratch-frame/src/ScratchIntegrationHOC.jsx
Comment thread src/components/Editor/Project/ScratchContainer.jsx
Comment thread src/components/Editor/Project/ScratchContainer.jsx
Comment thread src/hooks/useProject.js Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

New-project navigation can use a stale project locale, and in-place language changes leave the iframe document language outdated.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Refresh initial locale when iframe project changes

src/​components/​Editor/​Project/​ScratchContainer.jsx:48

initialLocale is pinned for the entire ScratchContainer lifetime, but this component stays mounted when one Scratch project is replaced by another. If the user changes language on project A and then opens project B, iframeProjectIdentifier changes while this value remains A's original locale, so the new iframe loads B's wrong localized project copy even though its UI is switched to the latest language. Keep the locale pinned only while the iframe project identifier is unchanged, and refresh it when a genuinely new iframe project is loaded.

Comment thread apps/scratch-frame/src/ScratchIntegrationHOC.jsx

@cocomarine cocomarine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⭐

@jamiebenstead
jamiebenstead merged commit 0971e66 into main Oct 8, 2026
12 checks passed
@jamiebenstead
jamiebenstead deleted the 1804-students-lose-work-if-changing-locale-before-saving-scratch-work branch October 8, 2026 09:53

This branch was successfully deployed

1 active deployment
previews/1672/merge — 1cd7cbf7 Deployed Oct 7, 2026 by jamiebenstead via deploy-branch / build-deploy #6862
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.

3 participants