Skip to content

Commit 16f8eb9

Browse files
committed
[eslint] Disallow use within try/catch blocks (#34040)
Follow up to #34032. The linter now ensures that `use` cannot be used within try/catch. DiffTrain build for [820af20](820af20)
1 parent 0c4e650 commit 16f8eb9

35 files changed

+101
-86
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55795,6 +55795,15 @@ function isInsideDoWhileLoop(node) {
5579555795
}
5579655796
return false;
5579755797
}
55798+
function isInsideTryCatch(node) {
55799+
while (node) {
55800+
if (node.type === 'TryStatement' || node.type === 'CatchClause') {
55801+
return true;
55802+
}
55803+
node = node.parent;
55804+
}
55805+
return false;
55806+
}
5579855807
function isUseEffectEventIdentifier(node) {
5579955808
{
5580055809
return node.type === 'Identifier' && node.name === 'useEffectEvent';
@@ -55998,6 +56007,12 @@ const rule = {
5599856007
if (hasFlowSuppression(hook, 'react-rule-hook')) {
5599956008
continue;
5600056009
}
56010+
if (isUseIdentifier(hook) && isInsideTryCatch(hook)) {
56011+
context.report({
56012+
node: hook,
56013+
message: `React Hook "${getSourceCode().getText(hook)}" cannot be called in a try/catch block.`,
56014+
});
56015+
}
5600156016
if ((cycled || isInsideDoWhileLoop(hook)) &&
5600256017
!isUseIdentifier(hook)) {
5600356018
context.report({

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9be531cd37f5558c72f7de360eb921b0074e8544
1+
820af2097103309fdc5675d2bde744103a439eff
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9be531cd37f5558c72f7de360eb921b0074e8544
1+
820af2097103309fdc5675d2bde744103a439eff

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-9be531cd-20250729";
1437+
exports.version = "19.2.0-www-classic-820af209-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-9be531cd-20250729";
1437+
exports.version = "19.2.0-www-modern-820af209-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-9be531cd-20250729";
613+
exports.version = "19.2.0-www-classic-820af209-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-9be531cd-20250729";
613+
exports.version = "19.2.0-www-modern-820af209-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-9be531cd-20250729";
617+
exports.version = "19.2.0-www-classic-820af209-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-9be531cd-20250729";
617+
exports.version = "19.2.0-www-modern-820af209-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-9be531cd-20250729",
19321+
version: "19.2.0-www-classic-820af209-20250729",
1932219322
rendererPackageName: "react-art",
1932319323
currentDispatcherRef: ReactSharedInternals,
19324-
reconcilerVersion: "19.2.0-www-classic-9be531cd-20250729"
19324+
reconcilerVersion: "19.2.0-www-classic-820af209-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-9be531cd-20250729";
19358+
exports.version = "19.2.0-www-classic-820af209-20250729";
1935919359
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1936019360
"function" ===
1936119361
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)