Skip to content

feat(compiler): reject Strong document queries for a component's own markup - #1492

Merged
trueadm merged 12 commits into
mainfrom
feat/strong-own-markup-queries
Oct 1, 2026
Merged

trueadm merged 12 commits into
mainfrom
feat/strong-own-markup-queries

Conversation

@trueadm

@trueadm trueadm commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

New OCTANE_STRONG_OWN_MARKUP_QUERY (issue #1027, item 2). It rejects document.getElementById(), querySelector(), querySelectorAll(), and getElementsByClassName() in a Strong module when a literal selector matches a literal id or class that the same component renders. The message names a ref as the replacement. Compatibility mode and emitted code are unchanged.

Stacked on #1491. This branch builds on the DOM ownership pass in strong-dom.js, so until #1491 merges the diff also shows its commit. Review only the top commit, "reject Strong document queries for a component's own markup".

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.js records each intrinsic element's literal id, and its classes from string literals or string elements of a class array, keyed by its outermost component function.
  • It then matches document queries made in the same component. Only these selector forms are matched:
    • getElementById('x');
    • getElementsByClassName('a b');
    • a single compound selector such as #id, .class, or li.item.active.
  • window.document, globalThis.document, and const aliases of document are followed.
  • These stay valid:
    • portal targets such as getElementById('modal-root');
    • markup rendered by another component;
    • dynamic selectors and selectors with combinators;
    • element-scoped queries;
    • a shadowed document.
  • strong-dom.test.ts gains query fixtures for all of the above, plus .tsrx @for rows, event handlers, Volar parity, and every compile mode.
  • Docs: a query row and paragraph in docs/strong-compiler-checks.md, plus tsrx-basics.md, differences-from-react.md, llms.txt, and build-tools.mdx. Changeset added.

Validation

  • pnpm format:files:check on the diff
  • pnpm typecheck (full run passed on the combined local work), plus pnpm typecheck:files on this diff
  • pnpm 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.
  • Targeted: all strong-* compiler suites plus volar.test.ts, 1,295 tests passing.
  • Loosening the selector match on purpose turns tests red.
  • Compiled 3,479 real repo files under Strong. All 5 query diagnostics are true positives: the news benchmark querying its own #hydration-input, and floating-ui visual specs querying their own .container and #virtual-context.

Risk / follow-ups

  • Attribute selectors such as input[type="search"] are not proven, so they still compile. The Strong repair eval PR records this as a compiler gap.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with 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 analyzeStrongDOM compiler pass (wired from strong-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 a useRef provably targets a single intrinsic element in the same component. It also rejects document.getElementById / querySelector* / getElementsByClassName with literal selectors that match literal id or class values the same component renders (OCTANE_STRONG_OWN_MARKUP_QUERY), steering authors to refs instead.

Docs, changesets, and a large strong-dom.test.ts suite cover reject/allow cases (TSRX, @for rows, 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.

trueadm and others added 2 commits October 1, 2026 09:38
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]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent feat PR: new feature or capability labels Oct 1, 2026
@github-actions
github-actions Bot marked this pull request as draft October 1, 2026 08:40
trueadm and others added 2 commits October 1, 2026 09:49
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
trueadm marked this pull request as ready for review October 1, 2026 18:37
trueadm and others added 4 commits October 1, 2026 19:49
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]>
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No size increases and no timing regressions outside noise.

Compares 196cb6570 with b7f7abf02 on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample moving the same way. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 4.71 4.66 −1.1% ±51% ⚪ within noise
octane-tsrx replace 11.47 15.63 +36.3% ±45% ⚪ within noise
octane-tsrx add 4.36 4.85 +11.2% ±30% ⚪ within noise
octane-tsrx update 0.99 1.14 +15.2% ±75% ⚪ within noise
octane-tsrx select 0.45 0.43 −4.4% ±66% ⚪ within noise
octane-tsrx swap 1.04 0.85 −18.3% ±108% ⚪ within noise
octane-tsrx remove 1.06 0.78 −26.4% ±69% ⚪ within noise
octane-tsrx runlots 48.41 45.82 −5.4% ±65% ⚪ within noise
octane-tsrx select_lots 0.41 0.49 +19.5% ±57% ⚪ within noise
octane-tsrx clear 57.45 79.80 +38.9% ±50% ⚪ within noise
octane-jsx run 5.75 6.58 +14.4% ±76% ⚪ within noise
octane-jsx replace 16.08 16.68 +3.7% ±84% ⚪ within noise
octane-jsx add 5.45 6.04 +10.8% ±67% ⚪ within noise
octane-jsx update 1.34 1.73 +29.1% ±84% ⚪ within noise
octane-jsx select 0.71 0.78 +9.9% ±81% ⚪ within noise
octane-jsx swap 1.36 1.47 +8.1% ±88% ⚪ within noise
octane-jsx remove 1.25 1.47 +17.6% ±74% ⚪ within noise
octane-jsx runlots 40.08 43.67 +9.0% ±54% ⚪ within noise
octane-jsx select_lots 5.63 5.27 −6.4% ±76% ⚪ within noise
octane-jsx clear 74.12 74.28 +0.2% ±54% ⚪ 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

  • 🟡 6 job(s) slower than every recent main run: React parity shard (3/4), example apps (3/3), example apps (1/3), test shard (Node 24, 2/4), typecheck checks, validate publishable packages

Compares the CI run for 7ec047dd7 (run) with the last 5 successful main push runs. A job is only slower or faster outside the whole main range, by at least 10% and 15s.

job main median main range this PR Δ
wall clock (first job start to last job end) 17m 05s 12m 35s–23m 15s 20m 39s +3m 34s (+21%) ⚪ within noise
total job time 184m 21s 144m 08s–242m 49s 226m 59s +42m 38s (+23%) ⚪ within noise
React parity shard (3/4) 13m 10s 10m 59s–18m 01s 19m 43s +6m 33s (+50%) 🟡 slower
example apps (3/3) 3m 49s 3m 34s–5m 33s 9m 48s +5m 59s (+157%) 🟡 slower
example apps (1/3) 3m 36s 3m 07s–9m 27s 9m 31s +5m 55s (+164%) 🟡 slower
test shard (Node 24, 2/4) 13m 32s 10m 24s–15m 53s 16m 33s +3m 01s (+22%) 🟡 slower
typecheck checks 9m 23s 7m 20s–11m 01s 11m 17s +1m 54s (+20%) 🟡 slower
validate publishable packages 4m 32s 3m 45s–5m 20s 5m 54s +1m 22s (+30%) 🟡 slower
All 26 timed jobs
job main median main range this PR Δ
React parity shard (2/4) 10m 50s 9m 32s–19m 40s 18m 14s +7m 24s (+68%) ⚪ within noise
React parity shard (3/4) 13m 10s 10m 59s–18m 01s 19m 43s +6m 33s (+50%) 🟡 slower
example apps (3/3) 3m 49s 3m 34s–5m 33s 9m 48s +5m 59s (+157%) 🟡 slower
example apps (1/3) 3m 36s 3m 07s–9m 27s 9m 31s +5m 55s (+164%) 🟡 slower
example apps (2/3) 4m 15s 3m 26s–9m 58s 9m 42s +5m 27s (+128%) ⚪ within noise
React parity shard (4/4) 13m 38s 11m 39s–22m 17s 18m 51s +5m 13s (+38%) ⚪ within noise
heavy integration (browser - chromium) 12m 52s 11m 12s–19m 08s 16m 17s +3m 25s (+27%) ⚪ within noise
website integration suite 7m 24s 5m 45s–11m 41s 10m 44s +3m 20s (+45%) ⚪ within noise
test shard (Node 24, 2/4) 13m 32s 10m 24s–15m 53s 16m 33s +3m 01s (+22%) 🟡 slower
test shard (Node 24, 4/4) 12m 54s 10m 24s–16m 16s 15m 21s +2m 27s (+19%) ⚪ within noise
test shard (Node 24, 3/4) 11m 56s 9m 44s–15m 12s 14m 18s +2m 22s (+20%) ⚪ within noise
lint checks 8m 49s 7m 43s–12m 27s 10m 59s +2m 10s (+25%) ⚪ within noise
typecheck checks 9m 23s 7m 20s–11m 01s 11m 17s +1m 54s (+20%) 🟡 slower
React parity shard (1/4) 14m 25s 10m 05s–18m 11s 16m 19s +1m 54s (+13%) ⚪ within noise
validate publishable packages 4m 32s 3m 45s–5m 20s 5m 54s +1m 22s (+30%) 🟡 slower
Lynx compatibility 2m 00s 1m 34s–2m 55s 2m 44s +44s (+37%) ⚪ within noise
classify changeset release 16s 14s–21s 17s +1s (+6%) ⚪ within noise
lint 4s 4s–5s 5s +1s (+25%) ⚪ within noise
React parity checks 15s 14s–16s 16s +1s (+7%) ⚪ within noise
test (24) 4s 3s–5s 5s +1s (+25%) ⚪ within noise
examples 4s 4s–4s 4s ±0s (±0%) ⚪ within noise
typecheck 4s 3s–4s 4s ±0s (±0%) ⚪ within noise
CI provenance 4s 3s–4s 4s ±0s (±0%) ⚪ within noise
Three compatibility 3m 28s 2m 51s–4m 23s 3m 17s −11s (−5%) ⚪ within noise
heavy integration (package builds, eval corpus, runtime loaders, Astro) 5m 28s 4m 36s–16m 52s 5m 07s −21s (−6%) ⚪ within noise
test shard (Node 24, 1/4) 14m 01s 11m 10s–17m 32s 11m 25s −2m 36s (−19%) ⚪ within noise

@trueadm
trueadm merged commit b6a414a into main Oct 1, 2026
30 checks passed
@trueadm
trueadm deleted the feat/strong-own-markup-queries branch October 1, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent feat PR: new feature or capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant