Skip to content

fix: demo images load in Studio's article preview - #6

Merged
Madraka merged 1 commit into
mainfrom
fix/demo-media-preview
Oct 23, 2026
Merged

Madraka merged 1 commit into
mainfrom
fix/demo-media-preview

Conversation

@Madraka

@Madraka Madraka commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

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.ts answers GET/HEAD /media/<sha16>/<slug>.png for those three from ASSETS, 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 of pnpm check) covers the mapping, the response, and that other paths, methods and missing files pass through. Under wrangler dev, a cookie-less request for both demo images gets 200 image/png at 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/playground could serve demoMedia keys before the session check, and this file would then go away.

  • pnpm check (Biome, TypeScript, tests) passes
  • Signed off (DCO)
  • Deploy: not done (pnpm run deploy after merge)

🤖 Generated with Claude Code

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>
@Madraka
Madraka merged commit 23f498d into main Oct 23, 2026
1 check passed
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