Skip to content

Commit 04e623e

Browse files
martypdxcursoragent
andcommitted
fix: skip JSX comments in HTML template generation
JSX comments {/* ... */} were generating anchor placeholders (<!--0-->) in the HTML output even though Analyzer correctly skipped them for binding index calculations. This mismatch caused rendering artifacts. HtmlGenerator.JSXExpressionContainer now checks for JSXEmptyExpression (which includes comments) and skips them, matching Analyzer behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 0e947e4 commit 04e623e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

packages/thoth/transform/HtmlGenerator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export class HtmlGenerator extends Generator {
9393

9494
// {...}
9595
JSXExpressionContainer(node, state) {
96+
// Skip empty expressions (comments: {/* ... */})
97+
if(node.expression?.type === 'JSXEmptyExpression') return;
9698
state.write(this.childReplace);
9799
}
98100

packages/thoth/transform/template-generators.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,20 @@ describe('render generator', () => {
246246
expect(code).toMatchInlineSnapshot(`"__renderer("a84dfd44", null, null, false, \`<p>static</p>\`)"`);
247247
});
248248

249+
test('jsx comments are ignored', ({ compile, expect }) => {
250+
// JSX comments {/* ... */} should not generate anchor placeholders
251+
const code = compile(`({ title }) => <div>
252+
{/* Title is optional */}
253+
{title && <h1>{title}</h1>}
254+
</div>`);
255+
256+
// Only one <!--0--> for the conditional, none for the comment
257+
expect(code).toMatchInlineSnapshot(`"__renderer("77ff2813", g24227028, b6b86b273, false, \`<div>
258+
259+
<!--0-->
260+
</div>\`)"`);
261+
});
262+
249263

250264
test('props and elements', ({ compile, expect }) => {
251265
const code = compile(`const t = <p className={"className"}>

0 commit comments

Comments
 (0)