Skip to content

Conversation

@zetter-rpf
Copy link
Contributor

@zetter-rpf zetter-rpf commented Feb 9, 2026

Closes https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/1135

Add Scratch into editor, using a similar approach to experience CS. See commits for details

This will just visible to people looking at the test page, not anyone using the code editor.

This doesn't yet handle any project loading or saving which which will be added separately. See outstanding tasks.

Screenshot

localhost_3011_web-component html

This approach is similar to the one taken by Experience CS. The scratch.jsx, scratch.scss and ScratchIntegrationHOC.jsx as well as the scratch build are all taken from the experience CS repo with minimal changes.

We're not using all parts of the integration yet, but expect we will need it.

I've chosen to use the the public build of scratch for now as it was the simplest to set up. Many of the changes we previously relied on have been merged into main, but it's possible we may need use a fork or patch behaviour around loading and saving projects.

I've kept scratch and the editor using the same package.json and webpack config for now. This makes it simpler to get started and run and build the projects. In the future there may be value in splitting these out as it would allow us to use different versions of tools (react/redux) between them
This is just an empty project for now

I've chosen to use srcDoc to embed the iframe to avoid the need of serving the contents of the iframe. If we want
the iframe to be in the same domain as the project, the project including the web component would need to serve it.

As far as I can tell, srcDoc doesn't have any limitations that would affect us, but if it does we have alternatives:

+ Set up an a page that can host the iframe contents in each project that wants to use Scratch
+ Permanently hosting the iframe contents at a known subdomain, e.g. code-editor-scratch.raspberrypi.org and handling the complexities of cross domain iframes.
This stops some images 404ing such as the icons used in some of the blocks. This approach was copied from the
experience CS repo.

I've set assetHost so the assets are loaded from the deployed web component site rather than relative to the project.
This test makes sure that scratch is rendering by checking the 'Go' button (green flag).

We might want to update it to test more interesting behaviour later.
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.

1 participant