fix(preview): don't crash the preview panel on a malformed URL in withVariantMatcherOverride - #6382
Merged
Conversation
…hVariantMatcherOverride #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/#6374, which found that a malformed sandbox/production preview base (
display.iframeBase, an untrusted value from the sandbox daemon or production preview server config) crashed the whole preview panel mid-render, and wrapped everynew URL(...)call site that buildspreview.tsx'siframeSrc/openInNewTabUrl(withDeviceHint,withDecoFBT,previewOrigin,resolvePreviewUrl) in try/catch, falling back to the unmodified input on failure.They missed one sibling:
withVariantMatcherOverride(called on that same href from all threeiframeSrc/openInNewTabUrlbranches inpreview.tsxwhenever a Blocks variant override is active —workspace.state.variantOverride) still callsnew URL(href, "http://local")unguarded onceparams.length > 0. A malformed href (e.g. an unparseable host) reaching this call throws synchronously during render, taking down the panel the same way #6362 fixed for the other call sites — but only reproduces while a variant override is selected, which is why it slipped through both prior fixes.Fix: wrap the
new URLcall in try/catch, falling back to the unmodifiedhref, matching the shape already used by every other URL-construction site in this file.Regression test:
withVariantMatcherOverride("http://[::1", ["a@sections.0.variants.0.rule=0"])— a host string that's malformed even when resolved against a base — now returns the href unchanged instead of throwing; before the fix this test fails withTypeError: "http://[::1" cannot be parsed as a URL.Reviewer check:
bun test apps/web/src/components/sections-editor/variant-matcher-override.test.tsLocally verified:
bun run fmt, the targeted test file above (10 pass), andbunx oxlinton both changed files (0 warnings/errors). No type signatures changed, so skipped a fulltsc --noEmit; full CI covers the rest.Summary by cubic
Prevents the preview panel from crashing when
withVariantMatcherOverridereceives a malformed preview URL. Previously, with a variant override selected,new URL(href, "http://local")threw during render; now we catch and return the original href, aligning with other preview URL builders.withDeviceHint,withDecoFBT,previewOrigin, andresolvePreviewUrl; preserves relative href behavior; no API or type changes.Written for commit c6aa468. Summary will update on new commits.