Skip to content

Commit af29a26

Browse files
committed
[eslint] Do not allow useEffectEvent fns to be called in arbitrary closures (#33544)
Summary: useEffectEvent is meant to be used specifically in combination with useEffect, and using the feature in arbitrary closures can lead to surprising reactivity semantics. In order to minimize risk in the experimental rollout, we are going to restrict its usage to being called directly inside an effect or another useEffectEvent, effectively enforcing the function coloring statically. Without an effect system this is the best we can do. DiffTrain build for [97cdd5d](97cdd5d)
1 parent 4ab994b commit af29a26

35 files changed

+93
-91
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55210,13 +55210,15 @@ const rule = {
5521055210
}
5521155211
},
5521255212
Identifier(node) {
55213-
if (lastEffect == null &&
55214-
useEffectEventFunctions.has(node) &&
55215-
node.parent.type !== 'CallExpression') {
55213+
if (lastEffect == null && useEffectEventFunctions.has(node)) {
55214+
const message = `\`${getSourceCode().getText(node)}\` is a function created with React Hook "useEffectEvent", and can only be called from ` +
55215+
'the same component.' +
55216+
(node.parent.type === 'CallExpression'
55217+
? ''
55218+
: ' They cannot be assigned to variables or passed down.');
5521655219
context.report({
5521755220
node,
55218-
message: `\`${getSourceCode().getText(node)}\` is a function created with React Hook "useEffectEvent", and can only be called from ` +
55219-
'the same component. They cannot be assigned to variables or passed down.',
55221+
message,
5522055222
});
5522155223
}
5522255224
},

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
96c61b7f1f145b9fe5103051b636959cdeb20cc8
1+
97cdd5d3c33eda77be4f96a43f72d6916d3badbb
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
96c61b7f1f145b9fe5103051b636959cdeb20cc8
1+
97cdd5d3c33eda77be4f96a43f72d6916d3badbb

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-96c61b7f-20250709";
1437+
exports.version = "19.2.0-www-classic-97cdd5d3-20250710";
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-96c61b7f-20250709";
1437+
exports.version = "19.2.0-www-modern-97cdd5d3-20250710";
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-96c61b7f-20250709";
613+
exports.version = "19.2.0-www-classic-97cdd5d3-20250710";

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-96c61b7f-20250709";
613+
exports.version = "19.2.0-www-modern-97cdd5d3-20250710";

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-96c61b7f-20250709";
617+
exports.version = "19.2.0-www-classic-97cdd5d3-20250710";
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-96c61b7f-20250709";
617+
exports.version = "19.2.0-www-modern-97cdd5d3-20250710";
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
@@ -19299,10 +19299,10 @@ __DEV__ &&
1929919299
(function () {
1930019300
var internals = {
1930119301
bundleType: 1,
19302-
version: "19.2.0-www-classic-96c61b7f-20250709",
19302+
version: "19.2.0-www-classic-97cdd5d3-20250710",
1930319303
rendererPackageName: "react-art",
1930419304
currentDispatcherRef: ReactSharedInternals,
19305-
reconcilerVersion: "19.2.0-www-classic-96c61b7f-20250709"
19305+
reconcilerVersion: "19.2.0-www-classic-97cdd5d3-20250710"
1930619306
};
1930719307
internals.overrideHookState = overrideHookState;
1930819308
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -19336,7 +19336,7 @@ __DEV__ &&
1933619336
exports.Shape = Shape;
1933719337
exports.Surface = Surface;
1933819338
exports.Text = Text;
19339-
exports.version = "19.2.0-www-classic-96c61b7f-20250709";
19339+
exports.version = "19.2.0-www-classic-97cdd5d3-20250710";
1934019340
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1934119341
"function" ===
1934219342
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)