Skip to content

Commit a7a6a73

Browse files
committed
Fix mount-or-update check in rerenderOptimistic (#27277)
I noticed this was wrong because it should call updateWorkInProgressHook before it checks if currentHook is null. DiffTrain build for [9a01c8b](9a01c8b)
1 parent b1f8e0d commit a7a6a73

18 files changed

+156
-94
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ab31a9ed28d340172440e4b12e27d2af689249b3
1+
9a01c8b54e91c588391070c65701342e4e361ea7

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-classic-b5d591d4";
30+
var ReactVersion = "18.3.0-www-classic-5ee47d9f";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-modern-ad388db9";
30+
var ReactVersion = "18.3.0-www-modern-85b0d0c8";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
6969
return self;
7070
}
7171

72-
var ReactVersion = "18.3.0-www-classic-217d7ffa";
72+
var ReactVersion = "18.3.0-www-classic-a63d3ca6";
7373

7474
var LegacyRoot = 0;
7575
var ConcurrentRoot = 1;
@@ -9287,13 +9287,17 @@ function mountOptimistic(passthrough, reducer) {
92879287
}
92889288

92899289
function updateOptimistic(passthrough, reducer) {
9290-
var hook = updateWorkInProgressHook(); // Optimistic updates are always rebased on top of the latest value passed in
9290+
var hook = updateWorkInProgressHook();
9291+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
9292+
}
9293+
9294+
function updateOptimisticImpl(hook, current, passthrough, reducer) {
9295+
// Optimistic updates are always rebased on top of the latest value passed in
92919296
// as an argument. It's called a passthrough because if there are no pending
92929297
// updates, it will be returned as-is.
92939298
//
92949299
// Reset the base state and memoized state to the passthrough. Future
92959300
// updates will be applied on top of this.
9296-
92979301
hook.baseState = hook.memoizedState = passthrough; // If a reducer is not provided, default to the same one used by useState.
92989302

92999303
var resolvedReducer =
@@ -9309,12 +9313,13 @@ function rerenderOptimistic(passthrough, reducer) {
93099313
// So instead of a forked re-render implementation that knows how to handle
93109314
// render phase udpates, we can use the same implementation as during a
93119315
// regular mount or update.
9316+
var hook = updateWorkInProgressHook();
9317+
93129318
if (currentHook !== null) {
93139319
// This is an update. Process the update queue.
9314-
return updateOptimistic(passthrough, reducer);
9320+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
93159321
} // This is a mount. No updates to process.
9316-
9317-
var hook = updateWorkInProgressHook(); // Reset the base state and memoized state to the passthrough. Future
9322+
// Reset the base state and memoized state to the passthrough. Future
93189323
// updates will be applied on top of this.
93199324

93209325
hook.baseState = hook.memoizedState = passthrough;

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
6969
return self;
7070
}
7171

72-
var ReactVersion = "18.3.0-www-modern-a127d0ff";
72+
var ReactVersion = "18.3.0-www-modern-cf21fab9";
7373

7474
var LegacyRoot = 0;
7575
var ConcurrentRoot = 1;
@@ -9043,13 +9043,17 @@ function mountOptimistic(passthrough, reducer) {
90439043
}
90449044

90459045
function updateOptimistic(passthrough, reducer) {
9046-
var hook = updateWorkInProgressHook(); // Optimistic updates are always rebased on top of the latest value passed in
9046+
var hook = updateWorkInProgressHook();
9047+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
9048+
}
9049+
9050+
function updateOptimisticImpl(hook, current, passthrough, reducer) {
9051+
// Optimistic updates are always rebased on top of the latest value passed in
90479052
// as an argument. It's called a passthrough because if there are no pending
90489053
// updates, it will be returned as-is.
90499054
//
90509055
// Reset the base state and memoized state to the passthrough. Future
90519056
// updates will be applied on top of this.
9052-
90539057
hook.baseState = hook.memoizedState = passthrough; // If a reducer is not provided, default to the same one used by useState.
90549058

90559059
var resolvedReducer =
@@ -9065,12 +9069,13 @@ function rerenderOptimistic(passthrough, reducer) {
90659069
// So instead of a forked re-render implementation that knows how to handle
90669070
// render phase udpates, we can use the same implementation as during a
90679071
// regular mount or update.
9072+
var hook = updateWorkInProgressHook();
9073+
90689074
if (currentHook !== null) {
90699075
// This is an update. Process the update queue.
9070-
return updateOptimistic(passthrough, reducer);
9076+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
90719077
} // This is a mount. No updates to process.
9072-
9073-
var hook = updateWorkInProgressHook(); // Reset the base state and memoized state to the passthrough. Future
9078+
// Reset the base state and memoized state to the passthrough. Future
90749079
// updates will be applied on top of this.
90759080

90769081
hook.baseState = hook.memoizedState = passthrough;

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,6 +2995,9 @@ function mountOptimistic(passthrough) {
29952995
}
29962996
function updateOptimistic(passthrough, reducer) {
29972997
var hook = updateWorkInProgressHook();
2998+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
2999+
}
3000+
function updateOptimisticImpl(hook, current, passthrough, reducer) {
29983001
hook.baseState = hook.memoizedState = passthrough;
29993002
return updateReducerImpl(
30003003
hook,
@@ -3003,10 +3006,11 @@ function updateOptimistic(passthrough, reducer) {
30033006
);
30043007
}
30053008
function rerenderOptimistic(passthrough, reducer) {
3006-
if (null !== currentHook) return updateOptimistic(passthrough, reducer);
3007-
reducer = updateWorkInProgressHook();
3008-
reducer.baseState = reducer.memoizedState = passthrough;
3009-
return [passthrough, reducer.queue.dispatch];
3009+
var hook = updateWorkInProgressHook();
3010+
if (null !== currentHook)
3011+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
3012+
hook.baseState = hook.memoizedState = passthrough;
3013+
return [passthrough, hook.queue.dispatch];
30103014
}
30113015
function pushEffect(tag, create, inst, deps) {
30123016
tag = { tag: tag, create: create, inst: inst, deps: deps, next: null };
@@ -10091,7 +10095,7 @@ var slice = Array.prototype.slice,
1009110095
return null;
1009210096
},
1009310097
bundleType: 0,
10094-
version: "18.3.0-www-classic-b5d591d4",
10098+
version: "18.3.0-www-classic-5ee47d9f",
1009510099
rendererPackageName: "react-art"
1009610100
};
1009710101
var internals$jscomp$inline_1303 = {
@@ -10122,7 +10126,7 @@ var internals$jscomp$inline_1303 = {
1012210126
scheduleRoot: null,
1012310127
setRefreshHandler: null,
1012410128
getCurrentFiber: null,
10125-
reconcilerVersion: "18.3.0-www-classic-b5d591d4"
10129+
reconcilerVersion: "18.3.0-www-classic-5ee47d9f"
1012610130
};
1012710131
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1012810132
var hook$jscomp$inline_1304 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,6 +2801,9 @@ function mountOptimistic(passthrough) {
28012801
}
28022802
function updateOptimistic(passthrough, reducer) {
28032803
var hook = updateWorkInProgressHook();
2804+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
2805+
}
2806+
function updateOptimisticImpl(hook, current, passthrough, reducer) {
28042807
hook.baseState = hook.memoizedState = passthrough;
28052808
return updateReducerImpl(
28062809
hook,
@@ -2809,10 +2812,11 @@ function updateOptimistic(passthrough, reducer) {
28092812
);
28102813
}
28112814
function rerenderOptimistic(passthrough, reducer) {
2812-
if (null !== currentHook) return updateOptimistic(passthrough, reducer);
2813-
reducer = updateWorkInProgressHook();
2814-
reducer.baseState = reducer.memoizedState = passthrough;
2815-
return [passthrough, reducer.queue.dispatch];
2815+
var hook = updateWorkInProgressHook();
2816+
if (null !== currentHook)
2817+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
2818+
hook.baseState = hook.memoizedState = passthrough;
2819+
return [passthrough, hook.queue.dispatch];
28162820
}
28172821
function pushEffect(tag, create, inst, deps) {
28182822
tag = { tag: tag, create: create, inst: inst, deps: deps, next: null };
@@ -9756,7 +9760,7 @@ var slice = Array.prototype.slice,
97569760
return null;
97579761
},
97589762
bundleType: 0,
9759-
version: "18.3.0-www-modern-de287969",
9763+
version: "18.3.0-www-modern-91e39875",
97609764
rendererPackageName: "react-art"
97619765
};
97629766
var internals$jscomp$inline_1283 = {
@@ -9787,7 +9791,7 @@ var internals$jscomp$inline_1283 = {
97879791
scheduleRoot: null,
97889792
setRefreshHandler: null,
97899793
getCurrentFiber: null,
9790-
reconcilerVersion: "18.3.0-www-modern-de287969"
9794+
reconcilerVersion: "18.3.0-www-modern-91e39875"
97919795
};
97929796
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
97939797
var hook$jscomp$inline_1284 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13827,13 +13827,17 @@ function mountOptimistic(passthrough, reducer) {
1382713827
}
1382813828

1382913829
function updateOptimistic(passthrough, reducer) {
13830-
var hook = updateWorkInProgressHook(); // Optimistic updates are always rebased on top of the latest value passed in
13830+
var hook = updateWorkInProgressHook();
13831+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
13832+
}
13833+
13834+
function updateOptimisticImpl(hook, current, passthrough, reducer) {
13835+
// Optimistic updates are always rebased on top of the latest value passed in
1383113836
// as an argument. It's called a passthrough because if there are no pending
1383213837
// updates, it will be returned as-is.
1383313838
//
1383413839
// Reset the base state and memoized state to the passthrough. Future
1383513840
// updates will be applied on top of this.
13836-
1383713841
hook.baseState = hook.memoizedState = passthrough; // If a reducer is not provided, default to the same one used by useState.
1383813842

1383913843
var resolvedReducer =
@@ -13849,12 +13853,13 @@ function rerenderOptimistic(passthrough, reducer) {
1384913853
// So instead of a forked re-render implementation that knows how to handle
1385013854
// render phase udpates, we can use the same implementation as during a
1385113855
// regular mount or update.
13856+
var hook = updateWorkInProgressHook();
13857+
1385213858
if (currentHook !== null) {
1385313859
// This is an update. Process the update queue.
13854-
return updateOptimistic(passthrough, reducer);
13860+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
1385513861
} // This is a mount. No updates to process.
13856-
13857-
var hook = updateWorkInProgressHook(); // Reset the base state and memoized state to the passthrough. Future
13862+
// Reset the base state and memoized state to the passthrough. Future
1385813863
// updates will be applied on top of this.
1385913864

1386013865
hook.baseState = hook.memoizedState = passthrough;
@@ -33964,7 +33969,7 @@ function createFiberRoot(
3396433969
return root;
3396533970
}
3396633971

33967-
var ReactVersion = "18.3.0-www-classic-18629a7a";
33972+
var ReactVersion = "18.3.0-www-classic-76b0eed2";
3396833973

3396933974
function createPortal$1(
3397033975
children,

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13768,13 +13768,17 @@ function mountOptimistic(passthrough, reducer) {
1376813768
}
1376913769

1377013770
function updateOptimistic(passthrough, reducer) {
13771-
var hook = updateWorkInProgressHook(); // Optimistic updates are always rebased on top of the latest value passed in
13771+
var hook = updateWorkInProgressHook();
13772+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
13773+
}
13774+
13775+
function updateOptimisticImpl(hook, current, passthrough, reducer) {
13776+
// Optimistic updates are always rebased on top of the latest value passed in
1377213777
// as an argument. It's called a passthrough because if there are no pending
1377313778
// updates, it will be returned as-is.
1377413779
//
1377513780
// Reset the base state and memoized state to the passthrough. Future
1377613781
// updates will be applied on top of this.
13777-
1377813782
hook.baseState = hook.memoizedState = passthrough; // If a reducer is not provided, default to the same one used by useState.
1377913783

1378013784
var resolvedReducer =
@@ -13790,12 +13794,13 @@ function rerenderOptimistic(passthrough, reducer) {
1379013794
// So instead of a forked re-render implementation that knows how to handle
1379113795
// render phase udpates, we can use the same implementation as during a
1379213796
// regular mount or update.
13797+
var hook = updateWorkInProgressHook();
13798+
1379313799
if (currentHook !== null) {
1379413800
// This is an update. Process the update queue.
13795-
return updateOptimistic(passthrough, reducer);
13801+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
1379613802
} // This is a mount. No updates to process.
13797-
13798-
var hook = updateWorkInProgressHook(); // Reset the base state and memoized state to the passthrough. Future
13803+
// Reset the base state and memoized state to the passthrough. Future
1379913804
// updates will be applied on top of this.
1380013805

1380113806
hook.baseState = hook.memoizedState = passthrough;
@@ -33809,7 +33814,7 @@ function createFiberRoot(
3380933814
return root;
3381033815
}
3381133816

33812-
var ReactVersion = "18.3.0-www-modern-a127d0ff";
33817+
var ReactVersion = "18.3.0-www-modern-cf21fab9";
3381333818

3381433819
function createPortal$1(
3381533820
children,

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3808,6 +3808,9 @@ function mountOptimistic(passthrough) {
38083808
}
38093809
function updateOptimistic(passthrough, reducer) {
38103810
var hook = updateWorkInProgressHook();
3811+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
3812+
}
3813+
function updateOptimisticImpl(hook, current, passthrough, reducer) {
38113814
hook.baseState = hook.memoizedState = passthrough;
38123815
return updateReducerImpl(
38133816
hook,
@@ -3816,10 +3819,11 @@ function updateOptimistic(passthrough, reducer) {
38163819
);
38173820
}
38183821
function rerenderOptimistic(passthrough, reducer) {
3819-
if (null !== currentHook) return updateOptimistic(passthrough, reducer);
3820-
reducer = updateWorkInProgressHook();
3821-
reducer.baseState = reducer.memoizedState = passthrough;
3822-
return [passthrough, reducer.queue.dispatch];
3822+
var hook = updateWorkInProgressHook();
3823+
if (null !== currentHook)
3824+
return updateOptimisticImpl(hook, currentHook, passthrough, reducer);
3825+
hook.baseState = hook.memoizedState = passthrough;
3826+
return [passthrough, hook.queue.dispatch];
38233827
}
38243828
function pushEffect(tag, create, inst, deps) {
38253829
tag = { tag: tag, create: create, inst: inst, deps: deps, next: null };
@@ -16669,7 +16673,7 @@ Internals.Events = [
1666916673
var devToolsConfig$jscomp$inline_1783 = {
1667016674
findFiberByHostInstance: getClosestInstanceFromNode,
1667116675
bundleType: 0,
16672-
version: "18.3.0-www-classic-c01203f3",
16676+
version: "18.3.0-www-classic-d2e8c11b",
1667316677
rendererPackageName: "react-dom"
1667416678
};
1667516679
var internals$jscomp$inline_2140 = {
@@ -16699,7 +16703,7 @@ var internals$jscomp$inline_2140 = {
1669916703
scheduleRoot: null,
1670016704
setRefreshHandler: null,
1670116705
getCurrentFiber: null,
16702-
reconcilerVersion: "18.3.0-www-classic-c01203f3"
16706+
reconcilerVersion: "18.3.0-www-classic-d2e8c11b"
1670316707
};
1670416708
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1670516709
var hook$jscomp$inline_2141 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -16938,4 +16942,4 @@ exports.unstable_renderSubtreeIntoContainer = function (
1693816942
);
1693916943
};
1694016944
exports.unstable_runWithPriority = runWithPriority;
16941-
exports.version = "18.3.0-www-classic-c01203f3";
16945+
exports.version = "18.3.0-www-classic-d2e8c11b";

0 commit comments

Comments
 (0)