Repository navigation
fix(octane): adopt DOM bindings over browser-translated text leaves - #1909
Conversation
…1904) Chrome's page translation replaces a text leaf's Text node with nested <font> wrappers. Fixed and addressed adoption rejected that leaf (#318, #321), and a leaf translated after adoption silently dropped every later write, because nodeValue is a no-op on an element. Adoption now accepts a text leaf whose first child is a <font> element and writes nothing to it, so the page neither flashes back to its source language nor shifts. The writer receives the channel's previous value and, once that value exists, replaces any non-Text leaf content on change. Any other element in a text leaf still throws. Document the behavior and the translate="no" opt-out in docs/deferred-hydration.md, and add a website-only catalog note to #318 and #321 that never reaches a runtime bundle. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…1904) Structural programs had the same Chrome Translate failure as fixed views. A static text proof or a text hole whose Text node was replaced by <font> wrappers failed adoption with #286, and a text hole translated after adoption silently kept its translation, because writeText set the data of a detached node. - resolveFragment accepts a <font> element in a static text slot. The marker id already hashes the template source, including that text. - adoptRegion accepts a <font>-wrapped text hole and records `undefined`. The first commit stores the value in a detached Text node and writes nothing. - writeText replaces the range content with its node only when the value changes and the node is no longer the range's only child. Any other element in either slot still throws #286. Extend the deferred-hydration paragraph and the website-only error note, now also on #286, to structural views. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…1904) Review follow-up. The fixed and addressed resolvers share an isTextLeaf predicate. It reads firstChild once and uses nextSibling instead of childNodes.length, which is not O(1). The fixed-scalar writer reads nodeValue once. A null nodeValue identifies an element first child, such as Chrome Translate's <font>, so the changed write no longer reads nodeType. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Benchmark report🟢 No byte growth, no added work, and no timing changes beyond ±3%. Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)No changes across 60 measured values. Public-import reachability bundles (bytes)No changes across 111 measured values. |
…g walk (#1904) Review follow-up. The element branch of both resolvers still counted live child lists (`childNodes.length`, `children.length`) and indexed `children[i]`. In Blink each of those creates a collection and keeps it on the node. Each parent now keeps a cursor to its next unclaimed child. Validation reads `firstChild` and `nextSibling` only, and a final check rejects any child the server topology does not have. A parent without a cursor (opaque, text, or not yet visited) claims nothing, which replaces two explicit parent checks. Error codes are unchanged for compiler-issued descriptors. New tests pin #318 and #321 for an extra child, a stray text node, a missing child, reordered children, and a child under a childless element. Unbound children still adopt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website | 6856723 | Commit Preview URL Branch Preview URL |
Oct 08 2026, 06:54 PM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website-mcp | 1ed0f16 | Commit Preview URL Branch Preview URL |
Oct 08 2026, 05:55 PM |
…tion paths (#1904) Apply performance-audit's "Reuse stable member reads" (#1913) to the code this PR adds. - Both adopters' write loops read `next[i]` and `previous[i]` once. - writeOperation reads `instance.previous[index]` once, after its disposed guards. - writeText no longer reads `region.range` on the unchanged path, and caches `range.end` in the branches that use it. - adoptRegion caches `range.end`. - resolveFixedNodes destructures its open-children flag rather than indexing `descriptor.nodes[i]` again. Minified adopters shrink by 12–14 B. gzip moves 4–11 B, so this is a read-count change, not a size claim. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Text leaf allows extra font siblings
- Added the missing
!first.nextSiblingguard to the font branch ofisTextLeaf, so a<font>followed by extra siblings is now correctly rejected, matching the Text-node branch behavior and the oldchildNodes.length > 1check.
- Added the missing
Or push these changes by commenting:
@cursor push a575c05c4c
Preview (a575c05c4c)
diff --git a/packages/octane/src/dom-bindings.ts b/packages/octane/src/dom-bindings.ts
--- a/packages/octane/src/dom-bindings.ts
+++ b/packages/octane/src/dom-bindings.ts
@@ -242,7 +242,9 @@
const first = node.firstChild;
return (
first === null ||
- (first.nodeType === 3 ? !first.nextSibling : (first as Element).localName === 'font')
+ (first.nodeType === 3
+ ? !first.nextSibling
+ : (first as Element).localName === 'font' && !first.nextSibling)
);
}You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 9593d6b. Configure here.
…1904) Bugbot review: isTextLeaf accepted a leading <font> even when other nodes followed it. Those leaves used to fail #318/#321, and a structural text hole already requires a single node. Chrome Translate replaces one Text node with one wrapper, so a text leaf now holds no child, or exactly one: a Text node or a <font> element. The negative tests cover a <font> followed by text in every fixed lane, and two wrappers in an addressed view. Co-Authored-By: Claude Opus 5.5 <[email protected]>


Fixes #1904
Summary
Chrome's page translation replaces each translated Text node with nested
<font style="vertical-align: inherit;">wrappers. DOM-binding adoption failed on that, in both adopter families:__adoptScalarBindings/__adoptBindings):resolveFixedNodesaccepted only an empty leaf or one lone Text child, so it threw feat(base-ui): port the Menu item family (Phase 3f stage 2) #318.resolveAddressedNodeshas the same check and threw feat(octane): cross-module hook fact extraction (opt-in) #321. This happened for visible andhiddenroots alike.firstChild.nodeValue, which does nothing on an Element. Every later text update was dropped without an error.dom-binding-program.ts):<font>failed adoption with feat(seo): make document metadata reach <head> in SSR #286.writeTextset the data of a detached Text node, so updates were dropped without an error.The fix keeps the translation until the value changes:
<b>, a<span>, or a Text node followed by<font>, still throws feat(base-ui): port the Menu item family (Phase 3f stage 2) #318/feat(octane): cross-module hook fact extraction (opt-in) #321/feat(seo): make document metadata reach <head> in SSR #286.Why
translate="no"stays the explicit opt-out. The compiler does not add it, because that would make all dynamic text untranslatable.Changes
packages/octane/src/dom-bindings.ts(fixed views)isTextLeafpredicate. It readsfirstChildonce and usesnextSiblinginstead ofchildNodes.length. A leaf passes when it is empty or holds exactly one child: a Text node or afontelement. Translation replaces one Text node with one wrapper, matching structural text holes.childNodes.length,children.lengthandchildren[i]. In Blink each creates a collection and keeps it on the node.writeFixedScalarand the generalwritetake an optionalpreviousargument. Both adopters'writePreparedpassprevious[i], and theBindingScalarChannelswrite type includes it.nodeValueonce. A nullnodeValueidentifies an element first child, which is replaced viatextContentonly whenprevious !== undefined.packages/octane/src/dom-binding-program.ts(structural programs)writeOperationpassesinstance.previous[index].resolveFragmentaccepts a<font>element in a static text slot. The marker id already hashes the view's source, including that text (strongHash(...source)incompiler/dom-binding-program.js).adoptRegionaccepts a<font>-wrapped text hole and recordsregion.text = undefined.writeTextturnsundefinedinto a detached Text node on the first commit, which records the value without writing. When a changed value finds its node displaced,writeTextreplaces the range content with that node.valid()treatsundefinedlikenull. Translated content makes handoff validation fail, which takes the renderer's existingPresentationAdoptionMisspath.docs/deferred-hydration.md, under "Compiled presentation on existing DOM":translate="no"orclass="notranslate"is the zero-cost opt-out. The compiler does not add it, because that would make all dynamic text untranslatable.codes.jsongains an optional website-onlynote./errors/<code>decoder renders the note under the message.next[i]andprevious[i]once.writeOperationreadsinstance.previous[index]once, after its disposed guards.writeTextno longer readsregion.rangeon the unchanged path.adoptRegionandwriteTextcacherange.end.resolveFixedNodesdestructures its open-children flag.octane.Validation
pnpm format:check: not run locally.pnpm format:files:checkpassed on every changed file.pnpm typecheck: not run locally; left to CI.pnpm test: not run locally; left to CI.--project octane: 646/646 pass across every runtime file that adopts DOM bindings. That isscalar-dom-bindings,behavior-root,behavior-root-bundle,binding-handoff,binding-handoff-displaced-host,behavior-handoff-bundle, andhydration/{range-boundary,unclosed-range,independent-island,text-sibling-hydrate}.expected [[1, null]] to deeply equal [[3, 'Nouveau message.']].expected 'Status: ready now' to be 'Status: envoyée now'.previous !== undefinedguard fails the MutationObserver/identity assertions at adoption.fontin the fixed resolvers fails the<b>feat(base-ui): port the Menu item family (Phase 3f stage 2) #318/feat(octane): cross-module hook fact extraction (opt-in) #321 negatives.pnpm error-codes:check: 17/17, including thenotevalidation and formatter-identity tests.pnpm sync: no generated changes.New tests:
scalar-dom-bindings.test.ts, using the issue'sPanelacross the dev/prod × scalar/general lanes:hiddenroot. Adoption does not throw, the elements and<font>subtrees keep their identity, and a MutationObserver records no mutations.<b>child,[Text, <font>], or[<font>, Text]still throws feat(base-ui): port the Menu item family (Phase 3f stage 2) #318 and claims nothing. The last case comes from Bugbot's review.unboundchildren gets the same positive case and the<b>feat(octane): cross-module hook fact extraction (opt-in) #321 negative.behavior-root.test.ts, "a page translated by the browser", in dev and prod:Noticeview with static text, a text hole, and an@ifarm holding a text hole.innerHTMLis unchanged at adoption and on an unchanged publish. Only changed holes are replaced, static text stays translated, and a re-created arm renders fresh source text.<span>in place of the static text or of the text hole still throws feat(seo): make document metadata reach <head> in SSR #286 and leaves the DOM untouched.Perf review:
fix/translated-text-leaf(origin/maine29a12be0a..1084f00f1f)Scan:
node scripts/perf-review-scan.mjs→ 0 candidates.Hot paths touched:
writeFixedScalar/write: run once per changed binding write, per publication or signal notification.next[i] === previous[i]before the writer is called, so unchanged writes do no added work.nodeValueonce, and adds nonodeTyperead: a nullnodeValueidentifies the element case.writeText: runs on every commit of every text hole.region.textonce, thentext.data. That is one read fewer than before: the base readregion.texttwice.nextSiblingcomparison.region.textnow also holdsundefined, an oddball likenull, so the field's representation is unchanged.adoptRegion: run once per adoption, per node.firstChild/nextSibling. They no longer touchchildNodes,childrenor collection indexing, so adoption creates no NodeList or HTMLCollection.cursorsarrays are packed: one push per node, writes to existing indices only.adoptRegionand the static-text proof, thefontcheck runs only where the old check would already have thrown.writeOperation: one extra array read per changed program write.dom-bindings.tsadopters,dom-binding-program.tsdom-bindings.tswriteFixedScalar,dom-binding-program.tswriteTexttextContent, orremoveRangeplusinsertBefore) has no read after it, and runs only when translated text changes valueCI bench report for
025f9575ec, comparing merge593e4e73fwith385d6aba9(run):__adoptScalarBindings,__adoptBindingsordom-binding-program: the adopters are reached only from compiled binding artifacts, and the report has no suite for them. So there are no adopter rows to quote. The identical bytes do show the change does not leak into renderer or application bundles.swap0.039 → 0.040 ms, +5.5% (CI +3.4% … +7.5%). Its bundle is byte-identical between base and head, and the benchmark never loads the binding runtime, so this is runner noise rather than an effect of this diff. The other 19 operations are within noise.Local scratch probe: esbuild minify + gzip -9 of each entry,
process.env.NODE_ENV=production, origin/main vs head:__adoptScalarBindings__adoptBindingsdom-binding-program(includes thedom-bindingschanges)Structural code: +38 B gzip of the program's +71. I trimmed it from +46 B by compacting
adoptRegion,writeTextand the static-text check.Review follow-ups:
nodeValueread took the scalar adopter to +51 B gzip, from the first push's +30.nodeTypewriterThe shared helper has the smallest combined cost and one predicate for both resolvers.
Compiled output: no compiler change. Reachability: no new imports or references. Scheduling: none.
Not checked: real Chrome Translate in a browser. jsdom reproduces the issue's recorded
span → font → font → Textstructure.Risk / follow-ups
Stale server text after translation: translated bound text keeps its server value if the data changed between SSR and adoption, until the next change. This is documented, and was Dominic's choice over a flash and layout shift at adoption.
Handoff to
hydrateRoot: a structural view handed to normal hydration while it still holds translated text failsvalid(), which takes the renderer's existingPresentationAdoptionMisspath. What the renderer then does with translated text, includingtextHoleUpdate, belongs to the separate renderer work.Adopter bytes have no CI rows. The bench report has no suite that loads the binding adopters (see the perf review), so their byte evidence is the local scratch probe above, not CI rows.
Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches hot adoption and text-write paths across fixed and structural binding runtimes; behavior is well-tested but edge cases remain (e.g. stale server text until the next bound update after translation).
Overview
DOM binding adoption no longer fails when Chrome’s page translation has replaced server text with nested
<font>wrappers. Fixed views and structural programs accept that topology instead of raising #318, #321, or #286; other non-text substitutions still fail.At adoption, translated text is left in place (no flash back to the source language). Bound text switches to plain text on the next value change so updates work again, including when translation happens after adoption. Writers pass a
previousvalue so<font>leaves are not overwritten until the binding actually changes.Topology validation in
dom-bindings.tsuses anisTextLeafcheck and sibling cursors instead ofchildNodes/childrenlength checks. StructuralwriteText/adoptRegiontrackregion.textasundefinedwhile translated holes await their first write.Docs (
deferred-hydration.md) document the behavior andtranslate="no"/notranslateopt-out. Error catalog entries for #286/#318/#321 gain optional website-onlynotefields (runtime formatters unchanged). New tests cover pre/post-adoption translation for scalar, addressed, and structural views.Reviewed by Cursor Bugbot for commit 1084f00. Bugbot is set up for automated code reviews on this repo. Configure here.