Skip to content

[Compiler Bug]: Compiler breaks JSX pragma handling for Oxc/SWC/TS #36460

@swandir

Description

@swandir

What kind of issue is this?

  • React Compiler core (the JS output is incorrect, or your app works incorrectly after optimization)
  • babel-plugin-react-compiler (build issue installing or using the Babel plugin)
  • eslint-plugin-react-hooks (build issue installing or using the eslint plugin)
  • react-compiler-healthcheck (build issue installing or using the healthcheck script)

Link to repro

https://stackblitz.com/edit/vitejs-vite-9eantx6h

Repro steps

React Compiler adds an import declaration to the top of the module, before leading comments.

React Compiler playground

While this works file with Babel's JSX transform (playground), other tools don't respect JSX pragma (e.g. @jsxImportSource) comments that come after any code statement, including imports.

Oxc playground

SWC playground

TypeScript playground

It's common to integrate React Compiler into a build process that handles JSX transform using Oxc/SWC. And current compiler's behavior prevents code with JSX pragmas from working in such a setup.

React Compiler should probably keep JSX pragmas and other leading comments/directives at the top.

How often does this bug happen?

Every time

What version of React are you using?

19.2.6

What version of React Compiler are you using?

1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugType: Bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions