Skip to content

fix(preview): don't crash the preview panel on a malformed iframeBase URL - #6374

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/preview-guard-iframe-base-url-w2
Aug 20, 2026
Merged

fix(preview): don't crash the preview panel on a malformed iframeBase URL#6374
pedrofrxncx merged 1 commit into
mainfrom
fix/preview-guard-iframe-base-url-w2

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Follows #6362, which wrapped withDeviceHint/withDecoFBT's new URL() calls in try/catch after a malformed directPreviewUrl/previewUrl crashed the whole preview panel mid-render — matching previewOrigin's existing defensive shape.

It missed four sibling call sites that construct URLs from the same untrusted display.iframeBase (set from the sandbox daemon / production preview server, see preview-display.ts): productionOrigin, the two iframeSrc branches (sandbox and production modes), and productionOpenTabBase. Each still called new URL(...) unguarded as an argument expression — a malformed iframeBase (e.g. an unparseable host) throws before withDeviceHint's own try/catch ever runs, taking the whole panel down the same way #6362 fixed for the other inputs.

Failure scenario: the sandbox daemon or Fast Preview server reports an iframeBase that isn't a valid absolute URL (malformed host, stray bracket in an IPv6 literal, etc.) — the preview panel throws during render and goes blank instead of degrading gracefully.

Fix: added resolvePreviewUrl(), the same try/catch-and-fall-back-to-null shape as the existing previewOrigin helper, and used it (or previewOrigin itself, for the origin-only case) at all four call sites. Added a regression test mirroring the existing withDeviceHint/withDecoFBT malformed-URL tests.

To verify: bun test apps/web/src/components/sandbox/preview/preview.test.ts

Checked locally: bun run fmt, cd apps/web && bunx tsc --noEmit, bun test apps/web/src/components/sandbox/preview/preview.test.ts (7 pass), bunx oxlint on both touched files (0 warnings/errors). Full CI validates the rest.


Summary by cubic

Stops the preview panel from crashing when display.iframeBase is malformed. Previously, new URL(...) at several sites threw during render; now URL resolution is guarded and falls back instead of throwing.

  • Add resolvePreviewUrl(path, base): try/catch, returns href or null, same defensive shape as previewOrigin.
  • Use guarded resolution at four sites: productionOrigin, sandbox iframeSrc, production iframeSrc, and productionOpenTabBase.
  • Behavior with malformed base: panel stays up; iframe may fail to load; “Open in new tab” may be disabled when the URL is null. Valid bases behave unchanged.
  • Add regression tests for resolvePreviewUrl. Verify with: bun test apps/web/src/components/sandbox/preview/preview.test.ts.

Written for commit 093e6ac. Summary will update on new commits.

Review in cubic

… URL

#6362 wrapped withDeviceHint/withDecoFBT's new URL() calls in try/catch
after a malformed directPreviewUrl/previewUrl crashed the whole preview
panel mid-render, matching previewOrigin's existing defensive shape.

It missed four sibling call sites that construct URLs from the same
untrusted display.iframeBase (sandbox daemon / production preview server
config): productionOrigin, the two iframeSrc branches, and
productionOpenTabBase. Each still calls new URL(...) unguarded as an
argument expression, so a malformed iframeBase (e.g. an unparseable host)
throws before withDeviceHint/withVariantMatcherOverride's own try/catch
ever runs, taking the panel down the same way #6362 fixed for the other
inputs.

Added resolvePreviewUrl(), the same try/catch-and-fall-back-to-null shape
as previewOrigin, and use it (or previewOrigin itself) at all four sites.
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) August 20, 2026 21:13
@pedrofrxncx
pedrofrxncx merged commit 3876f8e into main Aug 20, 2026
34 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/preview-guard-iframe-base-url-w2 branch August 20, 2026 21:22
pedrofrxncx added a commit that referenced this pull request Aug 21, 2026
…hVariantMatcherOverride (#6382)

#6362/#6374 wrapped every other URL-construction call site in preview.tsx (withDeviceHint, withDecoFBT, previewOrigin, resolvePreviewUrl) in try/catch after a malformed sandbox/production preview base crashed the whole panel mid-render. withVariantMatcherOverride, called on the same untrusted href from all three iframeSrc/openInNewTab branches whenever a Blocks variant override is active, still called new URL(href, "http://local") unguarded and was missed by both fixes.

Falls back to the unmodified href on a malformed input, matching the established defensive shape in the rest of the file.
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