Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3516,6 +3516,22 @@ function lowerJsxElement(
text = exprPath.node.value;
} else {
text = trimJsxText(exprPath.node.value);
/*
* If the decoded value trimmed to null, the text may still contain
* meaningful content that Babel decoded from HTML entity references
* (e.g. ` ` → space). In that case, trimming the decoded value
* discards the intentional whitespace. Preserve it by trimming the
* raw source instead so that the entity reference is retained in the
* output JSX and decoded correctly by the standard JSX transform.
*/
if (text === null) {
const rawValue = (
exprPath.node.extra as {raw?: string} | undefined
)?.raw;
if (rawValue != null) {
text = trimJsxText(rawValue);
}
}
}

if (text === null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

## Input

```javascript
// Ensure HTML entity references in JSX text (e.g.  ) are preserved after
// compilation and not stripped as whitespace-only nodes.
function MyApp() {
return (
<div>
&#32;
<span>hello world</span>
</div>
);
}

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime"; // Ensure HTML entity references in JSX text (e.g. &#32;) are preserved after
// compilation and not stripped as whitespace-only nodes.
function MyApp() {
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = (
<div>
{"&#32;"}
<span>hello world</span>
</div>
);
$[0] = t0;
} else {
t0 = $[0];
}
return t0;
}

```

### Eval output
(kind: exception) Fixture not implemented
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Ensure HTML entity references in JSX text (e.g. &#32;) are preserved after
// compilation and not stripped as whitespace-only nodes.
function MyApp() {
return (
<div>
&#32;
<span>hello world</span>
</div>
);
}
Loading