Skip to content

fix(babel-plugin): stamp only tags that are actually DOM - #901

Merged
divshekhar merged 1 commit into
mainfrom
fix/r3f-crash-source-stamping
Sep 8, 2026
Merged

fix(babel-plugin): stamp only tags that are actually DOM#901
divshekhar merged 1 commit into
mainfrom
fix/r3f-crash-source-stamping

Conversation

@divshekhar

Copy link
Copy Markdown
Contributor

The most severe defect in the 2026-09-08 field export. Extracted unchanged from eb3e6c57 on fix/pr-list-tells-the-truth, where it rode along inside an onboarding commit under a PR titled about the open-PR list (#872) — invisible to any reviewer, and lost if that branch were reworked. See my comment on #872 for the suggested split.

The defect

"Lowercase means host element" is true only for React DOM. React is a reconciler interface: react-three-fiber, react-pdf and ink define their own lowercase intrinsics, and those host instances are not nodes and do not take attributes.

R3F is the case that bit. Its applyProps treats any prop containing a dash as a pierced property path, so data-reticle-source is walked as datareticlesource. There is no data object on a three.js instance, so it throws:

Uncaught Error: R3F: Cannot set "data-reticle-source". Ensure it is an object before setting "reticle-source".
    at applyProps (react-three-fiber.esm:434:79)
    at commitUpdate (react-three-fiber.esm:8631:5)

The throw is inside R3F's commit phase and unhandled, so it does not degrade the viewport — it unmounts the entire React app to a white screen.

Why it is severe rather than cosmetic

  • The option that causes it is on by default.
  • It fires on an element update, not a mount. In the field the app imported a STEP file, ran a volume extraction and rendered geometry for ~20 minutes across ~15 passing verdicts before a newly generated mesh took it down mid-pipeline, losing all in-memory setup state.
  • So reticle init looks clean, a session connects, verdicts pass, and the app dies much later — which reads as an application bug. The reporter initially diagnosed it as one and only found us by reading the stack trace.
  • Its documentation names the React version as the risk axis. The actual risk axis is whether the tree contains non-DOM reconciler elements.

Net: an entire application category — CAD, simulation, 3D configurators, map and model viewers — is not merely unverifiable but actively broken by installing us.

The approach

An allowlist, not a heuristic. The set of custom-reconciler intrinsics is unbounded and cannot be enumerated; the set of HTML and SVG tags can. Wrong conservatively costs one source pointer on an exotic element. Wrong the other way costs the user their entire app.

Stated rather than implied in dom-tags.ts: a few three.js class names collide with real DOM tags — line is both <line> in SVG and THREE.Line, and so is audio. A tag name alone cannot separate them, and a lexical "is it under a <Canvas>" walk only sees the file being transformed. The complete answer for a three.js app remains reticle({ sourceMapping: false }), which init now writes on its own when it finds react-three-fiber in the manifest.

Verification

pnpm format:check, pnpm lint, pnpm typecheck green; 15/15 babel-plugin tests.

Not claimed: I have not driven a real react-three-fiber app against this build. The unit tests pin that the listed non-DOM intrinsics are skipped and DOM tags still stamp; the end-to-end proof that the white screen is gone is the thing #891's awkward-app corpus exists to make routine.

🤖 Generated with Claude Code

Extracted, unchanged, from eb3e6c5 on `fix/pr-list-tells-the-truth`, where it
rode along inside an onboarding commit on a PR titled about the open-PR list.
It is the most severe defect in the 2026-09-08 field export and it needs to land
as itself, where a reviewer can see it.

"Lowercase means host element" is true only for React DOM. React is a reconciler
interface: react-three-fiber, react-pdf and ink define their own lowercase
intrinsics, and those host instances are not nodes and do not take attributes.

R3F is the case that bit. Its `applyProps` treats any prop containing a dash as
a PIERCED PROPERTY PATH, so `data-reticle-source` is walked as `data` ->
`reticle` -> `source`; there is no `data` object on a three.js instance and it
throws from inside the commit phase. Unhandled there, the whole React tree
unmounts to a white screen. It fires on an element UPDATE rather than a mount,
so a field app imported a STEP file, ran a volume extraction and rendered
geometry for ~20 minutes with ~15 passing verdicts before a newly generated mesh
took the app down mid-pipeline — which reads as an application bug, and was
initially diagnosed as one.

The option that causes it is ON by default, and its documentation names the
React version as the risk axis. The actual risk axis is whether the tree
contains non-DOM reconciler elements.

The check is an ALLOWLIST, not a heuristic. The set of custom-reconciler
intrinsics is unbounded and cannot be enumerated; the set of HTML and SVG tags
can. Getting it wrong conservatively costs one source pointer on an exotic
element. Getting it wrong the other way costs the user their entire app.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Divyanshu Shekhar <imdshekhar@gmail.com>
@divshekhar
divshekhar force-pushed the fix/r3f-crash-source-stamping branch from 41a2c7d to 34a5b51 Compare September 8, 2026 19:24
@divshekhar
divshekhar enabled auto-merge (squash) September 8, 2026 19:24
@divshekhar
divshekhar merged commit 762f617 into main Sep 8, 2026
21 checks passed
@divshekhar
divshekhar deleted the fix/r3f-crash-source-stamping branch September 8, 2026 20:03
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