Repository navigation
fix: demo images load in Studio's article preview - #6
Merged
Merged
Conversation
Studio's preview is a sandboxed document, so its image requests are cross-site and carry no session cookie (SameSite=Lax). Without a session the playground answered /media/... with a 303 to the landing page, and every cover showed as a broken image there (seen on "Pages are made of sections"). Uploads are refused in the playground, so its only media are the demo images, already public under /demo/: the Worker now answers their media URLs from those static files. Adds node --test to pnpm check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Madraka <asker_17@msn.com>
5 tasks done
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.
What
The demo article "Pages are made of sections" showed a broken image, and so did every other cover, in Studio's article Preview. Reproduced in a live session on try.cloudhal.com.
Cause. The preview response's CSP carries
sandbox, so the preview document has an opaque origin. Its<img src="/media/…">requests are then cross-site, and the browser leaves out the session cookie (__Host-cloudhal_try,SameSite=Lax). Without a session, the playground Worker answers/media/…with 303 to the landing page, so the image breaks. On the site itself (/s/<session>/…) and in the editor's cover field, the cookie is sent and the images load.Fix. Uploads are refused in the playground, so its only media are the three demo images, whose bytes are already public static files (
/demo/media/site_playgrounddemo/<sha256>).src/playground/demo-media-route.tsanswersGET/HEAD /media/<sha16>/<slug>.pngfor those three fromASSETS, with or without a session:image/png,nosniff,default-src 'none'. Every other path still goes to the session as before. It runs only while the playground is enabled.Tests.
test/demo-media-route.test.ts(node --test, now part ofpnpm check) covers the mapping, the response, and that other paths, methods and missing files pass through. Underwrangler dev, a cookie-less request for both demo images gets 200image/pngat the right size; an unknown media path still gets 303.The other playground issue, Build saying "This deployment can't reach Workers AI", is fixed in Studio in the monorepo (cloudhal-dev/cloudhal#122). It reaches this repo with the next
@cloudhal/*bump.The cause is generic: in any playground deployment, previews lose media. A fix in
@cloudhal/cloudflare/playgroundcould servedemoMediakeys before the session check, and this file would then go away.pnpm check(Biome, TypeScript, tests) passespnpm run deployafter merge)🤖 Generated with Claude Code