Repository navigation
perf(core): hoist a fully static fragment as one constant - #1372
Merged
jonkwheeler merged 3 commits intoNov 18, 2026
Merged
Conversation
…ainers as in children lists
The spaces and tabs at the edges of an element's children print as
`{' '}` (tsrx-org#1277), but JSX inside a `{…}` container kept its text as
written on React, Preact, Hono and Solid, so
`<><div> 123 </div>{<div> 123 </div>}</>` printed two forms (tsrx-org#1351).
- React, Preact, Hono: a static hoisted out of a container (tsrx-org#1279)
leaves the walk that applies the rule. lower_static_script_bodies,
renamed lower_static_jsx, already redoes the walk's `<script>`
lowering for a static; it now also wraps each children list in the
static. This covers a container inside a bare static element too.
- Solid: create_element_children returns wrapEdgeWhitespace(...), so
JSX in a container, an attribute value, a callback, a `const`, a
module-level declaration or nested in a control-flow body gets the
rule. Solid's compiler collapses a whitespace run in JSX text but
keeps a `{' '}` literal, so `{<b> 1 </b>}` now renders " 1 "
like a children list instead of " 1 ".
- Vue already printed both forms the same; its output is unchanged.
In those places an element's text with edge whitespace now gets three
children instead of one string, as in a children list, so React's
existing <textarea>/<title> problem with that shape reaches them too.
wrapEdgeWhitespace returns its input when it wraps nothing, and gives
the trimmed text the location of what is left of it: with the whole
text's location, a `@` after a space (`<div> @</div>`) mapped one
character early and got no directive completion, in a children list
and now in a container.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
React, Preact and Hono hoisted static JSX element by element (tsrx-org#1279), so a fragment whose elements were all hoisted was still built again around their constants on every render. `<><div> 1 </div>{<><div> 2 </div><div> 3 </div></>}</>` gave three constants; it now gives one `const B__static1 = <>…</>;` and `return B__static1;` (tsrx-org#1352). Hoisting itself is unchanged. Once a component's output is lowered, each fragment in it that holds at least one static, and otherwise only text, literals and fragments of these, is replaced by one static that takes in the statics it held, with the name and place of the first of them. A static's reference is known by the declaration it points to, not by its name, and a static is taken in only through its one reference. Since it reads the output as lowered, the static prints each text as the fragment in place did, so server markup and text nodes stay the same wherever the walk wraps or leaves edge whitespace. It takes in no element tsrx-org#1279 left in place, so every element is built when it was before, and no component inside the fragment renders less often. A memoized component that receives the fragment as a prop or as children can skip a render, as it can for a single hoisted element since tsrx-org#1279. A keyed `@for` row is a keyed element by then, so it keeps its key and stays in place. Solid, Vue and Hono DOM don't hoist, and their output is byte-identical. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler
marked this pull request as ready for review
November 18, 2026 21:20
tsrx-org#1367 is now on main as bd00fda, and tsrx-org#1369 as 4500db9. This merge takes main in with tsrx-org#1367's commit as the base, so the tree is main plus this branch's own commit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
Merged
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
React, Preact and Hono hoist static JSX element by element (#1279). A fragment whose elements were all hoisted was still built again, around their constants, on every render.
export function B() { return <><div> 1 </div>{<><div> 2 </div><div> 3 </div></>}</>; }gave three constants. It now givesconst B__static1 = <><div>{' '}1{' '}</div>{<><div>{' '}2{' '}</div><div>{' '}3{' '}</div></>}</>;andreturn B__static1;. mizulu's fragment of ten static<div>s gives one constant instead of ten.#1279's hoisting is unchanged. Once a component's output is lowered, a fragment becomes one static that takes in the statics it held when two things are true:
The new static takes the name and place of the first static it took in. A static's reference is known by the declaration it points to, not by its name.
value/checkedis still set again on re-render, and nothing new is evaluated at module load.@forrow is a keyed element, and it keeps its key.Checked against 34a7ec8 with two rounds of differential matrices (React SSR, client and hydration; Preact; Hono SSR) and all tracked
.tsrxfiles. Solid, Vue and Hono DOM are byte-identical, and editor mappings cover the same ranges. Two differences remain:@forwhose row fragment folds, React dev reports the missing key once, as it does for a hoisted element body.Known, and the same as since #1279:
Tests
App__static_fold1;renderToStringsuite pinned to the in-place markup for 13 body shapes, including a fragment that is a body's only output.valueis set again.npx -y [email protected] test: 15,307 passed, 102 skipped.typecheck,format:checkandchangeset:checkpass.Fixes #1352
🤖 Generated with Claude Code
https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
Note
Medium Risk
Touches JSX codegen for React/Preact/Hono rendering, but behavior is gated to safe static-only fragments and covered by broad compile/runtime/mapping tests.
Overview
Adds
fold_static_fragmentsin the React/Preact/Hono JSX lowering path so a fragment made only of already-hoisted elements (plus text, static literals, or nested static fragments) collapses into one module-level__staticconstant instead of re-wrapping separate statics on every render.Static hoists now return declaration-linked references (
static_declarationon identifiers) so folding can merge single-use statics and rewrite the static list without breaking identity or memoization semantics. Solid, Vue, and Hono DOM output is unchanged.Tests and fixtures are updated across compile, content-mapper, and runtime harnesses (including new whole-fragment markup and render-count cases) to lock in correct markup, keys, component re-render behavior, and editor diagnostics when fragments are hoisted as a unit.
Reviewed by Cursor Bugbot for commit 377030a. Bugbot is set up for automated code reviews on this repo. Configure here.