Skip to content

feat(compiler): reject element descriptor APIs and single-item @for in Strong mode - #2055

Merged
trueadm merged 3 commits into
mainfrom
feat/strong-element-api
Oct 14, 2026
Merged

trueadm merged 3 commits into
mainfrom
feat/strong-element-api

Conversation

@trueadm

@trueadm trueadm commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Adds the Strong compile error OCTANE_STRONG_ELEMENT_API for modules outside the .tsx/.jsx dialect (.tsrx, .ts, and other plain modules). It fires on createElement, cloneElement, isValidElement, Children, or descriptorChildren from octane / octane/server, whether reached as a named import, a namespace member (Octane.createElement, Octane['Children']), or namespace destructuring. It also fires on jsx, jsxs, jsxDEV, or Fragment imported from octane/jsx-runtime, octane/jsx-dev-runtime, or their octane/strong/* variants.
  • Type-only imports (import type { ElementDescriptor }, import { type Children }) stay legal. Shadowed namespaces and look-alike names from other modules stay legal too. Strong .tsx and .jsx are exempt because their return <jsx> lowers to descriptors by design.
  • Adds the Strong compile error OCTANE_STRONG_SINGLE_ITEM_FOR for an @for over a one-item array literal, such as @for (const item of [source]; key item), whatever the binding pattern (const item, const { a, b }) or key (header, constant, or row-root key={…}). It also fires for a const holding a one-item literal (const one = [value]) when no other identifier in the module spells that name. Literals with two or more items, spreads, and holes stay valid.

Why

  • OCTANE_STRONG_ELEMENT_API is step 1 of the plan to keep Strong template modules off the generic descriptor renderer, which makes their performance predictable. It follows the existing OCTANE_STRONG_MAP_JSX and OCTANE_STRONG_COMPAT_IMPORT bans. On its own the check removes no bytes, because childSlot still reaches the descriptor renderer statically. The runtime driver gate waits for Runtime vision: render computes, commit writes — one compiled commit model #2043/perf(octane): render computes, commit writes — runtime size redesign (#2043) #2044.
  • OCTANE_STRONG_SINGLE_ITEM_FOR: agents use a one-row @for to bind a value or to force a remount. .rulesync/rules/tsrx-authoring.md already forbids this, and the error enforces it. The replacement is React's keyed remount: <Fragment key={value}>…</Fragment> or a key on the only element or component. To render one value, render it directly.

Changes

  • packages/octane/src/compiler/strong-template-policy.js:
    • The import check now covers element APIs and JSX-runtime entries. The three namespace-access sites (member, destructuring, JSX member) share one namespaceAccess helper with OCTANE_STRONG_COMPAT_IMPORT instead of three copies of that check.
    • The visitor flags a single-item literal @for directly. It records single-item const ids and identifier iterables as it goes, and one walk in finish() drops any name that another identifier spells, so an alias that is read, mutated, or shadowed elsewhere is never flagged. That walk runs only when the module has both a single-item const and an @for over an identifier.
    • Valid programs compile to the same output as before.
  • packages/octane/src/compiler/strong-diagnostics.js: two catalog entries in templates. OCTANE_STRONG_ELEMENT_API sits next to OCTANE_STRONG_COMPAT_IMPORT, and OCTANE_STRONG_SINGLE_ITEM_FOR next to OCTANE_STRONG_INDEX_KEY. pnpm sync regenerated docs/strong-compiler-checks.md, the website Strong-mode reference (anchors #octane-strong-element-api and #octane-strong-single-item-for), llms.txt, the MCP server JSON, and the CLI data.
  • The element-API message suggests template JSX, passing the component itself (icon={Plus}), or a () => @{ … } render function. The compiler marks <tsrx> blocks as legacy, so the message does not suggest them.
  • .rulesync/rules/tsrx-authoring.md names OCTANE_STRONG_SINGLE_ITEM_FOR in its existing "do not use a single-item @for" sentence. The generated copies come from pnpm rules:generate.
  • Fixtures:
    • packages/octane/tests/strong-manual-memo.test.ts: the Strong .tsrx fixtures imported createElement without using it, and the Strong plain-.ts fixtures built their markup with it. The plain fixtures now import paragraph and buttons from a non-Strong ./view runtime module through the loader's existing runtimeModules option, and their assertions are unchanged.
    • packages/octane/tests/_fixtures/suspense-superseded-arm.tsrx is the only single-item-loop fixture compiled with strong: true, from suspense-preserves-dom.test.ts. Its keyed @for row case covers replacing a keyed @for row beside a suspended arm (Keyed child disappears after a pending update is superseded #1698), which is row machinery rather than a remount trick. It now iterates a real one-row list from a selectionRows() helper, so it keeps testing the same @for path in Strong dev and prod.
    • packages/octane/tests/_fixtures/fragment-sibling-slots.tsrx: fragment-sibling-slots.test.ts compiles it with strong: true, and its ForRow case covers sibling slots at a @for row's fragment root. Its const rows = ['row'] alias tripped the new check in CI, so the row now comes from a oneRow() helper. I found it by Strong-compiling all 3,231 .tsrx files in the repo: the only other OCTANE_STRONG_SINGLE_ITEM_FOR hits are in fixtures no test compiles with Strong on. The other single-item loops (descriptor-children-shadowing, ssr-invalid-nesting, ssr-suspense, markerless-arm-retry, stale-leading-component-range) are not compiled with Strong on, since no vitest project enables Strong globally, so they are unchanged.
  • Other Strong modules in the repo (evals datasets, tests, website) contain neither pattern. The evals' @for literals all have three items.
  • Changeset: octane minor, covering both codes.

Validation

  • targeted tests (--project octane): strong-template-policy.test.ts (72 passed), strong-diagnostics-catalog.test.ts, and suspense-preserves-dom.test.ts all pass. I also ran every test file that combines Strong with element APIs: auto-memo, bundler-compiler, compiler-vite-options, native-reads, strong-html, volar, hydration/signal-instance-identity, layout-snapshot, private-context, signals-dom-bindings, and strong-manual-memo.
  • OCTANE_STRONG_ELEMENT_API tests cover client and server compile, slotHooks (.ts), and Volar editor diagnostics, plus the .tsx/.jsx exemption, type-only imports, shadowed namespaces, Fragment from octane, and createElement from another module. Four mutations each turn them red: dropping the .tsx exemption (7 failures), dropping the type-only skip (1), dropping the namespace check (2), and dropping the JSX-runtime check (2).
  • OCTANE_STRONG_SINGLE_ITEM_FOR tests cover client and server compile and Volar diagnostics. The rejected cases are a literal keyed by its item, a literal with a constant key, a literal with a row-root key, a local alias, and a module alias. The allowed cases are several items, a spread, an alias that grows, and a shadowed alias. Four mutations each turn them red: dropping the literal check (3 failures), dropping alias following (2), dropping the other-reference drop (2), and counting spreads (1). The pre-change suspense-superseded-arm.tsrx fails to compile under Strong at line 43.
  • pnpm typecheck:files on the changed test files and fixture
  • pnpm format:files:check on every changed file (llms.txt has no Prettier parser)
  • pnpm sync; the tree was clean after each commit
  • pnpm format:check, pnpm typecheck, pnpm test: not run locally under the machine-load rule. CI covers them.
  • perf-review: node scripts/perf-review-scan.mjs and node scripts/perf-review-scan.mjs packages/octane/src/compiler/ found 0 candidates. Both changes are compile-time Strong diagnostics: no runtime source, no compiled-output change, and no new runtime import. The added compile cost, in Strong modules only, is one specifier loop per import, one set lookup per namespace member, one array check per @for, and at most one AST walk per module.
  • concise-code: authored src +93 −29 in strong-template-policy.js plus +18 in the catalog; runtime +0 −0. The other src lines are generated JSON. No new files except the changeset, and no new exports. Alternatives considered:
    • Give JSX-runtime namespace imports a binding kind in strong-mode.js predeclareStatements. That adds a binding shape for a pattern that cannot run, since those entries are types-only, so I rejected it.
    • Resolve single-item aliases through createLexicalAnalysis scopes. That was about 15 more lines; the name match can never flag a list that isn't single-item, and only misses an alias whose name is reused elsewhere in the module, so I rejected it.
    • Bytes: not applicable (compiler only).

Risk / follow-ups

  • Plain .js/.mjs Strong modules are checked like .ts. Only the JSX dialect (.tsx/.jsx) is exempt, matching where descriptors are the intended lowering.
  • A value namespace import of a JSX runtime (import * as R from 'octane/jsx-runtime'; R.jsx(…)) is not flagged. Those entries are types-only, so such code cannot bundle anyway.
  • OCTANE_STRONG_SINGLE_ITEM_FOR does not follow a one-row list produced by a function call (rows(value)), a let, or an alias whose name appears anywhere else in the module. Those misses are deliberate, so the check never flags a real list.
  • Deferred, as planned: lowering value-position JSX in Strong .tsrx to compiled renderables (step 2), and gating childSlot's descriptor path behind a creator-installed driver (step 3, after Runtime vision: render computes, commit writes — one compiled commit model #2043/perf(octane): render computes, commit writes — runtime size redesign (#2043) #2044).

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.


Note

Medium Risk
Adds Strong compile errors that can break builds for .tsrx/plain Strong modules using descriptor APIs or one-item @for remount tricks; no runtime change for code that already compiles.

Overview
Strong mode gains two new compile-time errors (minor octane release), with catalog/docs/rules synced and tests/fixtures updated so existing Strong suites keep passing.

OCTANE_STRONG_ELEMENT_API applies to Strong modules that are not .tsx/.jsx (e.g. .tsrx, plain .ts). It rejects imports or namespace use of descriptor builders/inspectors from octane (createElement, cloneElement, isValidElement, Children, descriptorChildren) and of jsx / jsxs / jsxDEV / Fragment from Octane JSX runtime entrypoints. Type-only imports, shadowed names, and Strong .tsx/.jsx stay allowed.

OCTANE_STRONG_SINGLE_ITEM_FOR flags @for over a one-element array literal (or a module-unique const one-item alias only used as a loop iterable)—patterns often used for keyed remounts instead of <Fragment key={…}> or direct rendering.

Implementation lives in strong-template-policy.js (shared namespaceAccess, @for / alias analysis in finish()). Valid programs still compile to the same output; only new diagnostics and doc/generated JSON churn.

Reviewed by Cursor Bugbot for commit 91813bd. Bugbot is set up for automated code reviews on this repo. Configure here.

…s modules

Strong modules outside the .tsx/.jsx dialect now report
OCTANE_STRONG_ELEMENT_API for createElement, cloneElement,
isValidElement, Children, and descriptorChildren from octane (named
imports, namespace member access, and namespace destructuring), and for
jsx/jsxs/jsxDEV/Fragment from Octane's JSX runtime entries. Descriptors
render through the generic descriptor renderer instead of compiled
templates. Type-only imports stay valid, and Strong .tsx keeps them.

The namespace checks share one helper with OCTANE_STRONG_COMPAT_IMPORT.
The Strong useMemo/useCallback plain-module fixtures now take their
markup from a non-Strong view module.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 14, 2026 14:38
@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 14, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
⚠️ Deployment skipped
View logs
octane-website 91813bd Oct 14 2026, 03:28 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
⚠️ Deployment skipped
View logs
octane-website-mcp 91813bd Oct 14 2026, 03:28 PM

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No byte growth, no added work, and no timing changes beyond ±3%.

Compares f7b41dccc, the merge commit's first parent with 7c20e61ee on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 3.583 3.575 ±0.0% −7.8% … +3.9% ⚪ within noise
octane-tsrx replace 9.450 9.717 +2.0% −12.3% … +12.1% ⚪ within noise
octane-tsrx add 3.367 3.375 −1.8% −6.6% … +9.4% ⚪ within noise
octane-tsrx update 0.133 0.155 +6.9% +0.0% … +13.1% ⚪ within noise
octane-tsrx select 0.007 0.007 ±0.0% −4.4% … +10.2% ⚪ within noise
octane-tsrx swap 0.023 0.023 −0.9% −10.6% … +5.0% ⚪ within noise
octane-tsrx remove 0.021 0.019 +0.4% −8.6% … +8.8% ⚪ within noise
octane-tsrx runlots 34.292 34.675 −4.5% −13.0% … +14.4% ⚪ within noise
octane-tsrx select_lots 0.008 0.008 −5.6% −11.0% … +2.0% ⚪ within noise
octane-tsrx clear 66.450 62.275 −1.4% −7.7% … +8.0% ⚪ within noise
octane-jsx run 4.667 4.642 ±0.0% −2.7% … +5.2% ⚪ within noise
octane-jsx replace 10.025 9.433 −2.8% −8.4% … −0.0% ⚪ within noise
octane-jsx add 4.133 4.492 −2.4% −5.2% … +11.5% ⚪ within noise
octane-jsx update 0.313 0.329 −1.4% −9.4% … +10.5% ⚪ within noise
octane-jsx select 0.161 0.172 −0.5% −7.4% … +8.8% ⚪ within noise
octane-jsx swap 0.202 0.207 +1.3% −3.7% … +4.0% ⚪ within noise
octane-jsx remove 0.190 0.202 +3.1% −3.2% … +9.3% ⚪ within noise
octane-jsx runlots 38.175 40.500 +5.4% −1.7% … +14.7% ⚪ within noise
octane-jsx select_lots 2.053 2.029 −1.5% −7.7% … +7.7% ⚪ within noise
octane-jsx clear 63.308 61.175 −1.1% −4.2% … +1.0% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 93 measured values.

Public-import reachability bundles (bytes)

No changes across 120 measured values.

Strong .tsrx modules now report OCTANE_STRONG_SINGLE_ITEM_FOR for an
@for whose iterable is a one-item array literal, whatever its binding
pattern or key, and for a const holding one when no other identifier in
the module spells its name. Multi-item literals, spreads, and holes stay
valid. The replacement is React's keyed remount: <Fragment key={value}>
or a key on the only element or component.

suspense-superseded-arm.tsrx compiles with strong: true and its keyed
@for case covers row replacement (#1698), so it now iterates a real
one-row list instead of a literal. The tsrx-authoring rule names the
new code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm trueadm changed the title feat(compiler): reject element descriptor APIs in Strong .tsrx and .ts modules feat(compiler): reject element descriptor APIs and single-item @for in Strong mode Oct 14, 2026
fragment-sibling-slots.test.ts compiles its fixture with strong: true,
and ForRow covers sibling slots at a @for row's fragment root. Its
`const rows = ['row']` alias now trips OCTANE_STRONG_SINGLE_ITEM_FOR,
so the row comes from a helper instead of a single-item literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit 1f4ccb8 into main Oct 14, 2026
31 of 33 checks passed
@trueadm
trueadm deleted the feat/strong-element-api branch October 14, 2026 15:58
trueadm added a commit that referenced this pull request Oct 14, 2026
…note

The element API changeset from #2055 is unreleased and ships with this
change, which makes Strong .tsx modules a compile error. Its ".tsx may
keep these APIs" wording no longer holds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 14, 2026
* feat(compiler): reject element descriptor APIs in Strong .tsrx and .ts modules

Strong modules outside the .tsx/.jsx dialect now report
OCTANE_STRONG_ELEMENT_API for createElement, cloneElement,
isValidElement, Children, and descriptorChildren from octane (named
imports, namespace member access, and namespace destructuring), and for
jsx/jsxs/jsxDEV/Fragment from Octane's JSX runtime entries. Descriptors
render through the generic descriptor renderer instead of compiled
templates. Type-only imports stay valid, and Strong .tsx keeps them.

The namespace checks share one helper with OCTANE_STRONG_COMPAT_IMPORT.
The Strong useMemo/useCallback plain-module fixtures now take their
markup from a non-Strong view module.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(compiler): reject single-item @for loops in Strong mode

Strong .tsrx modules now report OCTANE_STRONG_SINGLE_ITEM_FOR for an
@for whose iterable is a one-item array literal, whatever its binding
pattern or key, and for a const holding one when no other identifier in
the module spells its name. Multi-item literals, spreads, and holes stay
valid. The replacement is React's keyed remount: <Fragment key={value}>
or a key on the only element or component.

suspense-superseded-arm.tsrx compiles with strong: true and its keyed
@for case covers row replacement (#1698), so it now iterates a real
one-row list instead of a literal. The tsrx-authoring rule names the
new code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(octane): keep the Strong fragment-sibling @for row a real list

fragment-sibling-slots.test.ts compiles its fixture with strong: true,
and ForRow covers sibling slots at a @for row's fragment root. Its
`const rows = ['row']` alias now trips OCTANE_STRONG_SINGLE_ITEM_FOR,
so the row comes from a helper instead of a single-item literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(compiler): reject Strong .tsx and .jsx modules

Strong mode renders through compiled templates, but JSX in a .tsx or .jsx
module lowers to element descriptors. A .tsx/.jsx module that "use strong"
or the application compiler.strong policy reaches now reports
OCTANE_STRONG_TSX_MODULE in client, server, and editor compilation. The
rest of the analysis still runs, so collectDiagnostics and
`octane analyze --strong-preview` list the module's other findings.

With no Strong .tsx left, OCTANE_STRONG_ELEMENT_API applies to every Strong
module, and the createElement raw-HTML check it now subsumes is removed.
Migration recipes, the MCP server recipes and skills, the Strong docs and
website guide, and the Strong compiler tests move to .tsrx.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(changeset): drop the Strong .tsx exemption from the element API note

The element API changeset from #2055 is unreleased and ships with this
change, which makes Strong .tsx modules a compile error. Its ".tsx may
keep these APIs" wording no longer holds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test: move the remaining Strong .tsx probes to .tsrx

direct-signal-bindings ran its Strong matrix over .tsx too, and
strong-hook-cache compiled its returned-JSX Strong case as .tsx; both now
report OCTANE_STRONG_TSX_MODULE. The .tsx compatibility cells stay, and the
returned-JSX Strong form now runs as a .tsrx module. The MCP explain test
expects the tsrx recipe fences.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 15, 2026
Brings in #2047-#2051 (Strong literal stabilisation), #2054 (checked
compiled boundaries and a compiled router entry), #2055/#2057 (Strong
rejects descriptor APIs and .tsx/.jsx), #2056/#2060/#2061 (CLI Strong
reports), #2062 (Strong in the website and devtools), #2065 (no
browser-translation DOM accommodations) and Version Packages.

Conflicts, resolved so main's behaviour lands on the redesign's commit model:
- runtime.ts, #2065: setText keeps main's legacy host-only convention and the
  redesign's hydration writeText. The translator recovery is gone from
  renderText/commitText, setRenderText/commitSetText, commitHole,
  childTextHoleUpdate, recordHole and bindSignalChild; removeOnlyChildText
  still removes a committed Text at commit. resetOnlyChildHost and
  PENDING_HOST_TEXTS (which served only the host-only text writes) are deleted.
- compile.js, #2065: text updates call setRenderText(_txt, v), commit
  functions setText(_txt, v), and commitHole takes no host.
- runtime.server.ts, #2054: a compiled-only frame checks its output;
  ordinary frames keep the redesign's returned-value normalization.
- codes.json: main's 344-346 (CompiledContext, CompiledOutlet) keep their
  numbers; the redesign's codes move to 347 (server boundary error), 348
  (hydration protocol skew) and 349 (frontier rehome). Generated tables and
  CLI data are regenerated; docs/ssr.md names #348.

Adaptations:
- compiled-boundaries.test.ts: the server runs no error boundary (React's
  model), so an invalid CompiledOutlet under a catch-only @Try fails
  renderToString with the CompiledOutlet error; the client still shows the
  catch arm.
- scripts/render-writers.mjs drops resetOnlyChildHost.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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