Repository navigation
feat(compiler): reject Strong document queries for a component's own markup - #1492
Merged
Merged
Conversation
When a useRef provably names exactly one intrinsic element in the same component (or keyed @for row), Strong mode now rejects imperative writes to what the template owns on that element: - OCTANE_STRONG_MANAGED_DOM_WRITE: textContent, innerText, or the child-list methods on an element with rendered children; className, classList mutators, or classList.value when the template sets a class; setAttribute, removeAttribute, or toggleAttribute for an attribute the template sets; and style, style.cssText, or a style property the template sets. - OCTANE_STRONG_RAW_HTML_WRITE: innerHTML, outerHTML, insertAdjacentHTML, or setHTMLUnsafe on a rendered element; the message names dangerouslySetInnerHTML={trustHTML(html)}. The proof follows .current reads, `const { current } = ref`, unreassigned local aliases, ref lists, and inline callback refs. Any other use of the ref (a component ref prop, a helper argument, a .current write, a second element) withdraws it. Writes to DOM the template does not own, such as mounting a widget into an empty container, stay valid. The analysis is a standalone pass in strong-dom.js that reuses Strong's hook scope analysis and is skipped for top-level statements without a ref prop and a DOM write spelling. Diagnostics only: compatibility mode and emitted code are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…markup New OCTANE_STRONG_OWN_MARKUP_QUERY rejects document.getElementById(), querySelector(), querySelectorAll(), and getElementsByClassName() when a literal selector matches a literal id or class rendered by the same component. The message names a ref as the replacement. Only a single compound selector (#id, .class, tag.class, …) is matched, against literal id and class values, including string elements of a class array. Portal targets, markup rendered by other components, dynamic selectors, combinators, element-scoped queries, and a shadowed document stay valid. window.document, globalThis.document, and const aliases of document are followed. Builds on the DOM ownership pass in strong-dom.js. Diagnostics only: compatibility mode and emitted code are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
5 of 6 tasks
Literal normalization rewrites text removed by JSX whitespace rules to '', which renders nothing. rendersChild now honours that, so an empty host never counts as owning children. Today's parsers drop line-break-only text before normalization, so this guards the contract rather than a reachable case; the new fixture pins a formatted empty container as a valid mount target. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 1, 2026
Brings in #1497 (Strong state values, updaters, and write-only state) and resolves the same conflicts as #1489 in strong-mode.js and the Strong docs, keeping the DOM ownership and query additions from #1491 and #1492. The workaround ledger records that #1497 now rejects five workarounds that previously compiled and kept the bug: both force-update click tallies, setN(n + 1) after await, mutate-then-set, and the mutating updater (27 → 22 compiler gaps). Prompts, references, and the recorded alternative are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 1, 2026 18:37
A TSRX sibling-scoped <style> block is extracted from the template rather than rendered into its host, so a host whose only child is a style block is empty. rendersChild treated the JSXStyleElement as rendered content, and Strong rejected valid widget mounts such as appendChild into that host. Hosts with a style block and real rendered children are still checked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
27 of 35 tasks
Contributor
Benchmark report🟢 No size increases and no timing regressions outside noise. Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)No changes across 105 measured values. CI job durations
Compares the CI run for
All 26 timed jobs
|
7 of 8 tasks
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.
Summary
New
OCTANE_STRONG_OWN_MARKUP_QUERY(issue #1027, item 2). It rejectsdocument.getElementById(),querySelector(),querySelectorAll(), andgetElementsByClassName()in a Strong module when a literal selector matches a literalidor class that the same component renders. The message names a ref as the replacement. Compatibility mode and emitted code are unchanged.Why
A probe on main @ 85cb387 found that both of these compiled under Strong:
useEffect(() => { document.getElementById('x').focus(); }); return <input id="x" />;document.querySelector('.box').classList.add('on')on<div class="box" />With two instances of the component, the query finds the wrong element, and the rendered page gets duplicate IDs.
Changes
strong-dom.jsrecords each intrinsic element's literalid, and its classes from string literals or string elements of aclassarray, keyed by its outermost component function.getElementById('x');getElementsByClassName('a b');#id,.class, orli.item.active.window.document,globalThis.document, andconstaliases ofdocumentare followed.getElementById('modal-root');document.strong-dom.test.tsgains query fixtures for all of the above, plus.tsrx@forrows, event handlers, Volar parity, and every compile mode.docs/strong-compiler-checks.md, plustsrx-basics.md,differences-from-react.md,llms.txt, andbuild-tools.mdx. Changeset added.Validation
pnpm format:files:checkon the diffpnpm typecheck(full run passed on the combined local work), pluspnpm typecheck:fileson this diffpnpm test: same local caveat as feat(compiler): close Strong render determinism gaps #1489 and feat(compiler): reject Strong writes to DOM the template renders #1491. 82,876 tests passed; the 2 failures pass in isolation and come from machine load.strong-*compiler suites plusvolar.test.ts, 1,295 tests passing.#hydration-input, and floating-ui visual specs querying their own.containerand#virtual-context.Risk / follow-ups
input[type="search"]are not proven, so they still compile. The Strong repair eval PR records this as a compiler gap.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Compile-time Strong diagnostics only—no runtime behavior change—but the new static rules can block previously valid patterns and rely on conservative selector/ref proof that may miss some unsafe cases.
Overview
Strong mode gains a new
analyzeStrongDOMcompiler pass (wired fromstrong-mode.js) that reports three static errors without changing emitted code or compatibility mode.It blocks imperative ref writes to template-owned DOM (
OCTANE_STRONG_MANAGED_DOM_WRITE) and raw HTML APIs on Octane-rendered nodes (OCTANE_STRONG_RAW_HTML_WRITE), when auseRefprovably targets a single intrinsic element in the same component. It also rejectsdocument.getElementById/querySelector*/getElementsByClassNamewith literal selectors that match literalidorclassvalues the same component renders (OCTANE_STRONG_OWN_MARKUP_QUERY), steering authors to refs instead.Docs, changesets, and a large
strong-dom.test.tssuite cover reject/allow cases (TSRX,@forrows, aliases, portal/dynamic selectors, etc.).Reviewed by Cursor Bugbot for commit 7ec047d. Bugbot is set up for automated code reviews on this repo. Configure here.