Skip to content

fix(web): reload the preview iframe through about:blank on retry - #5328

Open
pedrofrxncx wants to merge 1 commit into
mainfrom
fix/iframe-recovery-same-src-noop-w1
Open

fix(web): reload the preview iframe through about:blank on retry#5328
pedrofrxncx wants to merge 1 commit into
mainfrom
fix/iframe-recovery-same-src-noop-w1

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Follows #5324 (self-heal preview iframe stuck on connection-refused), merged to main just before this run.

The bug

useIframeLoadRecovery's retry path (preview-iframe-recovery.ts) reassigns the iframe's src to the exact same URL string it already has to force a reload:

iframe.src = currentSrc;

But in the failure case this watchdog exists to recover from, the iframe never navigated away from that URL in the first place (it's stuck on the browser's connection-refused page while src still reads the sandbox URL). Reassigning an unchanged src string is a documented no-op in several browsers (Firefox in particular skips the navigation entirely when the value doesn't change; this is the well-known "iframe src reload hack is unreliable" gotcha). So the entire self-heal mechanism silently does nothing in those browsers — it schedules retries forever but the frame never actually reloads.

The fix

Bounce through about:blank before restoring the target URL, so the assignment always differs from the previous value and reliably triggers a real navigation:

iframe.src = "about:blank";
iframe.src = currentSrc;

Regression test

Added preview-iframe-recovery.test.ts, which fakes setTimeout/clearTimeout with a manually-flushed queue (the real watchdog/backoff delays are 10s/1s) and asserts the iframe's src assignment sequence on retry. Confirmed it fails against the pre-fix code (git stash + rerun) with the exact same-string no-op it's meant to catch, and passes with the fix.

To verify

bun test apps/web/src/components/sandbox/preview/preview-iframe-recovery.test.ts

Checks run locally

  • bun run fmt
  • bunx tsc --noEmit in apps/web
  • targeted test above (green)

Full CI validates the rest.


Summary by cubic

Fixes the preview iframe self-heal so retries trigger a real reload by bouncing through about:blank. Prevents endless retries on browsers that treat same-URL src assignments as no-ops (e.g., Firefox).

  • Bug Fixes
    • Update useIframeLoadRecovery to set iframe.src = "about:blank" before restoring the target URL.
    • Add a regression test to assert the about:blank → target sequence with fake timers.

Written for commit a4e7ca1. Summary will update on new commits.

Review in cubic

The just-merged self-heal watchdog (#5324) retries a stuck iframe by
reassigning `iframe.src` to the same URL string it already has. In
several browsers (e.g. Firefox) reassigning an unchanged `src` is a
silent no-op — the exact failure mode this watchdog exists to recover
from, since the frame never left that URL. Bounce through
`about:blank` first so the retry always triggers a real navigation.
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