Skip to content

Commit 6bdf837

Browse files
committed
fix(compiler): use globalThis.Symbol to prevent shadowing by user components
1 parent 88ee1f5 commit 6bdf837

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,13 @@ function codegenReactiveScope(
748748
true,
749749
),
750750
t.callExpression(
751-
t.memberExpression(t.identifier('Symbol'), t.identifier('for')),
751+
t.memberExpression(
752+
t.memberExpression(
753+
t.identifier('globalThis'),
754+
t.identifier('Symbol'),
755+
),
756+
t.identifier('for'),
757+
),
752758
[t.stringLiteral(MEMO_CACHE_SENTINEL)],
753759
),
754760
);
@@ -968,7 +974,13 @@ function codegenReactiveScope(
968974
'!==',
969975
t.identifier(name),
970976
t.callExpression(
971-
t.memberExpression(t.identifier('Symbol'), t.identifier('for')),
977+
t.memberExpression(
978+
t.memberExpression(
979+
t.identifier('globalThis'),
980+
t.identifier('Symbol'),
981+
),
982+
t.identifier('for'),
983+
),
972984
[t.stringLiteral(EARLY_RETURN_SENTINEL)],
973985
),
974986
),
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {identity} from 'shared-runtime';
2+
3+
function Symbol() {
4+
return <div>I am a component named Symbol</div>;
5+
}
6+
7+
function Component({value}) {
8+
const x = identity(value);
9+
return <Symbol>{x}</Symbol>;
10+
}
11+
12+
export const FIXTURE_ENTRYPOINT = {
13+
fn: Component,
14+
params: [{value: 'hello'}],
15+
};

0 commit comments

Comments
 (0)