Skip to content

DOM bindings: native Chrome Translate causes #318 before adoption, including hidden views #1904

Closed

Description

@domgan-oai

Native Chrome page translation before adoptBindings makes a compiler-generated fixed view throw Minified Octane error #318, including when the view was hidden before translation.

Tested with unmodified npm [email protected], compiler peer @tsrx/[email protected], Chrome 156.0.8078.13 on macOS, and the public compiler/runtime. No extension or application DOM rewrite is needed: Chrome's built-in French-to-English Translate action produces the mutation.

Reproduction

The view has only a scalar-text span and button:

export function Panel(props) @{ "use dom bindings";
  <div hidden={props.hidden}>
    <span>{props.message as string}</span>
    <button type="button" hidden={props.hidden}>{props.label as string}</button>
  </div>;
}

A separate compiled module imports Panel and calls the public adoptBindings(root, Panel, source, undefined) API. The runnable example below compiles both SSR and browser output, and resolves the compiler-emitted binding import.

  1. Save the two files below in an empty directory.
  2. Run npm install --ignore-scripts, then npm start.
  3. Open http://127.0.0.1:18733/ in Chrome.
  4. Control: click the verification button without translating. Both visible and hidden panels report PASS.
  5. Reload. Use Chrome's native Translate action to translate French to English. Do not choose an automatic/always-translate preference.
  6. After the page visibly translates, click the verification button. Both panels report THREW — Minified Octane error #318.

The example writes its structural before/after evidence to last-result.json and also displays it under Full diagnostics. It does not mutate the panel before adoption; the only preceding change is native browser translation.

Observed structure and result

Before translation, both roots have this shape:

div
  span -> Text
  button -> Text

After native translation, both visible and hidden roots have:

div
  span -> font -> font -> Text
  button -> font -> font -> Text

The compiler stamp and outer div/span/button structure are retained. Adoption throws at resolveFixedNodes → __adoptScalarBindings → the compiled public adoptBindings call:

Minified Octane error #318
DOM bindings cannot adopt a mismatched static element topology.

This is a translation compatibility case, distinct from the fixed signal-number-cast SSR issue #1513: the untouched SSR control here succeeds, and all text holes use string casts.

Expected behavior / recovery question

Ideally, native page translation should not prevent later activation of scalar text bindings. If rejecting translated text slots is the intended fixed-tree contract, is there a supported recovery path callers should use?

The guard correctly detects that the browser changed the leaf structure; this report is not asking to disable arbitrary topology validation. Simply skipping the guard would also be insufficient because the current scalar writer uses firstChild.nodeValue. A recovery path would need to handle decorated scalar text leaves while preserving element identity and ownership checks.

Complete runnable example

package.json:

{
  "name": "octane-translate-adoption-repro",
  "private": true,
  "type": "module",
  "scripts": {
    "start": "node repro.mjs"
  },
  "dependencies": {
    "@tsrx/oxc": "0.16.0",
    "octane": "0.10.2"
  }
}

repro.mjs:

import http from 'node:http';
import path from 'node:path';
import {readFile, writeFile, mkdir} from 'node:fs/promises';
import {fileURLToPath, pathToFileURL} from 'node:url';
import {compile} from 'octane/compiler';
import {renderToString} from 'octane/server';

const here=path.dirname(fileURLToPath(import.meta.url));
async function packageRoot(entry,name) {
  let dir=path.dirname(fileURLToPath(import.meta.resolve(entry)));
  for (;;) {
    try {const pkg=JSON.parse(await readFile(path.join(dir,'package.json')));if(pkg.name===name)return {dir,pkg};} catch {}
    const parent=path.dirname(dir);if(parent===dir)throw Error('Package root not found: '+name);dir=parent;
  }
}
const octane=await packageRoot('octane/compiler','octane');
const generated=path.join(here,'.generated');await mkdir(generated,{recursive:true});
const source=`export function Panel(props) @{ 'use dom bindings';
  <div hidden={props.hidden}>
    <span>{props.message as string}</span>
    <button type="button" hidden={props.hidden}>{props.label as string}</button>
  </div>;
}`;
const activation=`import {adoptBindings} from 'octane/behavior';
import {Panel} from './Panel.tsrx';
export function connect(root, source) {return adoptBindings(root, Panel, source, undefined);}`;
const browserTarget=value=>typeof value==='string'?value:value.import??value.default;
const importMap={};
for(const [key,value] of Object.entries(octane.pkg.exports)) {
  const target=browserTarget(value);if(typeof target==='string')importMap[key==='.'?'octane':'octane'+key.slice(1)]='/octane/'+target.replace(/^\.\//,'');
}
for(const [key,value] of Object.entries(octane.pkg.imports))importMap[key]='/octane/'+value.default.replace(/^\.\//,'');
const depFiles={};
for(const spec of ['alien-signals/system','@tsrx/core/runtime/iterable','devalue']) {
  const resolved=import.meta.resolve(spec);const file=fileURLToPath(resolved);
  const pkgName=spec.startsWith('@')?spec.split('/').slice(0,2).join('/'):spec.split('/')[0];
  const dep=await packageRoot(spec,pkgName);const route='/deps/'+pkgName+'/';depFiles[route]=dep.dir;
  importMap[spec]=route+path.relative(dep.dir,file).replaceAll(path.sep,'/');
}
const nodeSpecifier=spec=>pathToFileURL(path.join(octane.dir,browserTarget(octane.pkg.exports[spec==='octane'?'.':'.'+spec.slice(6)]))).href;
for(const mode of ['server','client']) {
  let {code}=compile(mode==='server'?source:activation,mode==='server'?'/Panel.tsrx':'/activation.tsrx',{mode,dev:false,hmr:false});
  if(mode==='server')code=code.replace(/(['"])(octane(?:\/[^'"]+)?)\1/g,(_,q,s)=>q+nodeSpecifier(s)+q);
  await writeFile(path.join(generated,mode+'.mjs'),code);
}
const bindings=compile(source,'/Panel.tsrx?octane-bindings=Panel',{mode:'client',dev:false,hmr:false});
await writeFile(path.join(generated,'bindings.mjs'),bindings.code);
const serverModule=await import(pathToFileURL(path.join(generated,'server.mjs')));
const props={message:'Le traitement est interrompu. Veuillez réessayer.',label:'Réessayer'};
const panel=hidden=>renderToString(serverModule.Panel,{...props,hidden}).html;
const page=`<!doctype html><html lang="fr"><meta charset="utf-8"><title>Exemple de traduction</title>
<style>body{font:18px system-ui;margin:36px;max-width:960px}button{margin:10px;padding:12px}#summary{white-space:pre-wrap;padding:18px;background:#f0f3f6;line-height:1.8}pre{white-space:pre-wrap;font:13px monospace}</style>
<h1>Exemple de traduction dans le navigateur</h1>
<p>Cette page utilise seulement des données de démonstration. Traduisez cette page du français vers l'anglais avec la commande de traduction intégrée au navigateur, puis cliquez sur le bouton de vérification.</p>
<p>Le premier panneau est visible. Le deuxième panneau est masqué. Le test vérifie la structure des deux panneaux avant de connecter leurs propriétés dynamiques.</p>
<div id="visible">${panel(false)}</div><div id="hidden">${panel(true)}</div>
<button id="check">Vérifier les deux panneaux</button>
<p id="summary" translate="no">Ready. Control: click before translating. Reproduction: reload, translate the page, then click.</p>
<details translate="no"><summary>Full diagnostics</summary><pre id="details"></pre></details>
<script>window.process={env:{NODE_ENV:'production'}};window.capturedErrors=[];window.addEventListener('error',e=>window.capturedErrors.push(e.message));window.addEventListener('unhandledrejection',e=>window.capturedErrors.push(String(e.reason)));</script>
<script type="importmap">${JSON.stringify({imports:importMap})}</script>
<script type="module">
import {connect} from '/client.mjs';
const tree=root=>({tag:root.localName,children:[...root.childNodes].map(n=>n.nodeType===1?tree(n):{nodeType:n.nodeType})});
const beforeTranslation={visible:tree(document.querySelector('#visible').firstElementChild),hidden:tree(document.querySelector('#hidden').firstElementChild)};
document.querySelector('#check').onclick=async()=>{
  const results=[];
  for(const name of ['visible','hidden']){
    const root=document.getElementById(name).firstElementChild;
    const result={panel:name,beforeTranslation:beforeTranslation[name],beforeAdoption:tree(root)};
    try{const h=connect(root,{getSnapshot:()=>({...${JSON.stringify(props)},hidden:name==='hidden'}),subscribe:()=>()=>{}});h.dispose();result.result='PASS'}
    catch(e){result.result='THREW';result.error=e.message;result.stack=e.stack}
    results.push(result);
  }
  const evidence={octane:'0.10.2',userAgent:navigator.userAgent,results,capturedErrors:window.capturedErrors};
  document.getElementById('summary').textContent=results.map(r=>r.panel.toUpperCase()+': '+r.result+(r.error?' — '+r.error.split(';')[0]:'')).join('\\n');
  document.getElementById('details').textContent=JSON.stringify(evidence,null,2);
  await fetch('/result',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(evidence)});
};
</script></html>`;
const app=http.createServer(async(req,res)=>{
 try {
  const url=new URL(req.url,'http://127.0.0.1');
  if(req.method==='POST'&&url.pathname==='/result'){
   let text='';for await(const chunk of req){text+=chunk;if(text.length>1000000)throw Error('Result too large');}
   await writeFile(path.join(here,'last-result.json'),JSON.stringify(JSON.parse(text),null,2));res.end('saved');return;
  }
  if(url.pathname==='/'){res.setHeader('Content-Type','text/html; charset=utf-8');res.end(page);return;}
  let base,relative;
  if(url.pathname==='/client.mjs'){base=generated;relative='client.mjs';}
  else if(url.pathname==='/Panel.tsrx'&&url.searchParams.get('octane-bindings')==='Panel'){base=generated;relative='bindings.mjs';}
  else if(url.pathname.startsWith('/octane/')){base=octane.dir;relative=url.pathname.slice('/octane/'.length);}
  else {const prefix=Object.keys(depFiles).find(p=>url.pathname.startsWith(p));if(prefix){base=depFiles[prefix];relative=url.pathname.slice(prefix.length);}}
  if(!base){res.writeHead(404);res.end('Not found');return;}
  const file=path.resolve(base,relative);if(!file.startsWith(base+path.sep)){res.writeHead(403);res.end();return;}
  res.setHeader('Content-Type','text/javascript');res.end(await readFile(file));
 } catch(error){res.writeHead(500);res.end(error.message);}
});
const port=Number(process.env.PORT??18733);
app.listen(port,'127.0.0.1',()=>console.log('Open http://127.0.0.1:'+port+'/'));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions