#1518·ripple

[Bug]: TS view wraps a JSX spread child (`{...items}`) in an IIFE, and `<>{...items}</>` throws (with @tsrx/core 0.4.0)

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

[!IMPORTANT] Part of the upgrade (#1520). This doesn't happen with Ripple's pinned @tsrx/core 0.3.3, where {...items} is a parse error. It appears with 0.4.0 and later. Fix it together with the core bump in #1520, which targets 0.5.0.

Issue Category

Compilation Bug

Bug Description

Since @tsrx/core 0.4.0 (tsrx-org/tsrx#495), the parser reads JSX spread children (<div>{...items}</div>), and core's analyzer reports them for every target: JSX spread children (`{...items}`) are not supported. Render the array as an expression child instead: `{items}`. Core's own targets keep {...items} in their editor output, so TypeScript still checks the spread. Ripple's TS view (compile_to_volar_mappings) doesn't handle the node:

  • In an element, the spread child is treated as a statement and wrapped in an IIFE, {(() => { {...items} })()}. TypeScript then reports four syntax errors (TS1128 and three TS1381) on top of the compile error.
  • In a fragment whose only child is a spread (<>{...items}</>), compile_to_volar_mappings throws No source map entry for position "2:3".

With the pinned @tsrx/core 0.3.3, a spread child is a parse error, so this shows up with the upgrade to 0.4.0 or later. Client and server builds report the unsupported-spread error, as expected.

Expected: the TS view keeps {...items}, as core's targets do, and only the compile error is reported.

Reproduction Steps

From the repository root at 83ed5615968364a077cbd39bc26a74e4d8c12b11, point @tsrx/core at 0.4.0 (for example '@tsrx/core': 0.4.0 under overrides in pnpm-workspace.yaml) and run pnpm install. Then:

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

const sources = [
	`export function App({ items }: any) @{
	<div>{...items}</div>
}`,
	`export function App({ items }: any) @{
	<>{...items}</>
}`,
];

for (const source of sources) {
	try {
		const { code, errors } = compile_to_volar_mappings(source, 'App.tsrx', { loose: true });
		const file = ts.createSourceFile('App.tsx', code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
		console.log(code.split('\n').filter((line) => !line.startsWith('import ')).join('\n'));
		console.log('compile errors:', errors.map((e) => e.message.slice(0, e.message.indexOf(' Render'))));
		console.log('TSX syntax errors:', file.parseDiagnostics.map((d) => `TS${d.code}`).join(', ') || 'none');
	} catch (error) {
		console.log('throws:', error.message);
	}
	console.log('---');
}
JS

Output:

export function App({ items }: any) {
return <div>{(() => {
		{...items}
	})()}</div>;
}
compile errors: [ 'JSX spread children (`{...items}`) are not supported.' ]
TSX syntax errors: TS1128, TS1381, TS1381, TS1381
---
throws: No source map entry for position "2:3"
---

@tsrx/react prints return <div>{...items}</div>; and return <>{...items}</>; for the same sources, with no syntax errors.

Cause

Three places in packages/tsrx-ripple/src/transform/client/index.js don't know JSXSpreadChild:

  • transform_tsrx_tsx_child has no case for it and returns undefined. So transform_tsrx_tsx_children collects it as a statement and wraps it in an IIFE.
  • build_tsrx_ts_return_expression keeps a lone text child as a fragment, but has no such case for a lone spread child. {...items} has no single-value form, so it has to stay a fragment child.
  • The TS-view printer (create_tsx_with_typescript_support) prints the node with esrap's visitor, which writes {... and } without locations. @tsrx/core's mapping step then finds no generated position for the spread child's start and throws. @tsrx/core marks the start and end of JSXSpreadChild in its own printer for this reason.

Suggested fix

diff
--- a/packages/tsrx-ripple/src/transform/client/index.js
+++ b/packages/tsrx-ripple/src/transform/client/index.js
@@ -5692,6 +5692,10 @@ function build_tsrx_ts_return_expression(children, in_jsx_child, loc_node) {
 			return setLocation(b.jsx_fragment([only]), /** @type {AST.NodeWithLocation} */ (only));
 		}
+		if (/** @type {AST.Node} */ (only).type === 'JSXSpreadChild') {
+			// `{...items}` has no single-value form: keep it as a fragment child.
+			return setLocation(b.jsx_fragment([only]), /** @type {AST.NodeWithLocation} */ (only));
+		}
 		if (only.type === 'JSXExpressionContainer' && !in_jsx_child) {
 			return only.expression;
 		}
@@ -5845,6 +5849,17 @@ function transform_tsrx_tsx_child(node, context) {
 		return setLocation(b.jsx_text(value, value), /** @type {AST.NodeWithLocation} */ (node));
 	}

+	if (node.type === 'JSXSpreadChild') {
+		// Analysis reports spread children as unsupported. The TS view keeps
+		// `{...items}`, so TypeScript still checks its expression.
+		return /** @type {TsrxTsxChild} */ (
+			/** @type {unknown} */ ({
+				...node,
+				expression: context.visit(node.expression, context.state),
+			})
+		);
+	}
+
 	if (node.type === 'JSXExpressionContainer') {
 		// A `{/* comment */}` container renders nothing.
 		if (is_empty_expression_container(node)) {
@@ -8349,6 +8364,18 @@ function create_tsx_with_typescript_support(comments) {
 			context.newline();
 			context.write('}');
 		},
+		JSXSpreadChild(node, context) {
+			// esrap writes `{...` and `}` without locations: mark the node's
+			// start and end so the editor can map it.
+			if (!node.loc) {
+				base_tsx.JSXSpreadChild?.(node, context);
+				return;
+			}
+			const loc = /** @type {AST.SourceLocation} */ (node.loc);
+			context.location(loc.start.line, loc.start.column);
+			base_tsx.JSXSpreadChild?.(node, context);
+			context.location(loc.end.line, loc.end.column);
+		},
 		UpdateExpression(node, context) {
 			if (!node.loc) {
 				base_tsx.UpdateExpression?.(node, context);

I checked this against tsrx main (f73b6760: 0.4.0 plus pending changes). With it, {...items} prints as written and the TS view has no syntax errors in these places:

  • in an element and in a plain function's JSX;
  • alone in a fragment, and in a setup statement's fragment;
  • next to text and other children;
  • in a {…} container's element.

The unsupported-spread error is still reported in each case. The full test suite is unchanged: the only failures are the 4 from #1516.

If #1514 moves the printer's location handling to esrap, the JSXSpreadChild visitor may no longer be needed.

Additional Context

Found while checking the @tsrx/core upgrade: #1520.

Environment

  • Ripple main at 83ed5615968364a077cbd39bc26a74e4d8c12b11, @tsrx/ripple 0.2.4, esrap 2.3.2
  • @tsrx/core 0.4.0 (published), tsrx main at f73b6760, and tsrx-org/tsrx#711 (c71ebf37) give the same output. The pinned 0.3.3 rejects the syntax.
  • Node 24.18.0, macOS 26.6.2

Checklist

  • I've searched for existing issues