Repository navigation
fix(bridge): report ready for the srcdoc document, not the empty one before it - #291
Open
gaurav5430 wants to merge 2 commits into
Open
gaurav5430 wants to merge 2 commits into
gaurav5430 wants to merge 2 commits into
Conversation
…before it A srcdoc frame holds an empty about:blank document until its srcdoc document loads. When the bridge script runs before that, its first setupFrame call sets up the empty document and posts slashdocs:ready. The app sends the fragment of its URL once, at the first ready, so a document that routes on the fragment in its own script (in-page views behind #routes) is not loaded yet and never receives it: a shared link to such a view opens the document's first view instead. The second ready, from the srcdoc document, takes the app's "the document loaded itself again" path. Headings were not affected, because pendingHeading is retried once the real document loads. setupFrame now skips the initial document of a frame that has a srcdoc attribute, so ready is posted once, for the document the app talks to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gaurav5430
requested review from
anuragrao04 and
razvi-razorpay
as code owners
November 18, 2026 08:05
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.
What and why
A srcdoc frame holds an empty
about:blankdocument until its srcdoc document loads. That empty document is alreadycomplete, so when the bridge script runs before the srcdoc document has loaded, thesetTimeout(setupFrame, 0)at the end of the bridge sets up the empty document and postsslashdocs:ready.The app sends the fragment of its URL once, when
readyfirst becomes true (theslashdocs:navigate-headingeffect indoc-render-frame.tsx). When the srcdoc document then loads, the bridge sets it up and postsreadyagain. The app takes that second ready as "the document loaded itself again in place": it repaints and callsframeRestarted(), but it does not send the fragment again.Headings are not affected: the bridge keeps the fragment in
pendingHeadingand retries it once the real document has the element. A document that shows in-page views from the fragment in its own script is affected. On a fresh load of/app/d/<doc>#<view>it never gets the fragment and opens on its first view. With a 3 MB single-file document of that kind, 3 of 4 fresh loads failed in Chrome. A smaller document fails less often, because the race depends on how long the srcdoc takes to parse.setupFramenow skips the initial document of a frame that has asrcdocattribute (d.URL === "about:blank"; the srcdoc document's URL isabout:srcdoc).readyis posted once, for the document the app talks to, after that document's own scripts have run. Frames without asrcdocattribute are set up as before.How it was tested
frontend/, on Node 22.22.3:npm test(100 files, 1,309 tests),npm run lint,npm run format:checkandtsc -bpass. I did not run the Go half ofmake test; this change touches no Go code.tests/bridge-ready.test.ts: the initial document of a srcdoc frame is not set up, and noreadyis posted. Without the fix the test fails, because the bridge sets up the empty document. Setting up the srcdoc document itself cannot run in jsdom (the frame'saddEventListenerrejects anAbortSignalfrom the parent window), which is also whybridge.test.tsdoes not run it.Checklist
make lintandmake testpass locally (frontend half; the Go half was not run, see above)README.md,docs/,.env.example, chartvalues.yaml) if behaviour or configuration changed (no documented behaviour or configuration changes)🤖 Generated with Claude Code