Skip to content

Rust compiler outputs raw JSX in .flatMap()/.map() callbacks instead of $$render tagged template literals #19

@scottvrable

Description

@scottvrable

Astro Info

Astro                    v6.1.2
Vite                     v7.3.1
Node                     v22.12.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When a template contains .flatMap() or .map() expressions that assign JSX to variables and return arrays, the Rust compiler outputs raw JSX instead of wrapping it in $$render...`` tagged template literals. This produces invalid JavaScript that Rollup cannot parse.

The Go compiler correctly wraps all template expressions — including deeply nested ones inside callbacks — in tagged template literals.

Template pattern that triggers the bug:

{features.flatMap((feature) => {
  const mainRow = (
    <tr><td>{feature.title}</td></tr>
  );
  const detailRows = feature.description
    ? feature.description.map((line) => (
        <tr><td>{line}</td></tr>
      ))
    : [];
  return [mainRow, ...detailRows];
})}

Rust compiler output (invalid — raw JSX):

const mainRow = (
  <tr>
    <td>{feature.title}</td>
  </tr>
);

Go compiler output (correct — tagged template literal):

const mainRow = (
  $$render`<tr>
    <td>${feature.title}</td>
  </tr>`
);

Build error:
Expression expected (Note that you need plugins to import files that are not JavaScript)

What's the expected result?

he Rust compiler should wrap JSX inside callback expressions with $$render tagged template literals, matching the Go compiler's behavior.

Link to Minimal Reproducible Example

https://github.com/scottvrable/astro-rust-compiler-repro

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions