@@ -66,7 +66,7 @@ if (__DEV__) {
66
66
return self;
67
67
}
68
68
69
- var ReactVersion = "18.3.0-www-classic-3c471167 ";
69
+ var ReactVersion = "18.3.0-www-classic-1172eaef ";
70
70
71
71
var LegacyRoot = 0;
72
72
var ConcurrentRoot = 1;
@@ -9873,7 +9873,13 @@ if (__DEV__) {
9873
9873
} // useFormState actions run sequentially, because each action receives the
9874
9874
// previous state as an argument. We store pending actions on a queue.
9875
9875
9876
- function dispatchFormState(fiber, actionQueue, setState, payload) {
9876
+ function dispatchFormState(
9877
+ fiber,
9878
+ actionQueue,
9879
+ setPendingState,
9880
+ setState,
9881
+ payload
9882
+ ) {
9877
9883
if (isRenderPhaseUpdate(fiber)) {
9878
9884
throw new Error("Cannot update form state while rendering.");
9879
9885
}
@@ -9888,7 +9894,7 @@ if (__DEV__) {
9888
9894
next: null // circular
9889
9895
};
9890
9896
newLast.next = actionQueue.pending = newLast;
9891
- runFormStateAction(actionQueue, setState, payload);
9897
+ runFormStateAction(actionQueue, setPendingState, setState, payload);
9892
9898
} else {
9893
9899
// There's already an action running. Add to the queue.
9894
9900
var first = last.next;
@@ -9900,7 +9906,12 @@ if (__DEV__) {
9900
9906
}
9901
9907
}
9902
9908
9903
- function runFormStateAction(actionQueue, setState, payload) {
9909
+ function runFormStateAction(
9910
+ actionQueue,
9911
+ setPendingState,
9912
+ setState,
9913
+ payload
9914
+ ) {
9904
9915
var action = actionQueue.action;
9905
9916
var prevState = actionQueue.state; // This is a fork of startTransition
9906
9917
@@ -9912,7 +9923,10 @@ if (__DEV__) {
9912
9923
9913
9924
{
9914
9925
ReactCurrentBatchConfig$2.transition._updatedFibers = new Set();
9915
- }
9926
+ } // Optimistically update the pending state, similar to useTransition.
9927
+ // This will be reverted automatically when all actions are finished.
9928
+
9929
+ setPendingState(true);
9916
9930
9917
9931
try {
9918
9932
var returnValue = action(prevState, payload);
@@ -9929,18 +9943,26 @@ if (__DEV__) {
9929
9943
thenable.then(
9930
9944
function (nextState) {
9931
9945
actionQueue.state = nextState;
9932
- finishRunningFormStateAction(actionQueue, setState);
9946
+ finishRunningFormStateAction(
9947
+ actionQueue,
9948
+ setPendingState,
9949
+ setState
9950
+ );
9933
9951
},
9934
9952
function () {
9935
- return finishRunningFormStateAction(actionQueue, setState);
9953
+ return finishRunningFormStateAction(
9954
+ actionQueue,
9955
+ setPendingState,
9956
+ setState
9957
+ );
9936
9958
}
9937
9959
);
9938
9960
setState(thenable);
9939
9961
} else {
9940
9962
setState(returnValue);
9941
9963
var nextState = returnValue;
9942
9964
actionQueue.state = nextState;
9943
- finishRunningFormStateAction(actionQueue, setState);
9965
+ finishRunningFormStateAction(actionQueue, setPendingState, setState);
9944
9966
}
9945
9967
} catch (error) {
9946
9968
// This is a trick to get the `useFormState` hook to rethrow the error.
@@ -9952,7 +9974,7 @@ if (__DEV__) {
9952
9974
reason: error // $FlowFixMe: Not sure why this doesn't work
9953
9975
};
9954
9976
setState(rejectedThenable);
9955
- finishRunningFormStateAction(actionQueue, setState);
9977
+ finishRunningFormStateAction(actionQueue, setPendingState, setState);
9956
9978
} finally {
9957
9979
ReactCurrentBatchConfig$2.transition = prevTransition;
9958
9980
@@ -9974,7 +9996,11 @@ if (__DEV__) {
9974
9996
}
9975
9997
}
9976
9998
9977
- function finishRunningFormStateAction(actionQueue, setState) {
9999
+ function finishRunningFormStateAction(
10000
+ actionQueue,
10001
+ setPendingState,
10002
+ setState
10003
+ ) {
9978
10004
// The action finished running. Pop it from the queue and run the next pending
9979
10005
// action, if there are any.
9980
10006
var last = actionQueue.pending;
@@ -9990,7 +10016,12 @@ if (__DEV__) {
9990
10016
var next = first.next;
9991
10017
last.next = next; // Run the next action.
9992
10018
9993
- runFormStateAction(actionQueue, setState, next.payload);
10019
+ runFormStateAction(
10020
+ actionQueue,
10021
+ setPendingState,
10022
+ setState,
10023
+ next.payload
10024
+ );
9994
10025
}
9995
10026
}
9996
10027
}
@@ -10020,7 +10051,16 @@ if (__DEV__) {
10020
10051
currentlyRenderingFiber$1,
10021
10052
stateQueue
10022
10053
);
10023
- stateQueue.dispatch = setState; // Action queue hook. This is used to queue pending actions. The queue is
10054
+ stateQueue.dispatch = setState; // Pending state. This is used to store the pending state of the action.
10055
+ // Tracked optimistically, like a transition pending state.
10056
+
10057
+ var pendingStateHook = mountStateImpl(false);
10058
+ var setPendingState = dispatchOptimisticSetState.bind(
10059
+ null,
10060
+ currentlyRenderingFiber$1,
10061
+ false,
10062
+ pendingStateHook.queue
10063
+ ); // Action queue hook. This is used to queue pending actions. The queue is
10024
10064
// shared between all instances of the hook. Similar to a regular state queue,
10025
10065
// but different because the actions are run sequentially, and they run in
10026
10066
// an event instead of during render.
@@ -10038,14 +10078,15 @@ if (__DEV__) {
10038
10078
null,
10039
10079
currentlyRenderingFiber$1,
10040
10080
actionQueue,
10081
+ setPendingState,
10041
10082
setState
10042
10083
);
10043
10084
actionQueue.dispatch = dispatch; // Stash the action function on the memoized state of the hook. We'll use this
10044
10085
// to detect when the action function changes so we can update it in
10045
10086
// an effect.
10046
10087
10047
10088
actionQueueHook.memoizedState = action;
10048
- return [initialState, dispatch];
10089
+ return [initialState, dispatch, false ];
10049
10090
}
10050
10091
10051
10092
function updateFormState(action, initialState, permalink) {
@@ -10066,7 +10107,10 @@ if (__DEV__) {
10066
10107
currentStateHook,
10067
10108
formStateReducer
10068
10109
),
10069
- actionResult = _updateReducerImpl[0]; // This will suspend until the action finishes.
10110
+ actionResult = _updateReducerImpl[0];
10111
+
10112
+ var _updateState = updateState(),
10113
+ isPending = _updateState[0]; // This will suspend until the action finishes.
10070
10114
10071
10115
var state =
10072
10116
typeof actionResult === "object" &&
@@ -10090,7 +10134,7 @@ if (__DEV__) {
10090
10134
);
10091
10135
}
10092
10136
10093
- return [state, dispatch];
10137
+ return [state, dispatch, isPending ];
10094
10138
}
10095
10139
10096
10140
function formStateActionEffect(actionQueue, action) {
@@ -10118,8 +10162,9 @@ if (__DEV__) {
10118
10162
var actionQueue = actionQueueHook.queue;
10119
10163
var dispatch = actionQueue.dispatch; // This may have changed during the rerender.
10120
10164
10121
- actionQueueHook.memoizedState = action;
10122
- return [state, dispatch];
10165
+ actionQueueHook.memoizedState = action; // For mount, pending is always false.
10166
+
10167
+ return [state, dispatch, false];
10123
10168
}
10124
10169
10125
10170
function pushEffect(tag, create, inst, deps) {
@@ -10758,8 +10803,8 @@ if (__DEV__) {
10758
10803
}
10759
10804
10760
10805
function updateTransition() {
10761
- var _updateState = updateState(),
10762
- booleanOrThenable = _updateState [0];
10806
+ var _updateState2 = updateState(),
10807
+ booleanOrThenable = _updateState2 [0];
10763
10808
10764
10809
var hook = updateWorkInProgressHook();
10765
10810
var start = hook.memoizedState;
0 commit comments