#1519·ripple

[Bug]: TS view prints template text decoded, so `>`, `<`, `&gt;` and `&#123;x&#125;` reach TypeScript bare

Author: leonidazCreated Sep 26, 2026Updated Sep 29, 2026
Labelsbug

[!NOTE] A bug today. The fix needs @tsrx/core 0.5.0 or later, for tsrx-org/tsrx#711's raw without comments. 0.5.0 and 0.5.1 are published. Fix it together with the core bump in #1520, which now goes straight to 0.5.2 (updated 2026-09-29).

Issue Category

Compilation Bug

Bug Description

Ripple's TS view (compile_to_volar_mappings) prints template text as the string Ripple decoded for rendering, not as it's written. A character that JSX text can't hold reaches TypeScript bare, and a character reference turns into the character it stands for:

  • <div><span /> > 5</div> prints a bare > (TS1382).
  • <span><3</span> prints a bare < (TS1003).
  • &gt; prints as > (TS1382), and &lt; as <.
  • &#123;x&#125; prints as {x}, an expression that reads an undeclared x.
  • A <script> body is printed the same way. const value = 1 < 2 ? 'a' : 'b'; in packages/ripple/tests/client/head.test.tsrx and packages/ripple/tests/server/head.test.tsrx gets a bare < (TS1003).

The client and server builds are correct. Only the editor output is wrong. It happens on every @tsrx/core version I tried: 0.3.3 (pinned), 0.4.0, tsrx main, and tsrx-org/tsrx#711.

Expected: the TS view writes the text as written, with <, >, { and } as &lt;, &gt;, &#123; and &#125;. @tsrx/core's own printer does this for the other targets from tsrx-org/tsrx#711 on (escape_jsx_text).

Reproduction Steps

From the repository root at 83ed5615968364a077cbd39bc26a74e4d8c12b11, after pnpm install:

bash
cd packages/tsrx-ripple
node --input-type=module <<'JS'
import { readFileSync } from 'node:fs';
import { compile_to_volar_mappings } from './src/index.js';
import ts from 'typescript';

const sources = {
	'a `>` in text': `export function App() @{
	<div><span /> > 5</div>
}`,
	'character references': `export function App() @{
	<p>&#123;x&#125; &gt; 1</p>
}`,
	'head.test.tsrx': readFileSync('../ripple/tests/client/head.test.tsrx', 'utf8'),
};

for (const [name, source] of Object.entries(sources)) {
	const { code } = compile_to_volar_mappings(source, 'App.tsrx', { loose: true });
	const file = ts.createSourceFile('App.tsx', code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
	const [first] = file.parseDiagnostics;
	console.log(`${name}: ${file.parseDiagnostics.map((d) => `TS${d.code}`).join(', ') || 'no syntax errors'}`);
	if (first) console.log(`  ${code.split('\n')[file.getLineAndCharacterOfPosition(first.start).line].trim()}`);
}
JS

Output:

a `>` in text: TS1382
  return <div><span /> > 5</div>;
character references: TS1382
  return <p>{x} > 1</p>;
head.test.tsrx: TS1003
  const value = 1 < 2 ? 'a' : 'b';

Cause

transform_tsrx_tsx_child builds the TS view's text with b.jsx_text(value, value). Its value comes from get_template_text_value, which runs Ripple's decode_jsx_text_entities, so the node's raw is the decoded text. The TS view is printed with esrap's tsx language (create_tsx_with_typescript_support). Its JSXText visitor writes raw ?? value without escaping.

tsrx-org/tsrx#711 fixes the same bug for @tsrx/core's targets in core's printer, which Ripple doesn't use.

Suggested fix

Keep the text as written on the node, and escape <, >, { and } when the TS view prints it:

diff
--- a/packages/tsrx-ripple/src/template-ast.js
+++ b/packages/tsrx-ripple/src/template-ast.js
@@ -60,6 +60,19 @@ export function get_template_text_value(node, to_ts) {
 	return decode_jsx_text_entities(normalized);
 }

+/** @type {Record<string, string>} */
+const JSX_TEXT_ESCAPES = { '<': '&lt;', '>': '&gt;', '{': '&#123;', '}': '&#125;' };
+
+/**
+ * JSX text as the TypeScript view prints it: the text as written, with the
+ * characters JSX text can't hold written as character references.
+ * @param {string} raw
+ * @returns {string}
+ */
+export function escape_jsx_text(raw) {
+	return raw.replace(/[<>{}]/g, (ch) => JSX_TEXT_ESCAPES[ch]);
+}
+
--- a/packages/tsrx-ripple/src/transform/client/index.js
+++ b/packages/tsrx-ripple/src/transform/client/index.js
@@ -5842,7 +5843,10 @@ function transform_tsrx_tsx_child(node, context) {
 	if (node.type === 'JSXText') {
 		const value = get_template_text_value(node, true);
-		return setLocation(b.jsx_text(value, value), /** @type {AST.NodeWithLocation} */ (node));
+		return setLocation(
+			b.jsx_text(value, node.raw ?? value),
+			/** @type {AST.NodeWithLocation} */ (node),
+		);
 	}
@@ -8279,6 +8283,9 @@ function create_tsx_with_typescript_support(comments) {
 	return /** @type {Visitors<AST.Node, TransformClientState>} */ ({
 		...base_tsx,
+		JSXText(node, context) {
+			context.write(escape_jsx_text(node.raw ?? node.value), node);
+		},
 		_(node, context, visit) {

escape_jsx_text also needs importing from ../../template-ast.js in the client transform.

Two requirements:

  • It needs @tsrx/core with tsrx-org/tsrx#711. Before #711, template text's raw is the source slice, comments between children included: <p>a /* c */ b</p> has raw a /* c */ b, while value leaves the comment out. #711 makes raw the text as written without comments. It also makes core's wrapEdgeWhitespace, which Ripple calls on the TS view's children, keep raw instead of rebuilding each text as jsx_text(value, value). So this change belongs with the @tsrx/core upgrade that brings #711.
  • Escape at print time, not in raw. #711's completion mapping for text that starts with @ (segments.js) matches the node's raw against the source. When I stored the escaped text in raw instead, the mapping for <div>@if > x</div> covered @if > x</d in the source for @if &gt; x in the output. With the escaping in the printer, it maps @if to @if .

I checked this against #711's core. I compiled 2,191 sources: Ripple's and tsrx's .tsrx files and test sources, and generated text shapes in 20 template places. The change removes the TS-view syntax errors from 260 of the 269 sources that had them. The other 9 don't involve text: invalid inputs from error tests, an expected-HTML string, #1517, and #1518. Client and server output don't change, and the full test suite is unchanged: the only failures are the 4 from #1516.

Additional Context

  • tsrx-org/tsrx#711: escape_jsx_text, core's JSXText printer, template text raw, and wrapEdgeWhitespace.
  • tsrx-org/tsrx#710 makes template text's value decoded, in @tsrx/core 0.5.2 (tsrx-org/tsrx#972). With this change in place, the TS view already prints raw, so #710 doesn't affect it. Ripple's runtime decoding is a separate matter, covered in #1520, the upgrade issue.
  • #1514 changes the same printer's root visitor. The new JSXText visitor is independent of it.

Environment

  • Ripple main at 83ed5615968364a077cbd39bc26a74e4d8c12b11, @tsrx/ripple 0.2.4, @tsrx/core 0.3.3, esrap 2.3.2
  • The same TS view with @tsrx/core 0.4.0, tsrx main (f73b6760), and tsrx-org/tsrx#711 (c71ebf37)
  • Node 24.18.0, macOS 26.6.2

Checklist

  • I've searched for existing issues