Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(bridge): report ready for the srcdoc document, not the empty one before it - #291

Open
gaurav5430 wants to merge 2 commits into
razorpay:masterfrom
gaurav5430:gaurav5430/bridge-ready-after-srcdoc
Open

gaurav5430 wants to merge 2 commits into
razorpay:masterfrom
gaurav5430:gaurav5430/bridge-ready-after-srcdoc

Conversation

@gaurav5430

Copy link
Copy Markdown

What and why

A srcdoc frame holds an empty about:blank document until its srcdoc document loads. That empty document is already complete, so when the bridge script runs before the srcdoc document has loaded, the setTimeout(setupFrame, 0) at the end of the bridge sets up the empty document and posts slashdocs:ready.

The app sends the fragment of its URL once, when ready first becomes true (the slashdocs:navigate-heading effect in doc-render-frame.tsx). When the srcdoc document then loads, the bridge sets it up and posts ready again. The app takes that second ready as "the document loaded itself again in place": it repaints and calls frameRestarted(), but it does not send the fragment again.

Headings are not affected: the bridge keeps the fragment in pendingHeading and 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.

setupFrame now skips the initial document of a frame that has a srcdoc attribute (d.URL === "about:blank"; the srcdoc document's URL is about:srcdoc). ready is posted once, for the document the app talks to, after that document's own scripts have run. Frames without a srcdoc attribute are set up as before.

How it was tested

  • In frontend/, on Node 22.22.3: npm test (100 files, 1,309 tests), npm run lint, npm run format:check and tsc -b pass. I did not run the Go half of make test; this change touches no Go code.
  • New tests/bridge-ready.test.ts: the initial document of a srcdoc frame is not set up, and no ready is 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's addEventListener rejects an AbortSignal from the parent window), which is also why bridge.test.ts does not run it.
  • In Chrome, with a local copy of the reader and of the v0.5.0 render wrapper (the bridge script taken from a live render page), and this change applied to that bridge:
    • a single-page document that routes on the fragment opened the right view on 8 of 8 fresh loads, against 0 of 3 without the change;
    • heading links, and fragment routes of documents that already work around the race, kept working (8 of 8).

Checklist

  • make lint and make test pass locally (frontend half; the Go half was not run, see above)
  • Tests added or updated for the change
  • Docs updated (README.md, docs/, .env.example, chart values.yaml) if behaviour or configuration changed (no documented behaviour or configuration changes)
  • No breaking change, or the migration path is described below

🤖 Generated with Claude Code

…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>
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