Refactor to split scratch.jsx into clearer parts#1439
Merged
Conversation
4e212ba to
b522686
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the Scratch iframe entrypoint by extracting Scratch editor rendering, GUI wrapper setup, and parent-window postMessage helpers into dedicated modules to simplify future auth-token changes and reduce test mocking complexity.
Changes:
- Split Scratch GUI setup into
ScratchEditor+WrappedScratchGuicomponents. - Extracted
postScratchGuiEventinto a sharedevents.jshelper for iframe-to-parent messaging. - Updated/refocused tests: handshake tests stay in
scratch.test.js, while save/metadata behavior moves to newScratchEditortests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/scratch.jsx | Entry-point now mounts ScratchEditor and imports shared postMessage helper. |
| src/scratch.test.js | Simplifies mocks and asserts accessToken is passed into ScratchEditor. |
| src/components/ScratchEditor/ScratchEditor.jsx | New component encapsulating Scratch GUI props, event wiring, and save behavior. |
| src/components/ScratchEditor/ScratchEditor.test.jsx | New unit tests for editor render and save/metadata wiring. |
| src/components/ScratchEditor/WrappedScratchGui.jsx | New wrapper composing Scratch GUI HOCs and setting modal app element. |
| src/components/ScratchEditor/events.js | New helper for posting Scratch GUI events to the parent origin. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b522686 to
c58497c
Compare
Refactor to split scratch.jsx now that it's responsibilities have grown. I've kept scratch.jsx as responsible for initializing the page and setting up authentication. ScratchEditor is responsible for rendering the Scratch editor component and setting up the handlers it needs. I've also extracted WrappedScratchGui as it makes the tests a lot easier to set up when you don't need to mock the process of setting up the higher order component.
c58497c to
035e918
Compare
Now I've pushed this into the component, it is safer to store it as a ref rather than in a variable.
DNR500
approved these changes
Apr 21, 2026
DNR500
left a comment
Contributor
There was a problem hiding this comment.
Thanks for this, this looks cleaner
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.
Related to: https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/1197
Refactor to split scratch.jsx now that it's responsibilities have grown and simplify tests
In https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/1197 I'll need to update the access token that's passed into Scratch. This should make that easier.
I've kept
scratch.jsxas responsible for initializing the page and setting up authentication. ScratchEditor is responsible for rendering the Scratch editor component and setting up the handlers it needs.I've also extracted
WrappedScratchGuias it makes the tests easier to set up when you don't need to mock the process of setting up the higher order component.