Skip to content

Bug: React Compiler should not encode in JSX prop value #29120

@SukkaW

Description

@SukkaW

React version: 19.0.0-beta-26f2496093-20240514

Steps To Reproduce

Link to code example:

Input Code

'use client';

function Comp() {
  return (
    <div aria-label="我能吞下玻璃而不伤身体">
      我能吞下玻璃而不伤身体
    </div>
  )
}

React Compiler Output

function Comp() {
  const $ = _c(1);

  let t0;

  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = (
      <div aria-label="\u6211\u80FD\u541E\u4E0B\u73BB\u7483\u800C\u4E0D\u4F24\u8EAB\u4F53">
        我能吞下玻璃而不伤身体
      </div>
    );
    $[0] = t0;
  } else {
    t0 = $[0];
  }

  return t0;
}

React Compiler Playground

Babel / SWC / ESBuild JSX transform

SWC:

"use client";
import { jsx as _jsx } from "react/jsx-runtime";
function Comp() {
    var $ = _c(1);
    var t0;
    if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
        t0 = _jsx("div", {
            "aria-label": "\\u6211\\u80FD\\u541E\\u4E0B\\u73BB\\u7483\\u800C\\u4E0D\\u4F24\\u8EAB\\u4F53",
            children: "我能吞下玻璃而不伤身体"
        });
        $[0] = t0;
    } else {
        t0 = $[0];
    }
    return t0;
}

SWC Playground

Babel:

"use strict";
'use client';

var _jsxRuntime = require("react/jsx-runtime");
function Comp() {
  const $ = _c(1);
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      "aria-label": "\\u6211\\u80FD\\u541E\\u4E0B\\u73BB\\u7483\\u800C\\u4E0D\\u4F24\\u8EAB\\u4F53",
      children: "\u6211\u80FD\u541E\u4E0B\u73BB\u7483\u800C\u4E0D\u4F24\u8EAB\u4F53"
    });
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  return t0;
}

Babel REPL

ESBuild:

'use client'

import { jsx } from "react/jsx-runtime";
function Comp() {
  const $ = _c(1);
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = /* @__PURE__ */ jsx("div", { "aria-label": "\\u6211\\u80FD\\u541E\\u4E0B\\u73BB\\u7483\\u800C\\u4E0D\\u4F24\\u8EAB\\u4F53", children: "\u6211\u80FD\u541E\u4E0B\u73BB\u7483\u800C\u4E0D\u4F24\u8EAB\u4F53" });
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  return t0;
}

ESBuild REPL

The current behavior

The prop value becomes double escaped.

The expected behavior

The prop value should only be escaped once.

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