Repository navigation
Description
Note
This is a bug today, on Octane main with the published @tsrx/core 0.4.0 and @tsrx/oxc 0.16.0. It doesn't depend on @tsrx/core 0.5.0. The fix is in @tsrx/oxc (tsrx-org/oxc#110). Octane then picks up that release and adds the test.
Summary
On Node, Octane renders two kinds of comment in JSX text as text:
- a
//line comment in template text; - a
/* … */block comment in the text of JSX in a plain function.
The browser compiler leaves both out, and so do the other TSRX targets. The TSRX specification says comments between template children "are permitted … and do not render" (4.3 Template Elements).
The difference comes from the parser. On Node, parser.node.js parses with @tsrx/oxc's tsrx-core-compat, which keeps these comments in JSXText.value. The browser compiler (parser.browser.js) and the editor parse with @tsrx/core, which leaves them out:
| Source | @tsrx/oxc 0.16.0 value |
@tsrx/core 0.4.0 value |
|---|---|---|
template text with a // note line |
the // note line is in value |
the // note line is left out |
<p>a /* note */ b</p> in a plain function |
"a /* note */ b" |
"a b" |
normalizeAuthoredJsxLiterals then cooks whatever value holds, so the comment reaches the template and the SSR string.
@tsrx/oxc 0.16.0 is its latest release. A /* … */ comment in template text is already left out of value by both parsers. The parser side is tsrx-org/oxc#110.
Reproduction
At e813fc0e6d (current main), after pnpm install --frozen-lockfile --ignore-scripts, save this as packages/octane/repro.mjs and run node repro.mjs from packages/octane:
import { compile } from 'octane/compiler';
const sources = {
template: `export function App() @{
<p>
a
// note
b
</p>
}`,
'plain function': `export function App() {
return <p>a /* note */ b</p>;
}`,
};
for (const [name, source] of Object.entries(sources)) {
for (const mode of ['client', 'server']) {
const { code } = compile(source, 'App.tsrx', { mode, hmr: false });
console.log(name, mode, code.split('\n').find((line) => line.includes('<p>')).trim());
}
}Output:
template client const _t$0 = /* @__PURE__ */ _$template("<p>a // note b</p>");
template server return _$ssrHtml(`${`<p>${`a // note b`}</p>`}`);
plain function client const _t$0 = /* @__PURE__ */ _$template("<p>a /* note */ b</p>");
plain function server return _$ssrHtml(`${`<p>${`a /* note */ b`}</p>`}`);
With #octane/compiler-parser resolved to parser.browser.js (checked with a Node resolve hook), the same script prints:
template client const _t$0 = /* @__PURE__ */ _$template("<p>a b</p>");
template server return _$ssrHtml(`${`<p>${`a b`}</p>`}`);
plain function client const _t$0 = /* @__PURE__ */ _$template("<p>a b</p>");
plain function server return _$ssrHtml(`${`<p>${`a b`}</p>`}`);
Expected: <p>a b</p> from both compilers.
Suggested fix
- Pick up the
@tsrx/oxcrelease that fixes Comments in JSX text stay in the text'svalueandraw, where@tsrx/coreleaves them out tsrx-org/oxc#110, wheretsrx-core-compatleaves comments out ofJSXText.valuewherever@tsrx/coredoes. - Add a test that compiles the same source with both parsers and compares the text of client and SSR output, with a
//comment in template text and a/* … */comment in plain-function JSX text. It would also catch the other parser differences listed in the@tsrx/coreupgrade issue, Upgrading to the next @tsrx/core (0.5.0): template textraw,>in text, and the coming decodedvalue#1330.
Activity
fix: address the TSRX 0.5 upgrade issues
fix: update the TSRX toolchain to @tsrx/core 0.5 and the new formatter (