Skip to content

Commit 7f88cd0

Browse files
committed
[compiler] treat ref-like identifiers as refs by default (#34005)
`@enableTreatRefLikeIdentifiersAsRefs` is now on by default. I made one small fix to the render helper logic as part of this, uncovered by including more tests. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34005). * #34027 * #34026 * #34025 * #34024 * __->__ #34005 DiffTrain build for [6891dcb](6891dcb)
1 parent 5cf31b6 commit 7f88cd0

35 files changed

+105
-89
lines changed

compiled/eslint-plugin-react-hooks/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30733,7 +30733,7 @@ const EnvironmentConfigSchema = zod.z.object({
3073330733
enableChangeDetectionForDebugging: ExternalFunctionSchema.nullable().default(null),
3073430734
enableCustomTypeDefinitionForReanimated: zod.z.boolean().default(false),
3073530735
hookPattern: zod.z.string().nullable().default(null),
30736-
enableTreatRefLikeIdentifiersAsRefs: zod.z.boolean().default(false),
30736+
enableTreatRefLikeIdentifiersAsRefs: zod.z.boolean().default(true),
3073730737
lowerContextAccess: ExternalFunctionSchema.nullable().default(null),
3073830738
validateNoVoidUseMemo: zod.z.boolean().default(false),
3073930739
});
@@ -48334,6 +48334,19 @@ function validateNoRefAccessInRenderImpl(fn, env) {
4833448334
const type = refTypeOfType(place);
4833548335
env.set(place.identifier.id, type);
4833648336
}
48337+
const interpolatedAsJsx = new Set();
48338+
for (const block of fn.body.blocks.values()) {
48339+
for (const instr of block.instructions) {
48340+
const { value } = instr;
48341+
if (value.kind === 'JsxExpression' || value.kind === 'JsxFragment') {
48342+
if (value.children != null) {
48343+
for (const child of value.children) {
48344+
interpolatedAsJsx.add(child.identifier.id);
48345+
}
48346+
}
48347+
}
48348+
}
48349+
}
4833748350
for (let i = 0; (i == 0 || env.hasChanged()) && i < 10; i++) {
4833848351
env.resetChanged();
4833948352
returnValues = [];
@@ -48447,10 +48460,13 @@ function validateNoRefAccessInRenderImpl(fn, env) {
4844748460
if (!didError) {
4844848461
const isRefLValue = isUseRefType(instr.lvalue.identifier);
4844948462
for (const operand of eachInstructionValueOperand(instr.value)) {
48450-
if (hookKind != null) {
48463+
if (isRefLValue || hookKind != null) {
4845148464
validateNoDirectRefValueAccess(errors, operand, env);
4845248465
}
48453-
else if (!isRefLValue) {
48466+
else if (interpolatedAsJsx.has(instr.lvalue.identifier.id)) {
48467+
validateNoRefValueAccess(errors, env, operand);
48468+
}
48469+
else {
4845448470
validateNoRefPassedToFunction(errors, env, operand, operand.loc);
4845548471
}
4845648472
}

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1d7e942da76c794c3cbf52a8c214d90a69814a8f
1+
6891dcb87db831db17ab109730dea63706875dd7
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1d7e942da76c794c3cbf52a8c214d90a69814a8f
1+
6891dcb87db831db17ab109730dea63706875dd7

compiled/facebook-www/React-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ __DEV__ &&
14341434
exports.useTransition = function () {
14351435
return resolveDispatcher().useTransition();
14361436
};
1437-
exports.version = "19.2.0-www-classic-1d7e942d-20250729";
1437+
exports.version = "19.2.0-www-classic-6891dcb8-20250729";
14381438
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14391439
"function" ===
14401440
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ __DEV__ &&
14341434
exports.useTransition = function () {
14351435
return resolveDispatcher().useTransition();
14361436
};
1437-
exports.version = "19.2.0-www-modern-1d7e942d-20250729";
1437+
exports.version = "19.2.0-www-modern-6891dcb8-20250729";
14381438
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14391439
"function" ===
14401440
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,4 +610,4 @@ exports.useSyncExternalStore = function (
610610
exports.useTransition = function () {
611611
return ReactSharedInternals.H.useTransition();
612612
};
613-
exports.version = "19.2.0-www-classic-1d7e942d-20250729";
613+
exports.version = "19.2.0-www-classic-6891dcb8-20250729";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,4 +610,4 @@ exports.useSyncExternalStore = function (
610610
exports.useTransition = function () {
611611
return ReactSharedInternals.H.useTransition();
612612
};
613-
exports.version = "19.2.0-www-modern-1d7e942d-20250729";
613+
exports.version = "19.2.0-www-modern-6891dcb8-20250729";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ exports.useSyncExternalStore = function (
614614
exports.useTransition = function () {
615615
return ReactSharedInternals.H.useTransition();
616616
};
617-
exports.version = "19.2.0-www-classic-1d7e942d-20250729";
617+
exports.version = "19.2.0-www-classic-6891dcb8-20250729";
618618
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
619619
"function" ===
620620
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ exports.useSyncExternalStore = function (
614614
exports.useTransition = function () {
615615
return ReactSharedInternals.H.useTransition();
616616
};
617-
exports.version = "19.2.0-www-modern-1d7e942d-20250729";
617+
exports.version = "19.2.0-www-modern-6891dcb8-20250729";
618618
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
619619
"function" ===
620620
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19318,10 +19318,10 @@ __DEV__ &&
1931819318
(function () {
1931919319
var internals = {
1932019320
bundleType: 1,
19321-
version: "19.2.0-www-classic-1d7e942d-20250729",
19321+
version: "19.2.0-www-classic-6891dcb8-20250729",
1932219322
rendererPackageName: "react-art",
1932319323
currentDispatcherRef: ReactSharedInternals,
19324-
reconcilerVersion: "19.2.0-www-classic-1d7e942d-20250729"
19324+
reconcilerVersion: "19.2.0-www-classic-6891dcb8-20250729"
1932519325
};
1932619326
internals.overrideHookState = overrideHookState;
1932719327
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -19355,7 +19355,7 @@ __DEV__ &&
1935519355
exports.Shape = Shape;
1935619356
exports.Surface = Surface;
1935719357
exports.Text = Text;
19358-
exports.version = "19.2.0-www-classic-1d7e942d-20250729";
19358+
exports.version = "19.2.0-www-classic-6891dcb8-20250729";
1935919359
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1936019360
"function" ===
1936119361
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)