1287: url for scratch assets#2
Closed
DNR500 wants to merge 6 commits into
Closed
Conversation
This was referenced May 20, 2026
Closed
174ef4a to
5d0dde7
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Relates to issue: 1287
Resolves
Part of #1287 — load Scratch library thumbnails (sprites, costumes, sounds, backdrops) from a configurable host (RPF editor-api) instead of the MIT CDN.
Depends on the 13.7.3 sync PR (
sync-13.7.3-experience-cs). This PR should target that branch until it merges.Follow-up work in other repos:
editor-uiwill pin@RaspberryPiFoundation/scratch-guiand passlibraryAssetHost/libraryAssetsFetchWithHeaderseditor-apiwill serve assets from/api/scratch/assets/internalapi/asset/...Reviewer note
This PR is functionally fairly focused, but is stacked on top of the larger 13.7.3 sync PR.
Main review focus:
What this PR does
Adds configurable library asset loading so embedders (like Code Classroom) can load library thumbnails from their own asset host instead of the MIT CDN.
GUI / embedder API
Adds two new
<GUI />props:libraryAssetHostlibraryAssetsFetchWithHeadersThese are wired through
LibraryAssetConfigProvider.Using context removes prop drilling across the library UI while keeping the public
<GUI />API unchanged. I originally tried this with prop drilling (which looks like a norm in this codebase) but it touch a lot of components. As these values shouldn't change often context should be suitable here.libraryAssetHostChanges where library thumbnails are loaded from.
libraryAssetsFetchWithHeadersRoutes thumbnail loading through
ScratchImage/scratch-storageso requests can include auth + project metadata headers.When
libraryAssetsFetchWithHeadersis enabled:ScratchImageWhy
Scratch library metadata already lives inside
scratch-gui, but the actual asset binaries were still loading from the MIT CDN.For RPF, those assets need to come from
editor-api, including authenticated requests when required.This PR keeps the default MIT behaviour unchanged:
But allows
editor-uito redirect library asset loading to:{apiUrl}/api/scratch/assetswithout forking the library metadata.
I also based this on the Scratch 13.7.3 release tag rather than
developso we avoid unintentionally pulling unreleased upstream changes into RPF builds.Why
libraryAssetsFetchWithHeadersis separateLibrary thumbnails can currently load in two ways:
Direct image URLs (
<img src="...">)ScratchImage+scratch-storageeditor-apiassetslibraryAssetHostonly changes the asset URL.libraryAssetsFetchWithHeadersexplicitly opts into the authenticatedScratchImagepath and allows headers to be sent which html images wouldn't.Longer term, this logic could potentially move entirely into
ScratchImage, making the extra flag unnecessary. See the TODO that is currently in library-item.jsxScratchImage error handling
While testing with
editor-ui+editor-api, failed asset requests caused noisy errors and poor behaviour in the library UI.This PR makes those failures degrade more gracefully:
Testing
New / updated tests
test/unit/lib/library-asset-url.test.jstest/unit/contexts/library-asset-config-context.test.jsx