7
7
* @noflow
8
8
* @nolint
9
9
* @preventMunge
10
- * @generated SignedSource<<6f91cae5b10795257ddec042012ed6d4 >>
10
+ * @generated SignedSource<<44707665e2d49df89524e6821112ab6c >>
11
11
*/
12
12
13
13
"use strict";
@@ -3469,7 +3469,11 @@ if (__DEV__) {
3469
3469
}
3470
3470
}
3471
3471
3472
- function requestTransitionLane() {
3472
+ function requestTransitionLane( // This argument isn't used, it's only here to encourage the caller to
3473
+ // check that it's inside a transition before calling this function.
3474
+ // TODO: Make this non-nullable. Requires a tweak to useOptimistic.
3475
+ transition
3476
+ ) {
3473
3477
// The algorithm for assigning an update to a lane should be stable for all
3474
3478
// updates at the same priority within the same event. To do this, the
3475
3479
// inputs to the algorithm must be the same.
@@ -3502,7 +3506,7 @@ if (__DEV__) {
3502
3506
// until the async action scope has completed.
3503
3507
3504
3508
var currentEntangledActionThenable = null;
3505
- function entangleAsyncAction(thenable) {
3509
+ function entangleAsyncAction(transition, thenable) {
3506
3510
// `thenable` is the return value of the async action scope function. Create
3507
3511
// a combined thenable that resolves once every entangled scope function
3508
3512
// has finished.
@@ -7738,16 +7742,7 @@ if (__DEV__) {
7738
7742
markSkippedUpdateLanes(updateLane);
7739
7743
} else {
7740
7744
// This update does have sufficient priority.
7741
- // Check if this update is part of a pending async action. If so,
7742
- // we'll need to suspend until the action has finished, so that it's
7743
- // batched together with future updates in the same action.
7744
- if (
7745
- updateLane !== NoLane &&
7746
- updateLane === peekEntangledActionLane()
7747
- ) {
7748
- didReadFromEntangledAsyncAction = true;
7749
- } // Check if this is an optimistic update.
7750
-
7745
+ // Check if this is an optimistic update.
7751
7746
var revertLane = update.revertLane;
7752
7747
7753
7748
if (revertLane === NoLane) {
@@ -7767,6 +7762,12 @@ if (__DEV__) {
7767
7762
next: null
7768
7763
};
7769
7764
newBaseQueueLast = newBaseQueueLast.next = _clone;
7765
+ } // Check if this update is part of a pending async action. If so,
7766
+ // we'll need to suspend until the action has finished, so that it's
7767
+ // batched together with future updates in the same action.
7768
+
7769
+ if (updateLane === peekEntangledActionLane()) {
7770
+ didReadFromEntangledAsyncAction = true;
7770
7771
}
7771
7772
} else {
7772
7773
// This is an optimistic update. If the "revert" priority is
@@ -7777,7 +7778,14 @@ if (__DEV__) {
7777
7778
// The transition that this optimistic update is associated with
7778
7779
// has finished. Pretend the update doesn't exist by skipping
7779
7780
// over it.
7780
- update = update.next;
7781
+ update = update.next; // Check if this update is part of a pending async action. If so,
7782
+ // we'll need to suspend until the action has finished, so that it's
7783
+ // batched together with future updates in the same action.
7784
+
7785
+ if (revertLane === peekEntangledActionLane()) {
7786
+ didReadFromEntangledAsyncAction = true;
7787
+ }
7788
+
7781
7789
continue;
7782
7790
} else {
7783
7791
var _clone2 = {
@@ -8288,15 +8296,18 @@ if (__DEV__) {
8288
8296
var prevState = actionQueue.state; // This is a fork of startTransition
8289
8297
8290
8298
var prevTransition = ReactCurrentBatchConfig$2.transition;
8291
- ReactCurrentBatchConfig$2.transition = {};
8292
- var currentTransition = ReactCurrentBatchConfig$2.transition;
8299
+ var currentTransition = {
8300
+ _callbacks: new Set()
8301
+ };
8302
+ ReactCurrentBatchConfig$2.transition = currentTransition;
8293
8303
8294
8304
{
8295
8305
ReactCurrentBatchConfig$2.transition._updatedFibers = new Set();
8296
8306
}
8297
8307
8298
8308
try {
8299
8309
var returnValue = action(prevState, payload);
8310
+ notifyTransitionCallbacks(currentTransition, returnValue);
8300
8311
8301
8312
if (
8302
8313
returnValue !== null &&
@@ -8315,7 +8326,6 @@ if (__DEV__) {
8315
8326
return finishRunningFormStateAction(actionQueue, setState);
8316
8327
}
8317
8328
);
8318
- entangleAsyncAction(thenable);
8319
8329
setState(thenable);
8320
8330
} else {
8321
8331
setState(returnValue);
@@ -8876,7 +8886,9 @@ if (__DEV__) {
8876
8886
higherEventPriority(previousPriority, ContinuousEventPriority)
8877
8887
);
8878
8888
var prevTransition = ReactCurrentBatchConfig$2.transition;
8879
- var currentTransition = {};
8889
+ var currentTransition = {
8890
+ _callbacks: new Set()
8891
+ };
8880
8892
8881
8893
{
8882
8894
// We don't really need to use an optimistic update here, because we
@@ -8895,7 +8907,8 @@ if (__DEV__) {
8895
8907
8896
8908
try {
8897
8909
if (enableAsyncActions) {
8898
- var returnValue = callback(); // Check if we're inside an async action scope. If so, we'll entangle
8910
+ var returnValue = callback();
8911
+ notifyTransitionCallbacks(currentTransition, returnValue); // Check if we're inside an async action scope. If so, we'll entangle
8899
8912
// this new action with the existing scope.
8900
8913
//
8901
8914
// If we're not already inside an async action scope, and this action is
@@ -8909,8 +8922,7 @@ if (__DEV__) {
8909
8922
typeof returnValue === "object" &&
8910
8923
typeof returnValue.then === "function"
8911
8924
) {
8912
- var thenable = returnValue;
8913
- entangleAsyncAction(thenable); // Create a thenable that resolves to `finishedState` once the async
8925
+ var thenable = returnValue; // Create a thenable that resolves to `finishedState` once the async
8914
8926
// action has completed.
8915
8927
8916
8928
var thenableForFinishedState = chainThenableValue(
@@ -9214,8 +9226,10 @@ if (__DEV__) {
9214
9226
queue,
9215
9227
action
9216
9228
) {
9229
+ var transition = requestCurrentTransition();
9230
+
9217
9231
{
9218
- if (ReactCurrentBatchConfig$2. transition === null) {
9232
+ if (transition === null) {
9219
9233
// An optimistic update occurred, but startTransition is not on the stack.
9220
9234
// There are two likely scenarios.
9221
9235
// One possibility is that the optimistic update is triggered by a regular
@@ -16268,9 +16282,35 @@ if (__DEV__) {
16268
16282
16269
16283
var ReactCurrentBatchConfig$1 =
16270
16284
ReactSharedInternals.ReactCurrentBatchConfig;
16271
- var NoTransition = null;
16272
16285
function requestCurrentTransition() {
16273
- return ReactCurrentBatchConfig$1.transition;
16286
+ var transition = ReactCurrentBatchConfig$1.transition;
16287
+
16288
+ if (transition !== null) {
16289
+ // Whenever a transition update is scheduled, register a callback on the
16290
+ // transition object so we can get the return value of the scope function.
16291
+ transition._callbacks.add(handleTransitionScopeResult);
16292
+ }
16293
+
16294
+ return transition;
16295
+ }
16296
+
16297
+ function handleTransitionScopeResult(transition, returnValue) {
16298
+ if (
16299
+ returnValue !== null &&
16300
+ typeof returnValue === "object" &&
16301
+ typeof returnValue.then === "function"
16302
+ ) {
16303
+ // This is an async action.
16304
+ var thenable = returnValue;
16305
+ entangleAsyncAction(transition, thenable);
16306
+ }
16307
+ }
16308
+
16309
+ function notifyTransitionCallbacks(transition, returnValue) {
16310
+ var callbacks = transition._callbacks;
16311
+ callbacks.forEach(function (callback) {
16312
+ return callback(transition, returnValue);
16313
+ });
16274
16314
} // When retrying a Suspense/Offscreen boundary, we restore the cache that was
16275
16315
// used during the previous render by placing it here, on the stack.
16276
16316
@@ -21566,17 +21606,17 @@ if (__DEV__) {
21566
21606
return pickArbitraryLane(workInProgressRootRenderLanes);
21567
21607
}
21568
21608
21569
- var isTransition = requestCurrentTransition() !== NoTransition ;
21609
+ var transition = requestCurrentTransition();
21570
21610
21571
- if (isTransition ) {
21572
- if (ReactCurrentBatchConfig.transition !== null) {
21573
- var transition = ReactCurrentBatchConfig.transition;
21611
+ if (transition !== null ) {
21612
+ {
21613
+ var batchConfigTransition = ReactCurrentBatchConfig.transition;
21574
21614
21575
- if (!transition ._updatedFibers) {
21576
- transition ._updatedFibers = new Set();
21615
+ if (!batchConfigTransition ._updatedFibers) {
21616
+ batchConfigTransition ._updatedFibers = new Set();
21577
21617
}
21578
21618
21579
- transition ._updatedFibers.add(fiber);
21619
+ batchConfigTransition ._updatedFibers.add(fiber);
21580
21620
}
21581
21621
21582
21622
var actionScopeLane = peekEntangledActionLane();
@@ -21643,7 +21683,7 @@ if (__DEV__) {
21643
21683
workInProgressDeferredLane = OffscreenLane;
21644
21684
} else {
21645
21685
// Everything else is spawned as a transition.
21646
- workInProgressDeferredLane = requestTransitionLane ();
21686
+ workInProgressDeferredLane = claimNextTransitionLane ();
21647
21687
}
21648
21688
} // Mark the parent Suspense boundary so it knows to spawn the deferred lane.
21649
21689
@@ -25572,7 +25612,7 @@ if (__DEV__) {
25572
25612
return root;
25573
25613
}
25574
25614
25575
- var ReactVersion = "18.3.0-canary-382190c59 -20240125";
25615
+ var ReactVersion = "18.3.0-canary-85b296e9b -20240125";
25576
25616
25577
25617
// Might add PROFILE later.
25578
25618
0 commit comments