7
7
* @noflow
8
8
* @nolint
9
9
* @preventMunge
10
- * @generated SignedSource<<a8e13b4ae0027a62588426b400d5b877 >>
10
+ * @generated SignedSource<<6ab290eb8548e08a74bf8def3f649394 >>
11
11
*/
12
12
13
13
"use strict";
@@ -8476,7 +8476,13 @@ if (__DEV__) {
8476
8476
} // useFormState actions run sequentially, because each action receives the
8477
8477
// previous state as an argument. We store pending actions on a queue.
8478
8478
8479
- function dispatchFormState(fiber, actionQueue, setState, payload) {
8479
+ function dispatchFormState(
8480
+ fiber,
8481
+ actionQueue,
8482
+ setPendingState,
8483
+ setState,
8484
+ payload
8485
+ ) {
8480
8486
if (isRenderPhaseUpdate(fiber)) {
8481
8487
throw new Error("Cannot update form state while rendering.");
8482
8488
}
@@ -8491,7 +8497,7 @@ if (__DEV__) {
8491
8497
next: null // circular
8492
8498
};
8493
8499
newLast.next = actionQueue.pending = newLast;
8494
- runFormStateAction(actionQueue, setState, payload);
8500
+ runFormStateAction(actionQueue, setPendingState, setState, payload);
8495
8501
} else {
8496
8502
// There's already an action running. Add to the queue.
8497
8503
var first = last.next;
@@ -8503,7 +8509,12 @@ if (__DEV__) {
8503
8509
}
8504
8510
}
8505
8511
8506
- function runFormStateAction(actionQueue, setState, payload) {
8512
+ function runFormStateAction(
8513
+ actionQueue,
8514
+ setPendingState,
8515
+ setState,
8516
+ payload
8517
+ ) {
8507
8518
var action = actionQueue.action;
8508
8519
var prevState = actionQueue.state; // This is a fork of startTransition
8509
8520
@@ -8515,7 +8526,10 @@ if (__DEV__) {
8515
8526
8516
8527
{
8517
8528
ReactCurrentBatchConfig$2.transition._updatedFibers = new Set();
8518
- }
8529
+ } // Optimistically update the pending state, similar to useTransition.
8530
+ // This will be reverted automatically when all actions are finished.
8531
+
8532
+ setPendingState(true);
8519
8533
8520
8534
try {
8521
8535
var returnValue = action(prevState, payload);
@@ -8532,18 +8546,26 @@ if (__DEV__) {
8532
8546
thenable.then(
8533
8547
function (nextState) {
8534
8548
actionQueue.state = nextState;
8535
- finishRunningFormStateAction(actionQueue, setState);
8549
+ finishRunningFormStateAction(
8550
+ actionQueue,
8551
+ setPendingState,
8552
+ setState
8553
+ );
8536
8554
},
8537
8555
function () {
8538
- return finishRunningFormStateAction(actionQueue, setState);
8556
+ return finishRunningFormStateAction(
8557
+ actionQueue,
8558
+ setPendingState,
8559
+ setState
8560
+ );
8539
8561
}
8540
8562
);
8541
8563
setState(thenable);
8542
8564
} else {
8543
8565
setState(returnValue);
8544
8566
var nextState = returnValue;
8545
8567
actionQueue.state = nextState;
8546
- finishRunningFormStateAction(actionQueue, setState);
8568
+ finishRunningFormStateAction(actionQueue, setPendingState, setState);
8547
8569
}
8548
8570
} catch (error) {
8549
8571
// This is a trick to get the `useFormState` hook to rethrow the error.
@@ -8555,7 +8577,7 @@ if (__DEV__) {
8555
8577
reason: error // $FlowFixMe: Not sure why this doesn't work
8556
8578
};
8557
8579
setState(rejectedThenable);
8558
- finishRunningFormStateAction(actionQueue, setState);
8580
+ finishRunningFormStateAction(actionQueue, setPendingState, setState);
8559
8581
} finally {
8560
8582
ReactCurrentBatchConfig$2.transition = prevTransition;
8561
8583
@@ -8577,7 +8599,11 @@ if (__DEV__) {
8577
8599
}
8578
8600
}
8579
8601
8580
- function finishRunningFormStateAction(actionQueue, setState) {
8602
+ function finishRunningFormStateAction(
8603
+ actionQueue,
8604
+ setPendingState,
8605
+ setState
8606
+ ) {
8581
8607
// The action finished running. Pop it from the queue and run the next pending
8582
8608
// action, if there are any.
8583
8609
var last = actionQueue.pending;
@@ -8593,7 +8619,12 @@ if (__DEV__) {
8593
8619
var next = first.next;
8594
8620
last.next = next; // Run the next action.
8595
8621
8596
- runFormStateAction(actionQueue, setState, next.payload);
8622
+ runFormStateAction(
8623
+ actionQueue,
8624
+ setPendingState,
8625
+ setState,
8626
+ next.payload
8627
+ );
8597
8628
}
8598
8629
}
8599
8630
}
@@ -8623,7 +8654,16 @@ if (__DEV__) {
8623
8654
currentlyRenderingFiber$1,
8624
8655
stateQueue
8625
8656
);
8626
- stateQueue.dispatch = setState; // Action queue hook. This is used to queue pending actions. The queue is
8657
+ stateQueue.dispatch = setState; // Pending state. This is used to store the pending state of the action.
8658
+ // Tracked optimistically, like a transition pending state.
8659
+
8660
+ var pendingStateHook = mountStateImpl(false);
8661
+ var setPendingState = dispatchOptimisticSetState.bind(
8662
+ null,
8663
+ currentlyRenderingFiber$1,
8664
+ false,
8665
+ pendingStateHook.queue
8666
+ ); // Action queue hook. This is used to queue pending actions. The queue is
8627
8667
// shared between all instances of the hook. Similar to a regular state queue,
8628
8668
// but different because the actions are run sequentially, and they run in
8629
8669
// an event instead of during render.
@@ -8641,14 +8681,15 @@ if (__DEV__) {
8641
8681
null,
8642
8682
currentlyRenderingFiber$1,
8643
8683
actionQueue,
8684
+ setPendingState,
8644
8685
setState
8645
8686
);
8646
8687
actionQueue.dispatch = dispatch; // Stash the action function on the memoized state of the hook. We'll use this
8647
8688
// to detect when the action function changes so we can update it in
8648
8689
// an effect.
8649
8690
8650
8691
actionQueueHook.memoizedState = action;
8651
- return [initialState, dispatch];
8692
+ return [initialState, dispatch, false ];
8652
8693
}
8653
8694
8654
8695
function updateFormState(action, initialState, permalink) {
@@ -8669,7 +8710,10 @@ if (__DEV__) {
8669
8710
currentStateHook,
8670
8711
formStateReducer
8671
8712
),
8672
- actionResult = _updateReducerImpl[0]; // This will suspend until the action finishes.
8713
+ actionResult = _updateReducerImpl[0];
8714
+
8715
+ var _updateState = updateState(),
8716
+ isPending = _updateState[0]; // This will suspend until the action finishes.
8673
8717
8674
8718
var state =
8675
8719
typeof actionResult === "object" &&
@@ -8693,7 +8737,7 @@ if (__DEV__) {
8693
8737
);
8694
8738
}
8695
8739
8696
- return [state, dispatch];
8740
+ return [state, dispatch, isPending ];
8697
8741
}
8698
8742
8699
8743
function formStateActionEffect(actionQueue, action) {
@@ -8721,8 +8765,9 @@ if (__DEV__) {
8721
8765
var actionQueue = actionQueueHook.queue;
8722
8766
var dispatch = actionQueue.dispatch; // This may have changed during the rerender.
8723
8767
8724
- actionQueueHook.memoizedState = action;
8725
- return [state, dispatch];
8768
+ actionQueueHook.memoizedState = action; // For mount, pending is always false.
8769
+
8770
+ return [state, dispatch, false];
8726
8771
}
8727
8772
8728
8773
function pushEffect(tag, create, inst, deps) {
@@ -9201,8 +9246,8 @@ if (__DEV__) {
9201
9246
}
9202
9247
9203
9248
function updateTransition() {
9204
- var _updateState = updateState(),
9205
- booleanOrThenable = _updateState [0];
9249
+ var _updateState2 = updateState(),
9250
+ booleanOrThenable = _updateState2 [0];
9206
9251
9207
9252
var hook = updateWorkInProgressHook();
9208
9253
var start = hook.memoizedState;
@@ -25409,7 +25454,7 @@ if (__DEV__) {
25409
25454
return root;
25410
25455
}
25411
25456
25412
- var ReactVersion = "18.3.0-canary-3e6bc7d2d -20240312";
25457
+ var ReactVersion = "18.3.0-canary-17eaacaac -20240312";
25413
25458
25414
25459
// Might add PROFILE later.
25415
25460
0 commit comments