fix(preview): don't crash the preview panel on a malformed iframeBase URL - #6374
Merged
Conversation
… 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
enabled auto-merge (squash)
August 20, 2026 21:13
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.
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.
Follows #6362, which wrapped
withDeviceHint/withDecoFBT'snew URL()calls in try/catch after a malformeddirectPreviewUrl/previewUrlcrashed the whole preview panel mid-render — matchingpreviewOrigin'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, seepreview-display.ts):productionOrigin, the twoiframeSrcbranches (sandbox and production modes), andproductionOpenTabBase. Each still callednew URL(...)unguarded as an argument expression — a malformediframeBase(e.g. an unparseable host) throws beforewithDeviceHint'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
iframeBasethat 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-nullshape as the existingpreviewOriginhelper, and used it (orpreviewOriginitself, for the origin-only case) at all four call sites. Added a regression test mirroring the existingwithDeviceHint/withDecoFBTmalformed-URL tests.To verify:
bun test apps/web/src/components/sandbox/preview/preview.test.tsChecked locally:
bun run fmt,cd apps/web && bunx tsc --noEmit,bun test apps/web/src/components/sandbox/preview/preview.test.ts(7 pass),bunx oxlinton both touched files (0 warnings/errors). Full CI validates the rest.Summary by cubic
Stops the preview panel from crashing when
display.iframeBaseis malformed. Previously,new URL(...)at several sites threw during render; now URL resolution is guarded and falls back instead of throwing.resolvePreviewUrl(path, base): try/catch, returns href or null, same defensive shape aspreviewOrigin.productionOrigin, sandboxiframeSrc, productioniframeSrc, andproductionOpenTabBase.resolvePreviewUrl. Verify with:bun test apps/web/src/components/sandbox/preview/preview.test.ts.Written for commit 093e6ac. Summary will update on new commits.