Skip to content

Commit 74d2334

Browse files
committed
[compiler] Allow assigning ref-accessing functions to objects if not mutated (facebook#34026)
Allows assigning a ref-accessing function to an object so long as that object is not subsequently transitively mutated. We should likely rewrite the ref validation to use the new mutation/aliasing effects, which would provide a more consistent behavior across instruction types and require fewer special cases like this. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34026). * facebook#34027 * __->__ facebook#34026 DiffTrain build for [04a7a61](facebook@04a7a61)
1 parent a66fff1 commit 74d2334

35 files changed

+2311
-2235
lines changed

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

Lines changed: 213 additions & 77 deletions
Large diffs are not rendered by default.

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
33a2bf78c47bf3298655908eec123f5fedbebcc7
1+
04a7a61918522734a083bff37843865d7815d466
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
33a2bf78c47bf3298655908eec123f5fedbebcc7
1+
04a7a61918522734a083bff37843865d7815d466

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-33a2bf78-20250729";
1437+
exports.version = "19.2.0-www-classic-04a7a619-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-33a2bf78-20250729";
1437+
exports.version = "19.2.0-www-modern-04a7a619-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-33a2bf78-20250729";
613+
exports.version = "19.2.0-www-classic-04a7a619-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-33a2bf78-20250729";
613+
exports.version = "19.2.0-www-modern-04a7a619-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-33a2bf78-20250729";
617+
exports.version = "19.2.0-www-classic-04a7a619-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-33a2bf78-20250729";
617+
exports.version = "19.2.0-www-modern-04a7a619-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: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3501,6 +3501,19 @@ __DEV__ &&
35013501
throw SuspenseException;
35023502
}
35033503
}
3504+
function resolveLazy(lazyType) {
3505+
try {
3506+
return callLazyInitInDEV(lazyType);
3507+
} catch (x) {
3508+
if (null !== x && "object" === typeof x && "function" === typeof x.then)
3509+
throw (
3510+
((suspendedThenable = x),
3511+
(needsToResetSuspendedThenableDEV = !0),
3512+
SuspenseException)
3513+
);
3514+
throw x;
3515+
}
3516+
}
35043517
function getSuspendedThenable() {
35053518
if (null === suspendedThenable)
35063519
throw Error(
@@ -3716,7 +3729,7 @@ __DEV__ &&
37163729
("object" === typeof elementType &&
37173730
null !== elementType &&
37183731
elementType.$$typeof === REACT_LAZY_TYPE &&
3719-
callLazyInitInDEV(elementType) === current.type))
3732+
resolveLazy(elementType) === current.type))
37203733
)
37213734
return (
37223735
(current = useFiber(current, element.props)),
@@ -3817,7 +3830,7 @@ __DEV__ &&
38173830
);
38183831
case REACT_LAZY_TYPE:
38193832
var _prevDebugInfo = pushDebugInfo(newChild._debugInfo);
3820-
newChild = callLazyInitInDEV(newChild);
3833+
newChild = resolveLazy(newChild);
38213834
returnFiber = createChild(returnFiber, newChild, lanes);
38223835
currentDebugInfo = _prevDebugInfo;
38233836
return returnFiber;
@@ -3893,7 +3906,7 @@ __DEV__ &&
38933906
case REACT_LAZY_TYPE:
38943907
return (
38953908
(key = pushDebugInfo(newChild._debugInfo)),
3896-
(newChild = callLazyInitInDEV(newChild)),
3909+
(newChild = resolveLazy(newChild)),
38973910
(returnFiber = updateSlot(
38983911
returnFiber,
38993912
oldFiber,
@@ -3987,7 +4000,7 @@ __DEV__ &&
39874000
);
39884001
case REACT_LAZY_TYPE:
39894002
var _prevDebugInfo7 = pushDebugInfo(newChild._debugInfo);
3990-
newChild = callLazyInitInDEV(newChild);
4003+
newChild = resolveLazy(newChild);
39914004
returnFiber = updateFromMap(
39924005
existingChildren,
39934006
returnFiber,
@@ -4065,7 +4078,7 @@ __DEV__ &&
40654078
});
40664079
break;
40674080
case REACT_LAZY_TYPE:
4068-
(child = callLazyInitInDEV(child)),
4081+
(child = resolveLazy(child)),
40694082
warnOnInvalidKey(returnFiber, workInProgress, child, knownKeys);
40704083
}
40714084
return knownKeys;
@@ -4336,7 +4349,7 @@ __DEV__ &&
43364349
("object" === typeof key &&
43374350
null !== key &&
43384351
key.$$typeof === REACT_LAZY_TYPE &&
4339-
callLazyInitInDEV(key) === currentFirstChild.type)
4352+
resolveLazy(key) === currentFirstChild.type)
43404353
) {
43414354
deleteRemainingChildren(
43424355
returnFiber,
@@ -4428,7 +4441,7 @@ __DEV__ &&
44284441
case REACT_LAZY_TYPE:
44294442
return (
44304443
(prevDebugInfo = pushDebugInfo(newChild._debugInfo)),
4431-
(newChild = callLazyInitInDEV(newChild)),
4444+
(newChild = resolveLazy(newChild)),
44324445
(returnFiber = reconcileChildFibersImpl(
44334446
returnFiber,
44344447
currentFirstChild,
@@ -9116,7 +9129,7 @@ __DEV__ &&
91169129
case 16:
91179130
a: if (
91189131
((returnFiber = workInProgress.pendingProps),
9119-
(current = callLazyInitInDEV(workInProgress.elementType)),
9132+
(current = resolveLazy(workInProgress.elementType)),
91209133
(workInProgress.type = current),
91219134
"function" === typeof current)
91229135
)
@@ -17631,25 +17644,7 @@ __DEV__ &&
1763117644
pendingUNSAFE_ComponentWillUpdateWarnings = [];
1763217645
pendingLegacyContextWarning = new Map();
1763317646
};
17634-
var SuspenseException = Error(
17635-
"Suspense Exception: This is not a real error! It's an implementation detail of `use` to interrupt the current render. You must either rethrow it immediately, or move the `use` call outside of the `try/catch` block. Capturing without rethrowing will lead to unexpected behavior.\n\nTo handle async errors, wrap your component in an error boundary, or call the promise's `.catch` method and pass the result to `use`."
17636-
),
17637-
SuspenseyCommitException = Error(
17638-
"Suspense Exception: This is not a real error, and should not leak into userspace. If you're seeing this, it's likely a bug in React."
17639-
),
17640-
SuspenseActionException = Error(
17641-
"Suspense Exception: This is not a real error! It's an implementation detail of `useActionState` to interrupt the current render. You must either rethrow it immediately, or move the `useActionState` call outside of the `try/catch` block. Capturing without rethrowing will lead to unexpected behavior.\n\nTo handle async errors, wrap your component in an error boundary."
17642-
),
17643-
noopSuspenseyCommitThenable = {
17644-
then: function () {
17645-
console.error(
17646-
'Internal React error: A listener was unexpectedly attached to a "noop" thenable. This is a bug in React. Please file an issue.'
17647-
);
17648-
}
17649-
},
17650-
suspendedThenable = null,
17651-
needsToResetSuspendedThenableDEV = !1,
17652-
callComponent = {
17647+
var callComponent = {
1765317648
react_stack_bottom_frame: function (Component, props, secondArg) {
1765417649
var wasRendering = isRendering;
1765517650
isRendering = !0;
@@ -17766,6 +17761,24 @@ __DEV__ &&
1776617761
},
1776717762
callLazyInitInDEV =
1776817763
callLazyInit.react_stack_bottom_frame.bind(callLazyInit),
17764+
SuspenseException = Error(
17765+
"Suspense Exception: This is not a real error! It's an implementation detail of `use` to interrupt the current render. You must either rethrow it immediately, or move the `use` call outside of the `try/catch` block. Capturing without rethrowing will lead to unexpected behavior.\n\nTo handle async errors, wrap your component in an error boundary, or call the promise's `.catch` method and pass the result to `use`."
17766+
),
17767+
SuspenseyCommitException = Error(
17768+
"Suspense Exception: This is not a real error, and should not leak into userspace. If you're seeing this, it's likely a bug in React."
17769+
),
17770+
SuspenseActionException = Error(
17771+
"Suspense Exception: This is not a real error! It's an implementation detail of `useActionState` to interrupt the current render. You must either rethrow it immediately, or move the `useActionState` call outside of the `try/catch` block. Capturing without rethrowing will lead to unexpected behavior.\n\nTo handle async errors, wrap your component in an error boundary."
17772+
),
17773+
noopSuspenseyCommitThenable = {
17774+
then: function () {
17775+
console.error(
17776+
'Internal React error: A listener was unexpectedly attached to a "noop" thenable. This is a bug in React. Please file an issue.'
17777+
);
17778+
}
17779+
},
17780+
suspendedThenable = null,
17781+
needsToResetSuspendedThenableDEV = !1,
1776917782
thenableState$1 = null,
1777017783
thenableIndexCounter$1 = 0,
1777117784
currentDebugInfo = null,
@@ -19305,10 +19318,10 @@ __DEV__ &&
1930519318
(function () {
1930619319
var internals = {
1930719320
bundleType: 1,
19308-
version: "19.2.0-www-classic-33a2bf78-20250729",
19321+
version: "19.2.0-www-classic-04a7a619-20250729",
1930919322
rendererPackageName: "react-art",
1931019323
currentDispatcherRef: ReactSharedInternals,
19311-
reconcilerVersion: "19.2.0-www-classic-33a2bf78-20250729"
19324+
reconcilerVersion: "19.2.0-www-classic-04a7a619-20250729"
1931219325
};
1931319326
internals.overrideHookState = overrideHookState;
1931419327
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -19342,7 +19355,7 @@ __DEV__ &&
1934219355
exports.Shape = Shape;
1934319356
exports.Surface = Surface;
1934419357
exports.Text = Text;
19345-
exports.version = "19.2.0-www-classic-33a2bf78-20250729";
19358+
exports.version = "19.2.0-www-classic-04a7a619-20250729";
1934619359
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1934719360
"function" ===
1934819361
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)