Skip to content

Upgrading to the next @tsrx/core (0.5.0): template text raw, > in text, and the coming decoded value #1330

Closed

Description

@leonidaz

Important

Updated 2026-09-29. @tsrx/core 0.5.0 and 0.5.1 are published, and the upgrade is open as #1399 (^0.5.1). tsrx-org/tsrx#710 is fixed in tsrx-org/tsrx#972, which is open and ships in 0.5.2, a patch, not a later minor as planned before.

Summary

The next @tsrx/core release is a minor, 0.5.0: tsrx-org/tsrx#732 makes the changeset of tsrx-org/tsrx#713 (an element in a spread attribute's argument, or in an attribute value without braces, is template markup) a minor, and every other pending changeset is a patch. Octane's catalog range ^0.4.0 won't pick it up by itself. The upgrade needs the catalog entry bumped to ^0.5.0, the lockfile updated, and the new version added to minimumReleaseAgeExclude, as for 0.4.0. This issue covers what it changes for Octane, checked against Octane main at e813fc0e6d.

How Octane reads JSX text today

Two parsers. parser.node.js parses with @tsrx/oxc's tsrx-core-compat first, and falls back to @tsrx/core only when oxc throws a syntax error. parser.browser.js parses with @tsrx/core. So:

  • On Node (Vite, the bundler plugins, the tests), a @tsrx/core parser change reaches compile() only for a file that oxc rejects, such as one with a > in its text.
  • The browser compiler, and volar.js on every platform, always parse with @tsrx/core. volar.js also prints the virtual TSX with core's createJsxTransform, so core's JSXText printer is Octane's editor output.
  • A few analyzers call @tsrx/core's parseModule directly when they aren't handed an AST: analyzeHydrateBoundaries, analyzeRendererBoundaries, validateRendererModuleSource in compile-universal.js, and the Vite plugin's preflight.

One place cooks text. compileAuthored runs normalizeAuthoredJsxLiterals once, before anything else reads the tree:

if (node.type === 'JSXText') {
	const lines = node.value.split(/\r\n|\n|\r/);
	// … JSX whitespace cleanup over the lines …
	if (value.includes('&')) value = decodeHTMLStrict(value);
	return value === node.value ? node : { ...node, value, raw: value };
}
if (
	node.type === 'JSXAttribute' &&
	node.value?.type === 'Literal' &&
	typeof node.value.value === 'string' &&
	node.value.value.includes('&')
) {
	const value = decodeHTMLStrict(node.value.value);
	return { ...node, value: { ...node.value, value, raw: JSON.stringify(value) } };
}

It does the whitespace cleanup on value as written, then decodes the references with entities' decodeHTMLStrict, and stores the decoded text as both value and raw. Everything after it treats that as the rendered string and escapes it again for HTML:

  • normalizeChildren makes it a Text literal, which is baked into templates through escapeHtml or written by the SSR emitter;
  • lowerJsxChild makes it a string argument of createElement;
  • the universal compiler gets the same tree and turns it into a plan's text with normalizeJsxText.

raw is never read for text. The only reads are fallbacks, child.value ?? child.raw in onlyMeaningfulJsxChild and child.value != null ? child.value : child.raw in lowerJsxChild. Both parsers always give a JSXText a string value, so neither reaches raw.

What tsrx-org/tsrx#711 changes

Template text's raw leaves out comments

In a TSRX template, a // or /* … */ comment between an element's children is a comment, not text: comments "are permitted between template children and do not render" (TSRX spec, 4.3). In the example below, a and b are the <p>'s text, one JSXText node, and the element renders a b. In plain TSX, the same JSX would render a /* c */ b, since JSX text has no comments.

That node's value has always left the comment out. Its raw, the text as written, kept it. #711 leaves the comment out of raw too, because core's printers now print raw and would otherwise print the comment back as text. The two spaces are the ones on each side of the comment.

export function App() @{
	<p>a /* c */ b</p>
}
JSXText @tsrx/core 0.4.0 and main with #711
value "a b" "a b"
raw "a /* c */ b" "a b"

Effect on Octane: none. raw isn't read (see above), and compile(), SSR, and the virtual TSX are the same. @tsrx/oxc 0.16.0 still gives raw: "a /* c */ b" (tsrx-org/oxc#110).

A > in an element inside a {…} container is text

export function App({ c }) @{
	<main>{c && <b>a > b</b>}</main>
}
@tsrx/core 0.4.0 and main with #711
JSXText value and raw "> b" (a dropped) "a > b"
<b>{c} a > b</b> in a container Unexpected token `>` parses, text " a > b"

@tsrx/oxc rejects a > in any template text (Unexpected token. Did you mean `{'>'}` or `&gt;`?), so on Node such a file always takes the @tsrx/core fallback. Effect on Octane: two fixes, on every platform.

// before: the text before `>` is lost
const _v = c && _$createElement('b', {}, '> b');
// with #711
const _v = c && _$createElement('b', {}, 'a > b');

{c && <b>{c} a > b</b>} failed to compile, and now compiles to _$createScopedElement('b', {}, () => _$positionalChildren([c, ' a > b'])). SSR output changes the same way.

Core's JSXText printer prints raw, escaping <, >, {, and }

This printer is used only by the virtual TSX (compileToVolarMappings). A > in text used to print bare, which TypeScript rejects in TSX (TS1382):

// before
const App__static1 = <p>a > b</p>;
// with #711
const App__static1 = <p>a &gt; b</p>;

References print as written (&amp;, &nbsp;), as before. The existing test "preserves literal less-than text in virtual TSX" in tests/compiler/volar.test.ts still passes. Octane's own output is printed by esrap's TSX printer, not this one.

What else changes on tsrx main since 0.4.0

These are the changesets in .changeset/ on tsrx main. The text changes come from tsrx-org/tsrx#615, #641, #656, and #657.

Source @tsrx/core 0.4.0 @tsrx/core main @tsrx/oxc 0.16.0
{c && <div><b>1</b> 2</div>} '2' ' 2' ' 2'
const a = <span><b>1</b> 2</span>; in a @{ … } body '2' ' 2' ' 2'
<p><b>t</b> then /* c */ <i /></p> on the next line <b>t</b> <i></i> <b>t</b><i></i> <b>t</b><i></i>
<p> + U+00A0 + line break + <b /></p> U+00A0 dropped U+00A0 kept U+00A0 dropped

The columns show Octane's compiled output with each parser. The first three were differences between Octane's two parsers, and the upgrade removes them. The last one is new: with the upgrade, the browser compiler renders a non-breaking space that the Node compiler drops. Core now treats only space, tab, and line breaks as JSX whitespace, and leaves the rest to the JSX compiler. Octane's own whitespace cleanup keeps the U+00A0, as Babel does, while TypeScript and esbuild trim it at the edge of a line. @tsrx/oxc should keep the node as core now does (tsrx-org/oxc#112); Octane's cleanup then decides whether it renders.

The change that makes the release a minor, tsrx-org/tsrx#713, reads an element in a spread attribute's argument (<div {...{ k: <b>…</b> }} />) or in an attribute value without braces (<div k=<b>…</b> />) as template markup, as one in a braced value already is: a comment in it is a comment, a directive is a directive, and its text follows the template text rules. On Node @tsrx/oxc parses these, so the change reaches Octane through the browser compiler, the fallback, and the editor, and no Octane test changed.

The other parser changes are new syntax errors and messages ('}' expected., '>' expected., Declaration or statement expected.), inputs that used to be accepted and are now rejected (export abstract function f() {}, decorators on object literal members, const [a?] = b, <b />.foo), and a few AST shape changes that Octane doesn't read (ImportExpression.options, TSImportType.options). On Node they reach Octane only through the fallback. Octane reads only ImportExpression.source.

Test results

From the repository root:

pnpm exec vitest run --project octane --maxWorkers=4

The octane project runs every packages/octane/tests/**/*.test.{ts,tsrx} file except the browser, React-compat, profiling, devtools, and signals-runtime suites. That's 634 files and 13,357 tests, including tests/compiler/** (compile, parser, Volar, Valdi, universal compiler), SSR, hydration, the universal runtime, and conformance.

packages/octane's @tsrx/core Passed Failed
0.4.0, as pinned 13,357 0
tsrx main (f73b6760) 13,356 1: a timeout in ssr-async-identity-encoding.test.ts
tsrx-org/tsrx#711 (c71ebf37) 13,356 1: a timeout in behavior-root.test.ts

Neither failure comes from the new core:

  • ssr-async-identity-encoding.test.ts tests a runtime string encoder over all 65,536 code units, with no compiler involved. It passes when run alone.
  • behavior-root.test.ts compiles tests/_fixtures/dom-presentation.tsrx. Octane's output for it is byte-identical with 0.4.0, main, and React 19 parity: outstanding gaps and follow-ups after #709 #711 (108 outputs: every view, client and server, dev and prod), and compiles as fast. The test that timed out took 13.8 s of its 15 s limit even with 0.4.0. It passed in 3 of 4 standalone runs with React 19 parity: outstanding gaps and follow-ups after #709 #711.
  • The linked core loads from outside node_modules, so Vitest transforms it: the runs' total import time went from 387 s to 509–551 s, which makes slow tests time out more often.

No test in the suite covers a > in text, a comment in text where raw changed, or a double-encoded reference such as &amp;lt;.

What Octane needs to change for this release

Required:

  • Bump the catalog's @tsrx/core to ^0.5.0, update the lockfile, and add the new version to minimumReleaseAgeExclude. No compiler change is needed for 0.5.0 itself.
  • Read text from raw (the first item in "What Octane should change for perf: reduce SSR HTML payload and hydration markers #710"), in the same change: the ^0.5 range picks up 0.5.2, which decodes text value.

Decided, and independent of the release:

  • Change packages/octane/tests/compiler/strong-mode.test.ts › "Strong mode template locality" › "respects a var hoisted within a nested template block". It expects a component whose nested @{ … } declares var count to compile, while the component's setup declares const [count]. TSRX decided that a var in a nested @{ … } or control-flow body belongs to the component function, as in JavaScript, so it conflicts with the const. @tsrx/core reports Identifier 'count' has already been declared, and so does compileToVolarMappings (in errors; the test only checks diagnostics). The test passes on Node only because @tsrx/oxc doesn't report redeclarations (Redeclared bindings and other scope errors parse without an error, where @tsrx/core reports them tsrx-org/oxc#113). It should expect that error from compile() in client and server mode and from compileToVolarMappings, and a var with a name of its own can keep covering var hoisting in nested template blocks. Until @tsrx/oxc reports redeclarations, compile() on Node won't throw, so the compile() half has to wait for that fix or use the browser parser.

Optional follow-ups:

  • Add a test for a > in an element in a {…} container, and after a child container ({c && <b>{c} a > b</b>}), in client, SSR, and Volar output. Nothing in the suite covers it today, so React 19 parity: outstanding gaps and follow-ups after #709 #711's fix changes no test.
  • Add a test that compiles the same sources with both parsers and compares the output. The browser compiler and the Node compiler already differ in the cases in the next section.

Parser differences between @tsrx/core and @tsrx/oxc

Found while checking this upgrade. They exist on main today, and they decide what Octane can read from JSXText for #710:

Source @tsrx/core (with #711) @tsrx/oxc 0.16.0 Filed
// comment on its own line in JSX text left out of value kept in value tsrx-org/oxc#110
/* c */ in the text of a plain function's JSX a comment text tsrx-org/oxc#110
/* c */ in template text left out of value and raw left out of value, kept in raw tsrx-org/oxc#110
attribute string title="a &amp;lt;" value decoded: a &lt; value as written: a &amp;lt; tsrx-org/oxc#111
U+00A0 next to a line break text dropped tsrx-org/oxc#112
a redeclared binding (let twice, or a var against a const) Identifier '…' has already been declared accepted tsrx-org/oxc#113
> in template text text syntax error not filed: Octane falls back to @tsrx/core

Two of these are Octane bugs today, filed separately:

The redeclaration row is why Octane's Node compiler accepts the strong-mode.test.ts source above, and why it compiles let count declared twice into output that esbuild rejects.

Also found while checking, and not about text:

Coming next: tsrx-org/tsrx#710 decodes template text value

tsrx-org/tsrx#972 implements tsrx-org/tsrx#710, and it ships in @tsrx/core 0.5.2. After it, a JSXText's value has its character references decoded, and each CRLF line break read as LF, and raw is the text as written, with no comments since #711. That's the JSX AST standard, and what acorn's JSX parser gives:

export function App() @{
	<p>a &amp; b &quot;c&quot; /* note */ &nbsp;&#123;x&#125;</p>
}
JSXText 0.4.0 and main with #711 after #710
value "a &amp; b &quot;c&quot; &nbsp;&#123;x&#125;" the same "a & b \"c\" \u00a0{x}"
raw "a &amp; b &quot;c&quot; /* note */ &nbsp;&#123;x&#125;" "a &amp; b &quot;c&quot; &nbsp;&#123;x&#125;" the same as #711

@tsrx/core's own printers already print raw since #711, so core's output doesn't change. Octane's does, because normalizeAuthoredJsxLiterals reads value and decodes it again.

What breaks

I simulated #710 by decoding value in core's #parseTemplateRawText with acorn-jsx's XHTMLEntities rules, on top of #711.

  • Double decoding wherever Octane compiles from @tsrx/core's parse (the browser compiler, and the Node fallback). The editor's virtual TSX prints raw and isn't affected.

    export function App() @{
    	<p>&amp;lt;b&amp;gt; &amp;amp;</p>
    }
    
    // today: renders `&lt;b&gt; &amp;`
    _$template("<p>&amp;lt;b&amp;gt; &amp;amp;</p>")
    // after #710: renders `<b> &`
    _$template("<p>&lt;b&gt; &amp;</p>")

    It's still escaped, so it can't inject markup, but the text is wrong. On Node, @tsrx/oxc doesn't decode value, so the same file renders correctly there, until it has a > in its text and falls back.

  • Whitespace cleanup runs on decoded text. An encoded line break (&#10;) or tab at the end of a line is then treated as layout:

    export function App() @{
    	<p>a&#10;
    		b</p>
    }
    
    // today (TypeScript's reading: cleanup on the text as written)
    _$template("<p>a\n b</p>")
    // after #710
    _$template("<p>a b</p>")
  • /^\s*$/ checks on a parser AST. Code that reads value from a tree that normalizeAuthoredJsxLiterals hasn't cooked sees decoded text. JavaScript's \s matches U+00A0, so text that is only &nbsp; becomes "whitespace" there. That covers isRenderableChild in hydrate-boundaries.js and in renderer-boundaries.js when they parse for themselves, and Valdi's isEmptyChild (&#59; also decodes to ; there). The cooked tree already has this, since cooking decodes too.

  • Not affected: supportsTypeScriptRetry in parser.browser.js reads value from acorn-typescript's own parse, and the emitters read the cooked string.

Tests with #710 simulated. The test suite doesn't see any of this: no fixture has a double-encoded reference or an encoded line break in its text.

  • On Node, with the same command, 13,346 of 13,357 passed. The 11 failures were timeouts in volar.test.ts, typescript-text-inference.test.ts, and hydration-ssr-diagnostics.test.ts, which pass when rerun alone, and timeouts plus the failures that follow them in behavior-root.test.ts, which compiles the same output as with 0.4.0.

  • Because Node parses with @tsrx/oxc first, I also ran the suite with parser.node.js re-exporting parser.browser.js's parseModule, as the browser compiler parses. With React 19 parity: outstanding gaps and follow-ups after #709 #711 alone, 70 tests failed, none about text:

    • 49 plain-module hook tests that go through the native fallback, whose modules have the <const T> function type from [Bug]: tsrx-core: A const type parameter in a function type, constructor type, or signature fails to parse tsrx-org/tsrx#731 (44 in manual-hook-arguments.test.ts);
    • 16 tests of parser.node.js's own native path and syntax errors (parser.test.ts, style-syntax-fallback.test.ts, hydrate-compiler.test.ts);
    • one strong-mode.test.ts test, "respects a var hoisted within a nested template block", which @tsrx/core 0.4.0 rejects too (Identifier 'count' has already been declared), while @tsrx/oxc accepts it. Core is right here; see What Octane needs to change;
    • 4 in behavior-root.test.ts's timing-sensitive textarea tests, which fail the same way in other runs.

    With perf: reduce SSR HTML payload and hydration markers #710 simulated as well, the same 70 failed, plus 22 timeouts that pass when rerun alone.

What Octane should change for #710

Cook text from the text as written, so the result doesn't depend on whether a parser decoded value:

The alternative is to keep reading value and drop Octane's own decoding once both parsers decode it: @tsrx/oxc decodes neither attribute strings nor text today (tsrx-org/oxc#111). That also changes two things users can see:

  • JSX parsers decode only the XHTML entity table, while decodeHTMLStrict decodes all of HTML5. &check; isn't in the XHTML table, so acorn, Babel, and TypeScript leave it as written, while Octane renders ✓.
  • The cleanup would run on decoded text, as in the &#10; example above.

Either way, this has to land with the 0.5 upgrade in #1399, or before the lockfile gets 0.5.2. #710's fix ships in 0.5.2 as a patch, so the ^0.5.1 range #1399 sets picks it up on the next lockfile refresh. The @tsrx/oxc side has an ordering constraint too: if @tsrx/oxc starts decoding attribute strings or text before Octane decodes from raw, Octane's Node output starts decoding twice as well.

How this was checked

Activity

  1. leonidaz commented on Sep 29, 2026

    @leonidaz
    CollaboratorAuthor

    Updated the timing box and the #710 section: tsrx-org/tsrx#710 is fixed in tsrx-org/tsrx#972 and ships in @tsrx/core 0.5.2 as a patch, not a later minor. The ^0.5.1 range in #1399 picks it up on the next lockfile refresh, so #1399 needs the text half too: normalizeAuthoredJsxLiterals cleans up and decodes the JSXText from raw, as #1399 already does for attribute strings. @tsrx/oxc 0.17.0 leaves comments out of raw (tsrx-org/oxc#110), so that works with both parsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions