Repository navigation
fix(core, solid): print edge whitespace in JSX inside expression containers as in children lists - #1367
Merged
jonkwheeler merged 1 commit intoNov 18, 2026
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
jonkwheeler
marked this pull request as ready for review
November 17, 2026 20:28
jonkwheeler
added a commit
to jonkwheeler/tsrx
that referenced
this pull request
Nov 18, 2026
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
JSX inside an expression container now gets the same edge-whitespace handling as JSX in a children list (#1277):
<><div> 123 </div>{<div> 123 </div>}</>prints<div>{' '}123{' '}</div>for both elements on all five targets.{<div> 123 </div>}@tsrx/react,@tsrx/preact,@tsrx/honoconst A__static2 = <div> 123 </div>;const A__static2 = <div>{' '}123{' '}</div>;@tsrx/solid{<div> 123 </div>}{<div>{' '}123{' '}</div>}@tsrx/vue{<div>{' '}123{' '}</div>}@tsrx/core0.6.0), a static hoisted out of a container skips the walk that applies the rule. Before perf(core): hoist static JSX that an expression container renders #1279 the container printed{<div>{' '}123{' '}</div>}. The pass that already redoes the walk's<script>lowering for a static (lower_static_script_bodies, renamedlower_static_jsx) now also wraps every children list in the static. That also covers a container inside a bare static element (<div>{<span> a </span>}</div>), which no earlier version wrapped.create_element_childrennever applied the rule, so JSX in a container, an attribute value, a callback, aconst, a module-level declaration, or an element nested in an@if/@switch/@for/@trybody printed as written. It now returnswrapEdgeWhitespace(...).{' '}; output unchanged.What renders differently
These places now render the way the same JSX in a children list already does:
Solid text: babel-preset-solid reads a whitespace run in JSX text as one space but keeps a
{' '}literal. So<b> 1 </b>in a children list rendered" 1 ", while{<b> 1 </b>}(or the same<b>nested in an@ifbody) rendered" 1 ", and an edge tab became a space. Both now render" 1 "and keep the tab. With one space at each edge, nothing changes.Three children instead of one string (React, Preact, Hono, Solid). Text with edge whitespace in these places is now
' ','a',' ', as in a children list:<div> <!-- -->123<!-- --> </div>.childrenis[' ', 'a', ' '], so a component typedchildren: stringgets TS2322 in the editor.<textarea> a </textarea>(one child only) and renders<title> a </title>empty.All of this already happens on main for the same JSX in a children list (
<><textarea> a </textarea></>throws on React today), so it's an existing limit of the fix(language-server): list<script>body declarations as document symbols #1277 rule, not new here. Whether<textarea>/<title>(and string-onlychildren) should be left unwrapped or printed as one literal is a separate change to that rule, for every position: [Bug]: tsrx-core: edge whitespace turns an element's only text into three children, so React's<textarea>throws,<title>renders empty andchildren: stringgets an array #1368.Editor
wrapEdgeWhitespacegave the trimmed text the location of the whole text, spaces included. So its@completion mapped one character early (" @i"→"@if"), and<div> @</div>offered no directive completion. That's already the case in children lists, and this change would have spread it to containers. The text now gets the location of what is left of it, which fixes both.wrapEdgeWhitespacealso returns its input when it wraps nothing.Not covered
return <> a </>, still prints as written on every target.const x = <> a </>is wrapped.to_tscallswrapEdgeWhitespacetoo. It picks up the location fix once@tsrx/ripplemoves to this core; in this repo it resolves its published@tsrx/core0.3.3.Tests
packages/tsrx/tests/shared/compile.js, on all five targets, has 9 cases where the child form and the{…}form must print the same element:?:and&&branches.mapcallbackOne more case checks that text touching a newline stays as written. The
@completion loop adds<div> @</div>,{<div> @</div>}and{<div> @if </div>}, and now asserts that each mapping's source text equals its generated text.Runtime: a shared
JsxTextEdgeAppfixture covers a space, two spaces and a tab, each in five positions:It compares
textContenton React, Preact, Solid, Vue and Hono DOM.Mutation, run against the 143 matching tests:
npx -y [email protected] test: 15,169 passed, 102 skipped.typecheck,format:checkandchangeset:checkpass.Compiling all 106 tracked
.tsrxfiles on five targets, main vs this branch, changes only the new fixture plus two Solid fixtures that render the same.Reviewed independently by Opus and Codex (gpt-6.1-sol). Their findings were the rendered changes above (the
<textarea>/<title>shape, stringchildren, and Solid control-flow bodies), which the changeset now states.Fixes #1351
🤖 Generated with Claude Code
https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46