Skip to content

fix(core, solid): print edge whitespace in JSX inside expression containers as in children lists - #1367

Merged
jonkwheeler merged 1 commit into
tsrx-org:mainfrom
jonkwheeler:w14/1351-expression-jsx-text
Nov 18, 2026
Merged

jonkwheeler merged 1 commit into
tsrx-org:mainfrom
jonkwheeler:w14/1351-expression-jsx-text

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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.

Target main: {<div> 123 </div>} This PR
@tsrx/react, @tsrx/preact, @tsrx/hono const A__static2 = <div> 123 </div>; const A__static2 = <div>{' '}123{' '}</div>;
@tsrx/solid {<div> 123 </div>} {<div>{' '}123{' '}</div>}
@tsrx/vue {<div>{' '}123{' '}</div>} unchanged
  • React, Preact, Hono: since perf(core): hoist static JSX that an expression container renders #1279 (@tsrx/core 0.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, renamed lower_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.
  • Solid: create_element_children never applied the rule, so JSX in a container, an attribute value, a callback, a const, a module-level declaration, or an element nested in an @if/@switch/@for/@try body printed as written. It now returns wrapEdgeWhitespace(...).
  • Vue: already printed both forms with {' '}; 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 @if body) 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:

    • React SSR writes <div> <!-- -->123<!-- --> </div>.
    • A component's children is [' ', 'a', ' '], so a component typed children: string gets TS2322 in the editor.
    • React throws for <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-only children) 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 and children: string gets an array #1368.

Editor

wrapEdgeWhitespace gave 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. wrapEdgeWhitespace also returns its input when it wraps nothing.

Not covered

  • A component's own single-text output fragment, return <> a </>, still prints as written on every target. const x = <> a </> is wrapped.
  • Ripple's to_ts calls wrapEdgeWhitespace too. It picks up the location fix once @tsrx/ripple moves to this core; in this repo it resolves its published @tsrx/core 0.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:

    • the issue example, and the same in a template body
    • ?: and && branches
    • an attribute value
    • a .map callback
    • a container in a static element
    • module-level JSX
    • an edge tab
    • a two-space edge

    One 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 JsxTextEdgeApp fixture covers a space, two spaces and a tab, each in five positions:

    • a child
    • a container
    • a container inside a hoisted static
    • an attribute value
    • an arrow

    It compares textContent on React, Preact, Solid, Vue and Hono DOM.

  • Mutation, run against the 143 matching tests:

    Reverted Failing tests Which
    Static wrap 21 React/Preact/Hono compile
    Location change 18 mapping cases
    Solid change 17 9 compile, 8 runtime
  • npx -y [email protected] test: 15,169 passed, 102 skipped. typecheck, format:check and changeset:check pass.

  • Compiling all 106 tracked .tsrx files 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, string children, and Solid control-flow bodies), which the changeset now states.

Fixes #1351

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46

…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
jonkwheeler marked this pull request as ready for review November 17, 2026 20:28
@jonkwheeler
jonkwheeler merged commit bd00fda into tsrx-org:main Nov 18, 2026
10 checks passed
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
@github-actions github-actions Bot mentioned this pull request Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: tsrx-core, react, preact, hono, solid: JSX inside {…} keeps its text as written, while the same JSX in a children list prints spaces as {' '}

1 participant