Skip to content

Commit f10aaf1

Browse files
committed
Fix: useOptimistic should return passthrough value when there are no updates pending (#27936)
This fixes a bug that happened when the canonical value passed to useOptimistic without an accompanying call to setOptimistic. In this scenario, useOptimistic should pass through the new canonical value. I had written tests for the more complicated scenario, where a new value is passed while there are still pending optimistic updates, but not this simpler one. DiffTrain build for [60a927d](60a927d)
1 parent 990d5cc commit f10aaf1

19 files changed

+145
-65
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0ac3ea471fbcb7d79bc7d36179e960c72c779e76
1+
60a927d04ad3888facebcdf7da620aa1cfc9528f

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (__DEV__) {
2424
) {
2525
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
2626
}
27-
var ReactVersion = "18.3.0-www-classic-23db00d6";
27+
var ReactVersion = "18.3.0-www-classic-6f4b3c51";
2828

2929
// ATTENTION
3030
// When adding new symbols to this file,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,4 +587,4 @@ exports.useSyncExternalStore = function (
587587
exports.useTransition = function () {
588588
return ReactCurrentDispatcher.current.useTransition();
589589
};
590-
exports.version = "18.3.0-www-classic-db2e638d";
590+
exports.version = "18.3.0-www-classic-7b414a88";

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if (__DEV__) {
6666
return self;
6767
}
6868

69-
var ReactVersion = "18.3.0-www-classic-47994933";
69+
var ReactVersion = "18.3.0-www-classic-87e74e5e";
7070

7171
var LegacyRoot = 0;
7272
var ConcurrentRoot = 1;
@@ -9051,10 +9051,19 @@ if (__DEV__) {
90519051
queue.pending = null;
90529052
}
90539053

9054-
if (baseQueue !== null) {
9054+
var baseState = hook.baseState;
9055+
9056+
if (baseQueue === null) {
9057+
// If there are no pending updates, then the memoized state should be the
9058+
// same as the base state. Currently these only diverge in the case of
9059+
// useOptimistic, because useOptimistic accepts a new baseState on
9060+
// every render.
9061+
hook.memoizedState = baseState; // We don't need to call markWorkInProgressReceivedUpdate because
9062+
// baseState is derived from other reactive values.
9063+
} else {
90559064
// We have a queue to process.
90569065
var first = baseQueue.next;
9057-
var newState = hook.baseState;
9066+
var newState = baseState;
90589067
var newBaseState = null;
90599068
var newBaseQueueFirst = null;
90609069
var newBaseQueueLast = null;

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if (__DEV__) {
6666
return self;
6767
}
6868

69-
var ReactVersion = "18.3.0-www-modern-e805922c";
69+
var ReactVersion = "18.3.0-www-modern-dc8082dd";
7070

7171
var LegacyRoot = 0;
7272
var ConcurrentRoot = 1;
@@ -8801,10 +8801,19 @@ if (__DEV__) {
88018801
queue.pending = null;
88028802
}
88038803

8804-
if (baseQueue !== null) {
8804+
var baseState = hook.baseState;
8805+
8806+
if (baseQueue === null) {
8807+
// If there are no pending updates, then the memoized state should be the
8808+
// same as the base state. Currently these only diverge in the case of
8809+
// useOptimistic, because useOptimistic accepts a new baseState on
8810+
// every render.
8811+
hook.memoizedState = baseState; // We don't need to call markWorkInProgressReceivedUpdate because
8812+
// baseState is derived from other reactive values.
8813+
} else {
88058814
// We have a queue to process.
88068815
var first = baseQueue.next;
8807-
var newState = hook.baseState;
8816+
var newState = baseState;
88088817
var newBaseState = null;
88098818
var newBaseQueueFirst = null;
88108819
var newBaseQueueLast = null;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,9 +2860,10 @@ function updateReducerImpl(hook, current, reducer) {
28602860
current.baseQueue = baseQueue = pendingQueue;
28612861
queue.pending = null;
28622862
}
2863-
if (null !== baseQueue) {
2863+
pendingQueue = hook.baseState;
2864+
if (null === baseQueue) hook.memoizedState = pendingQueue;
2865+
else {
28642866
current = baseQueue.next;
2865-
pendingQueue = hook.baseState;
28662867
var newBaseQueueFirst = (baseFirst = null),
28672868
newBaseQueueLast = null,
28682869
update = current;
@@ -10291,7 +10292,7 @@ var slice = Array.prototype.slice,
1029110292
return null;
1029210293
},
1029310294
bundleType: 0,
10294-
version: "18.3.0-www-classic-d67c518f",
10295+
version: "18.3.0-www-classic-c9d1dfab",
1029510296
rendererPackageName: "react-art"
1029610297
};
1029710298
var internals$jscomp$inline_1325 = {
@@ -10322,7 +10323,7 @@ var internals$jscomp$inline_1325 = {
1032210323
scheduleRoot: null,
1032310324
setRefreshHandler: null,
1032410325
getCurrentFiber: null,
10325-
reconcilerVersion: "18.3.0-www-classic-d67c518f"
10326+
reconcilerVersion: "18.3.0-www-classic-c9d1dfab"
1032610327
};
1032710328
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1032810329
var hook$jscomp$inline_1326 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,9 +2667,10 @@ function updateReducerImpl(hook, current, reducer) {
26672667
current.baseQueue = baseQueue = pendingQueue;
26682668
queue.pending = null;
26692669
}
2670-
if (null !== baseQueue) {
2670+
pendingQueue = hook.baseState;
2671+
if (null === baseQueue) hook.memoizedState = pendingQueue;
2672+
else {
26712673
current = baseQueue.next;
2672-
pendingQueue = hook.baseState;
26732674
var newBaseQueueFirst = (baseFirst = null),
26742675
newBaseQueueLast = null,
26752676
update = current;
@@ -9957,7 +9958,7 @@ var slice = Array.prototype.slice,
99579958
return null;
99589959
},
99599960
bundleType: 0,
9960-
version: "18.3.0-www-modern-bab56d31",
9961+
version: "18.3.0-www-modern-31c1a5e7",
99619962
rendererPackageName: "react-art"
99629963
};
99639964
var internals$jscomp$inline_1305 = {
@@ -9988,7 +9989,7 @@ var internals$jscomp$inline_1305 = {
99889989
scheduleRoot: null,
99899990
setRefreshHandler: null,
99909991
getCurrentFiber: null,
9991-
reconcilerVersion: "18.3.0-www-modern-bab56d31"
9992+
reconcilerVersion: "18.3.0-www-modern-31c1a5e7"
99929993
};
99939994
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
99949995
var hook$jscomp$inline_1306 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13662,10 +13662,19 @@ if (__DEV__) {
1366213662
queue.pending = null;
1366313663
}
1366413664

13665-
if (baseQueue !== null) {
13665+
var baseState = hook.baseState;
13666+
13667+
if (baseQueue === null) {
13668+
// If there are no pending updates, then the memoized state should be the
13669+
// same as the base state. Currently these only diverge in the case of
13670+
// useOptimistic, because useOptimistic accepts a new baseState on
13671+
// every render.
13672+
hook.memoizedState = baseState; // We don't need to call markWorkInProgressReceivedUpdate because
13673+
// baseState is derived from other reactive values.
13674+
} else {
1366613675
// We have a queue to process.
1366713676
var first = baseQueue.next;
13668-
var newState = hook.baseState;
13677+
var newState = baseState;
1366913678
var newBaseState = null;
1367013679
var newBaseQueueFirst = null;
1367113680
var newBaseQueueLast = null;
@@ -34959,7 +34968,7 @@ if (__DEV__) {
3495934968
return root;
3496034969
}
3496134970

34962-
var ReactVersion = "18.3.0-www-classic-df230f01";
34971+
var ReactVersion = "18.3.0-www-classic-1829de97";
3496334972

3496434973
function createPortal$1(
3496534974
children,

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13598,10 +13598,19 @@ if (__DEV__) {
1359813598
queue.pending = null;
1359913599
}
1360013600

13601-
if (baseQueue !== null) {
13601+
var baseState = hook.baseState;
13602+
13603+
if (baseQueue === null) {
13604+
// If there are no pending updates, then the memoized state should be the
13605+
// same as the base state. Currently these only diverge in the case of
13606+
// useOptimistic, because useOptimistic accepts a new baseState on
13607+
// every render.
13608+
hook.memoizedState = baseState; // We don't need to call markWorkInProgressReceivedUpdate because
13609+
// baseState is derived from other reactive values.
13610+
} else {
1360213611
// We have a queue to process.
1360313612
var first = baseQueue.next;
13604-
var newState = hook.baseState;
13613+
var newState = baseState;
1360513614
var newBaseState = null;
1360613615
var newBaseQueueFirst = null;
1360713616
var newBaseQueueLast = null;
@@ -34780,7 +34789,7 @@ if (__DEV__) {
3478034789
return root;
3478134790
}
3478234791

34783-
var ReactVersion = "18.3.0-www-modern-332dd66b";
34792+
var ReactVersion = "18.3.0-www-modern-bac1e3ec";
3478434793

3478534794
function createPortal$1(
3478634795
children,

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,9 +3600,10 @@ function updateReducerImpl(hook, current, reducer) {
36003600
current.baseQueue = baseQueue = pendingQueue;
36013601
queue.pending = null;
36023602
}
3603-
if (null !== baseQueue) {
3603+
pendingQueue = hook.baseState;
3604+
if (null === baseQueue) hook.memoizedState = pendingQueue;
3605+
else {
36043606
current = baseQueue.next;
3605-
pendingQueue = hook.baseState;
36063607
var newBaseQueueFirst = (baseFirst = null),
36073608
newBaseQueueLast = null,
36083609
update = current;
@@ -16595,7 +16596,7 @@ Internals.Events = [
1659516596
var devToolsConfig$jscomp$inline_1799 = {
1659616597
findFiberByHostInstance: getClosestInstanceFromNode,
1659716598
bundleType: 0,
16598-
version: "18.3.0-www-classic-f0f463da",
16599+
version: "18.3.0-www-classic-be8e039e",
1659916600
rendererPackageName: "react-dom"
1660016601
};
1660116602
var internals$jscomp$inline_2145 = {
@@ -16625,7 +16626,7 @@ var internals$jscomp$inline_2145 = {
1662516626
scheduleRoot: null,
1662616627
setRefreshHandler: null,
1662716628
getCurrentFiber: null,
16628-
reconcilerVersion: "18.3.0-www-classic-f0f463da"
16629+
reconcilerVersion: "18.3.0-www-classic-be8e039e"
1662916630
};
1663016631
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1663116632
var hook$jscomp$inline_2146 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -16962,4 +16963,4 @@ exports.useFormState = function () {
1696216963
exports.useFormStatus = function () {
1696316964
throw Error(formatProdErrorMessage(248));
1696416965
};
16965-
exports.version = "18.3.0-www-classic-f0f463da";
16966+
exports.version = "18.3.0-www-classic-be8e039e";

0 commit comments

Comments
 (0)