Repository navigation
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]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Empty hosts treated as having children
- Added an explicit
child.value !== ''check inrendersChildso that empty strings left bynormalizeAuthoredJsxLiterals(collapsed from whitespace-only text with linebreaks) are correctly treated as non-rendering, preventing falseOCTANE_STRONG_MANAGED_DOM_WRITEdiagnostics on multiline empty hosts.
- Added an explicit
Or push these changes by commenting:
@cursor push 620ffd0ffb
Preview (620ffd0ffb)
diff --git a/packages/octane/src/compiler/strong-dom.js b/packages/octane/src/compiler/strong-dom.js
--- a/packages/octane/src/compiler/strong-dom.js
+++ b/packages/octane/src/compiler/strong-dom.js
@@ -154,9 +154,12 @@
return keys;
}
-// JSX drops whitespace-only text that contains a line break.
+// JSX drops whitespace-only text that contains a line break. After
+// normalizeAuthoredJsxLiterals those nodes are collapsed to '' but left in
+// children, so an empty value is never rendered content.
function rendersChild(child) {
- if (child.type === 'JSXText') return !/^\s*$/.test(child.value) || !/[\r\n]/.test(child.value);
+ if (child.type === 'JSXText')
+ return child.value !== '' && (!/^\s*$/.test(child.value) || !/[\r\n]/.test(child.value));
if (child.type === 'JSXExpressionContainer')
return child.expression?.type !== 'JSXEmptyExpression';
return true;
diff --git a/packages/octane/tests/compiler/strong-dom.test.ts b/packages/octane/tests/compiler/strong-dom.test.ts
--- a/packages/octane/tests/compiler/strong-dom.test.ts
+++ b/packages/octane/tests/compiler/strong-dom.test.ts
@@ -313,6 +313,16 @@
'<span ref={r} />',
],
[
+ 'textContent on a multiline empty host',
+ 'r.current.textContent = label;',
+ '<span ref={r}>\n</span>',
+ ],
+ [
+ 'mounting into a multiline empty container',
+ "r.current.appendChild(document.createElement('canvas'));",
+ '<div ref={r}>\n</div>',
+ ],
+ [
'mounting into an empty container',
"r.current.appendChild(document.createElement('canvas'));",
'<div ref={r} class="chart" />',You can send follow-ups to the cloud agent here.
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]>
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]>
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: Style children treated as rendered DOM
- Added a
JSXStyleElementcheck returningfalsein therendersChildfunction, consistent with every other child-content check in the codebase, so scoped style blocks no longer makeelement.childrentrue and valid DOM writes into style-only containers are allowed.
- Added a
Or push these changes by commenting:
@cursor push 119f9c9f1c
Preview (119f9c9f1c)
diff --git a/packages/octane/src/compiler/strong-dom.js b/packages/octane/src/compiler/strong-dom.js
--- a/packages/octane/src/compiler/strong-dom.js
+++ b/packages/octane/src/compiler/strong-dom.js
@@ -162,6 +162,7 @@
}
if (child.type === 'JSXExpressionContainer')
return child.expression?.type !== 'JSXEmptyExpression';
+ if (child.type === 'JSXStyleElement') return false;
return true;
}
diff --git a/packages/octane/tests/compiler/strong-dom.test.ts b/packages/octane/tests/compiler/strong-dom.test.ts
--- a/packages/octane/tests/compiler/strong-dom.test.ts
+++ b/packages/octane/tests/compiler/strong-dom.test.ts
@@ -399,6 +399,19 @@
expectStrongValid(source, '/src/App.tsx');
});
+ it('allows mounting into a container whose only children are scoped style blocks', () => {
+ expectStrongValid(
+ `${IMPORTS}export function Chart({ data }) @{
+ const container = useRef(null);
+ useEffect(() => { container.current.appendChild(document.createElement('canvas')); });
+ <div ref={container} class="chart">
+ <style>.chart { display: block; }</style>
+ </div>
+}`,
+ '/src/Chart.tsrx',
+ );
+ });
+
it('does not prove a ref declared outside the @for row that attaches it', () => {
expectStrongValid(
`${IMPORTS}export function List({ items }) @{You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit f001359. Configure here.
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]>
Benchmark reportNo benchmark report for this commit yet: PR bench is still running or skipped this change. CI job durations
Compares the CI run for
All 26 timed jobs
|
…trong-dom-writes # Conflicts: # docs/differences-from-react.md # docs/strong-compiler-checks.md # docs/tsrx-basics.md # packages/octane/src/compiler/strong-dom.js # packages/octane/tests/compiler/strong-dom.test.ts # website/public/llms.txt # website/src/content/docs/build-tools.mdx


Summary
Strong mode now rejects imperative writes, through a ref, to DOM that the template renders (issue #1027, item 1). The checks apply only to Strong modules; compatibility mode and emitted code are unchanged.
OCTANE_STRONG_MANAGED_DOM_WRITEreports a write to anything the template owns on the element:textContent,innerText,append,appendChild,insertBefore,prepend,removeChild,replaceChild, orreplaceChildrenon an element with rendered children;className,classListmutators, orclassList.valuewhen the template sets a class;setAttribute,removeAttribute, ortoggleAttributefor an attribute the template sets, using Octane's own prop-to-attribute table;style,style.cssText, or astyleproperty the template sets.OCTANE_STRONG_RAW_HTML_WRITEreportsinnerHTML,outerHTML,insertAdjacentHTML(), orsetHTMLUnsafe()on a rendered element, and namesdangerouslySetInnerHTML={trustHTML(html)}as the replacement.Why
A probe on main @ 85cb387 found that all three of these compiled under Strong:
r.current.textContent = label.toUpperCase()on<p ref={r}>{label}</p>r.current.className = …on<p ref={r} className="base" />r.current.innerHTML = htmlThe write overwrites or corrupts nodes that Octane reconciles. The server HTML never contains the result either, because effects don't run there.
Changes
New
packages/octane/src/compiler/strong-dom.js, a standalone pass that reuses Strong's existing hook-scope analysis.strong-mode.jsgains one import and one call.A write is reported only when the ref provably names exactly one intrinsic DOM element in the same component, or the same keyed
@forrow.The ref may be used only in these ways, or the proof is withdrawn:
refprop, including inside aref={[a, b]}list;.currentreads andconst { current } = ref;A component
refprop, a helper argument, a.currentwrite, or a second element all withdraw it. An inline callback ref's parameter counts as that element.Writes to DOM the template doesn't own stay valid:
textContenton an element without rendered children, mounting a widget into an empty container, astyleproperty the template'sstyledoesn't set,focus(), and measurement.New
packages/octane/tests/compiler/strong-dom.test.tscovers:.tsrx, including refs declared in@forrows and the{ref}attribute shorthand;.tsmodules;Docs: a "DOM ownership" section in
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: a full local run with a 12 GB heap passed 82,876 tests with 2 failures. Both pass in isolation: one is a load-sensitive browser timeout, the other a pristine upstream Base UI test. The machine was heavily loaded, and with the default heap the root Vitest process ran out of memory. CI is the authority here.Targeted: all
strong-*compiler suites plusvolar.test.ts, 1,275 tests passing.Breaking each rule on purpose (no escape tracking, ignoring the component/row boundary, assuming children, ignoring
stylekeys) turns tests red.Compiled 3,479 real repo files under Strong. Both new write diagnostics are true positives:
packages/react-map-gl:appendChildinto a<div>that renders an@ifblock;packages/xyflowViewport:style.transformwhere the template'sstylealso setstransform.Both bindings stay in compatibility mode, so nothing breaks.
Throughput: the pass is gated per top-level statement and walks 550 of 40,517 statements in that corpus. With the companion render checks, the Strong analyzer is +4.8% on real code, about +1% of a whole Strong compile. The paired
benchmarks/strong-compiler-checksaudit stays within noise.Risk / follow-ups
transformin the template for first paint and SSR, then writes it imperatively every frame. Per the brief this is rejected under Strong, and there is no Strong-clean equivalent today.OCTANE_STRONG_OWN_MARKUP_QUERYon top of this one.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Strong-only compile-time diagnostics can break builds for apps that imperatively mutate template-owned DOM via refs; runtime and compatibility mode are unchanged.
Overview
Strong mode now errors when imperative ref writes touch DOM that the template owns, without changing compatibility mode or emitted code.
A new compiler pass (
analyzeStrongDOM, wired fromstrong-mode.js) tracks refs that provably name a single intrinsic element in the component or@forrow, then flagsOCTANE_STRONG_MANAGED_DOM_WRITEfor child-list, class, attribute, and style mutations the template already controls, andOCTANE_STRONG_RAW_HTML_WRITEforinnerHTML/ adjacent HTML APIs (with guidance towarddangerouslySetInnerHTML={trustHTML(...)}). Ref proof is withdrawn if the binding escapes (component ref prop, reassignment, multiple elements, etc.). Tests cover.ts/.tsrx, Volar, and pinned output; docs add a DOM-ownership section to the Strong checks reference.Reviewed by Cursor Bugbot for commit e430476. Bugbot is set up for automated code reviews on this repo. Configure here.