Skip to content

[Compiler Bug]: incorrectly uses variable name as JSX tag (<base />) instead of referenced value #35268

@icyJoseph

Description

@icyJoseph

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://playground.react.dev/#N4Igzg9grgTgxgUxALhASwLYAcIwC4AEASggIZyEBmMEGBA5DGRfQNwA6AdnBJ2IQCNSYBAQC8DACZoAbmy5cefQgBUE-AMK0cnBJzzJizPADoAYhvEEAFAEpxAPgLAuBAkv4Et2K0JEdONyY8WECAHm8sAHoHLgBfAK4EAA8cfAJJBEpSKAAbKihuPDReAgAJWgQ7Z1cCYNCCMLVNbV49Qhj4rhAAGhAlSjQAcxR0bFxCPABPLFFgAgAFXKghtE4AeSxi3jACOIJqWgYhAQRcgFosZdXOc6ZyPHOebDRchBgo6X55Ti5rF0CBCiUWeWFepG2nAAshBMoZ2CBSLlcgj4gQwBC0GBBupFtc1ptIWBbKxeuAABYQADuAEl9O9OEiwChsrkRHEgA

Repro steps

Given this input:

import React from 'react';
const base = 'div';

const TestComponent: React.FC = () => {
  const Comp = base;
  return <Comp/>
};

export default function Home() {
  return <TestComponent />
}

The compiler outputs this for the TestComponent

const TestComponent: React.FC = () => {
  const $ = _c(1);
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = <base />;
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  return t0;
};

First reported here: vercel/next.js#86728

This outputs a <base /> tag instead of a div.

I searched on issues before posting, but I couldn't find other reports.

How often does this bug happen?

Every time

What version of React are you using?

Next.js' version on 16.0.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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions