Skip to content

Commit 4005e32

Browse files
committed
[crud] Fix deps comparison bug (#31599)
Fixes a bug with the experimental `useResourceEffect` hook where we would compare the wrong deps when there happened to be another kind of effect preceding the ResourceEffect. To do this correctly we need to add a pointer to the ResourceEffect's identity on the update. I also unified the previously separate push effect impls for resource effects since they are always pushed together as a unit. DiffTrain build for [c11c951](c11c951)
1 parent 63038b4 commit 4005e32

35 files changed

+2058
-1861
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7558ffe84df6bab5d701fd90de1c6313f9a1c066
1+
c11c9510fa14bbd87053685c19bfdfec2f427f49
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7558ffe84df6bab5d701fd90de1c6313f9a1c066
1+
c11c9510fa14bbd87053685c19bfdfec2f427f49

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ __DEV__ &&
18371837
exports.useTransition = function () {
18381838
return resolveDispatcher().useTransition();
18391839
};
1840-
exports.version = "19.0.0-www-classic-7558ffe8-20241119";
1840+
exports.version = "19.0.0-www-classic-c11c9510-20241120";
18411841
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
18421842
"function" ===
18431843
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
@@ -1837,7 +1837,7 @@ __DEV__ &&
18371837
exports.useTransition = function () {
18381838
return resolveDispatcher().useTransition();
18391839
};
1840-
exports.version = "19.0.0-www-modern-7558ffe8-20241119";
1840+
exports.version = "19.0.0-www-modern-c11c9510-20241120";
18411841
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
18421842
"function" ===
18431843
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
@@ -636,4 +636,4 @@ exports.useSyncExternalStore = function (
636636
exports.useTransition = function () {
637637
return ReactSharedInternals.H.useTransition();
638638
};
639-
exports.version = "19.0.0-www-classic-7558ffe8-20241119";
639+
exports.version = "19.0.0-www-classic-c11c9510-20241120";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,4 +636,4 @@ exports.useSyncExternalStore = function (
636636
exports.useTransition = function () {
637637
return ReactSharedInternals.H.useTransition();
638638
};
639-
exports.version = "19.0.0-www-modern-7558ffe8-20241119";
639+
exports.version = "19.0.0-www-modern-c11c9510-20241120";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ exports.useSyncExternalStore = function (
640640
exports.useTransition = function () {
641641
return ReactSharedInternals.H.useTransition();
642642
};
643-
exports.version = "19.0.0-www-classic-7558ffe8-20241119";
643+
exports.version = "19.0.0-www-classic-c11c9510-20241120";
644644
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
645645
"function" ===
646646
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
@@ -640,7 +640,7 @@ exports.useSyncExternalStore = function (
640640
exports.useTransition = function () {
641641
return ReactSharedInternals.H.useTransition();
642642
};
643-
exports.version = "19.0.0-www-modern-7558ffe8-20241119";
643+
exports.version = "19.0.0-www-modern-c11c9510-20241120";
644644
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
645645
"function" ===
646646
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 90 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,6 +3855,34 @@ __DEV__ &&
38553855
next: null
38563856
});
38573857
}
3858+
function pushResourceEffect(
3859+
identityTag,
3860+
updateTag,
3861+
inst,
3862+
create,
3863+
createDeps,
3864+
update,
3865+
updateDeps
3866+
) {
3867+
identityTag = {
3868+
resourceKind: ResourceEffectIdentityKind,
3869+
tag: identityTag,
3870+
create: create,
3871+
deps: createDeps,
3872+
inst: inst,
3873+
next: null
3874+
};
3875+
pushEffectImpl(identityTag);
3876+
return pushEffectImpl({
3877+
resourceKind: ResourceEffectUpdateKind,
3878+
tag: updateTag,
3879+
update: update,
3880+
deps: updateDeps,
3881+
inst: inst,
3882+
identity: identityTag,
3883+
next: null
3884+
});
3885+
}
38583886
function pushEffectImpl(effect) {
38593887
var componentUpdateQueue = currentlyRenderingFiber$1.updateQueue;
38603888
null === componentUpdateQueue &&
@@ -3919,56 +3947,39 @@ __DEV__ &&
39193947
updateDeps,
39203948
destroy
39213949
) {
3922-
0 !== (currentlyRenderingFiber$1.mode & 16) &&
3923-
0 === (currentlyRenderingFiber$1.mode & 64)
3924-
? mountResourceEffectImpl(
3925-
142608384,
3926-
Passive,
3927-
create,
3928-
createDeps,
3929-
update,
3930-
updateDeps,
3931-
destroy
3932-
)
3933-
: mountResourceEffectImpl(
3934-
8390656,
3935-
Passive,
3950+
if (
3951+
0 !== (currentlyRenderingFiber$1.mode & 16) &&
3952+
0 === (currentlyRenderingFiber$1.mode & 64)
3953+
) {
3954+
var hookFlags = Passive,
3955+
hook = mountWorkInProgressHook();
3956+
currentlyRenderingFiber$1.flags |= 142608384;
3957+
var inst = createEffectInstance();
3958+
inst.destroy = destroy;
3959+
hook.memoizedState = pushResourceEffect(
3960+
HasEffect | hookFlags,
3961+
hookFlags,
3962+
inst,
3963+
create,
3964+
createDeps,
3965+
update,
3966+
updateDeps
3967+
);
3968+
} else
3969+
(hookFlags = Passive),
3970+
(hook = mountWorkInProgressHook()),
3971+
(currentlyRenderingFiber$1.flags |= 8390656),
3972+
(inst = createEffectInstance()),
3973+
(inst.destroy = destroy),
3974+
(hook.memoizedState = pushResourceEffect(
3975+
HasEffect | hookFlags,
3976+
hookFlags,
3977+
inst,
39363978
create,
39373979
createDeps,
39383980
update,
3939-
updateDeps,
3940-
destroy
3941-
);
3942-
}
3943-
function mountResourceEffectImpl(
3944-
fiberFlags,
3945-
hookFlags,
3946-
create,
3947-
createDeps,
3948-
update,
3949-
updateDeps,
3950-
destroy
3951-
) {
3952-
var hook = mountWorkInProgressHook();
3953-
currentlyRenderingFiber$1.flags |= fiberFlags;
3954-
fiberFlags = createEffectInstance();
3955-
fiberFlags.destroy = destroy;
3956-
hook.memoizedState = pushEffectImpl({
3957-
resourceKind: ResourceEffectIdentityKind,
3958-
tag: HasEffect | hookFlags,
3959-
create: create,
3960-
deps: createDeps,
3961-
inst: fiberFlags,
3962-
next: null
3963-
});
3964-
hook.memoizedState = pushEffectImpl({
3965-
resourceKind: ResourceEffectUpdateKind,
3966-
tag: hookFlags,
3967-
update: update,
3968-
deps: updateDeps,
3969-
inst: fiberFlags,
3970-
next: null
3971-
});
3981+
updateDeps
3982+
));
39723983
}
39733984
function updateResourceEffectImpl(
39743985
fiberFlags,
@@ -3984,45 +3995,45 @@ __DEV__ &&
39843995
inst.destroy = destroy;
39853996
createDeps = void 0 === createDeps ? null : createDeps;
39863997
updateDeps = void 0 === updateDeps ? null : updateDeps;
3987-
var isUpdateDepsSame;
39883998
if (null !== currentHook) {
39893999
destroy = currentHook.memoizedState;
39904000
if (null !== createDeps) {
3991-
if (destroy.resourceKind === ResourceEffectUpdateKind)
4001+
if (
4002+
null != destroy.resourceKind &&
4003+
destroy.resourceKind === ResourceEffectUpdateKind
4004+
)
39924005
var isCreateDepsSame =
3993-
null != destroy.next.deps ? destroy.next.deps : null;
4006+
null != destroy.identity.deps ? destroy.identity.deps : null;
39944007
else
3995-
error$jscomp$0(
3996-
"Expected a ResourceEffectUpdateKind to be pushed together with ResourceEffectIdentityKind, got %s. This is a bug in React.",
3997-
destroy.resourceKind
3998-
),
3999-
(isCreateDepsSame = null != destroy.deps ? destroy.deps : null);
4008+
throw Error(
4009+
"Expected a ResourceEffectUpdate to be pushed together with ResourceEffectIdentity. This is a bug in React."
4010+
);
40004011
isCreateDepsSame = areHookInputsEqual(createDeps, isCreateDepsSame);
40014012
}
4002-
null !== updateDeps &&
4003-
(isUpdateDepsSame = areHookInputsEqual(
4004-
updateDeps,
4005-
null != destroy.deps ? destroy.deps : null
4006-
));
4013+
if (null !== updateDeps) {
4014+
if (
4015+
null != destroy.resourceKind &&
4016+
destroy.resourceKind === ResourceEffectUpdateKind
4017+
)
4018+
var isUpdateDepsSame = null != destroy.deps ? destroy.deps : null;
4019+
else
4020+
throw Error(
4021+
"Expected a ResourceEffectUpdate to be pushed together with ResourceEffectIdentity. This is a bug in React."
4022+
);
4023+
isUpdateDepsSame = areHookInputsEqual(updateDeps, isUpdateDepsSame);
4024+
}
40074025
}
40084026
(isCreateDepsSame && isUpdateDepsSame) ||
40094027
(currentlyRenderingFiber$1.flags |= fiberFlags);
4010-
hook.memoizedState = pushEffectImpl({
4011-
resourceKind: ResourceEffectIdentityKind,
4012-
tag: isCreateDepsSame ? hookFlags : HasEffect | hookFlags,
4013-
create: create,
4014-
deps: createDeps,
4015-
inst: inst,
4016-
next: null
4017-
});
4018-
hook.memoizedState = pushEffectImpl({
4019-
resourceKind: ResourceEffectUpdateKind,
4020-
tag: isUpdateDepsSame ? hookFlags : HasEffect | hookFlags,
4021-
update: update,
4022-
deps: updateDeps,
4023-
inst: inst,
4024-
next: null
4025-
});
4028+
hook.memoizedState = pushResourceEffect(
4029+
isCreateDepsSame ? hookFlags : HasEffect | hookFlags,
4030+
isUpdateDepsSame ? hookFlags : HasEffect | hookFlags,
4031+
inst,
4032+
create,
4033+
createDeps,
4034+
update,
4035+
updateDeps
4036+
);
40264037
}
40274038
function useEffectEventImpl(payload) {
40284039
currentlyRenderingFiber$1.flags |= 4;
@@ -17114,11 +17125,11 @@ __DEV__ &&
1711417125
(function () {
1711517126
var internals = {
1711617127
bundleType: 1,
17117-
version: "19.0.0-www-classic-7558ffe8-20241119",
17128+
version: "19.0.0-www-classic-c11c9510-20241120",
1711817129
rendererPackageName: "react-art",
1711917130
currentDispatcherRef: ReactSharedInternals,
1712017131
findFiberByHostInstance: getInstanceFromNode,
17121-
reconcilerVersion: "19.0.0-www-classic-7558ffe8-20241119"
17132+
reconcilerVersion: "19.0.0-www-classic-c11c9510-20241120"
1712217133
};
1712317134
internals.overrideHookState = overrideHookState;
1712417135
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -17152,7 +17163,7 @@ __DEV__ &&
1715217163
exports.Shape = Shape;
1715317164
exports.Surface = Surface;
1715417165
exports.Text = Text;
17155-
exports.version = "19.0.0-www-classic-7558ffe8-20241119";
17166+
exports.version = "19.0.0-www-classic-c11c9510-20241120";
1715617167
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1715717168
"function" ===
1715817169
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)