246
247
type ExecutionContext = number;
248
249
-export const NoContext = /* */ 0b00000;
250
-const BatchedContext = /* */ 0b00001;
251
-const LegacyUnbatchedContext = /* */ 0b00010;
252
-const RenderContext = /* */ 0b00100;
253
-const CommitContext = /* */ 0b01000;
254
-export const RetryAfterError = /* */ 0b10000;
249
+export const NoContext = /* */ 0b0000;
250
+const BatchedContext = /* */ 0b0001;
251
+const RenderContext = /* */ 0b0010;
252
+const CommitContext = /* */ 0b0100;
253
+export const RetryAfterError = /* */ 0b1000;
254
255
type RootExitStatus = 0 | 1 | 2 | 3 | 4 | 5;
256
const RootIncomplete = 0;
514
}
515
}
516
518
- if (lane === SyncLane) {
519
- if (
520
- // Check if we're inside unbatchedUpdates
521
- (executionContext & LegacyUnbatchedContext) !== NoContext &&
522
- // Check if we're not already rendering
523
- (executionContext & (RenderContext | CommitContext)) === NoContext
524
- ) {
525
- // This is a legacy edge case. The initial mount of a ReactDOM.render-ed
526
- // root inside of batchedUpdates should be synchronous, but layout updates
527
- // should be deferred until the end of the batch.
528
- performSyncWorkOnRoot(root);
529
- } else {
530
- ensureRootIsScheduled(root, eventTime);
531
- if (
532
- executionContext === NoContext &&
533
- (fiber.mode & ConcurrentMode) === NoMode
534
- ) {
535
- // Flush the synchronous work now, unless we're already working or inside
536
- // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
537
- // scheduleCallbackForFiber to preserve the ability to schedule a callback
538
- // without immediately flushing it. We only do this for user-initiated
539
- // updates, to preserve historical behavior of legacy mode.
540
- resetRenderTimer();
541
- flushSyncCallbacksOnlyInLegacyMode();
542
- }
543
- }
544
- } else {
545
- // Schedule other updates after in case the callback is sync.
546
- ensureRootIsScheduled(root, eventTime);
517
+ ensureRootIsScheduled(root, eventTime);
518
+ if (
519
+ lane === SyncLane &&
520
+ executionContext === NoContext &&
521
+ (fiber.mode & ConcurrentMode) === NoMode
522
+ ) {
523
+ // Flush the synchronous work now, unless we're already working or inside
524
+ // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
525
+ // scheduleCallbackForFiber to preserve the ability to schedule a callback
526
+ // without immediately flushing it. We only do this for user-initiated
527
+ // updates, to preserve historical behavior of legacy mode.
528
+ resetRenderTimer();
529
+ flushSyncCallbacksOnlyInLegacyMode();
530
}
531
532
return root;
1078
}
1079
}
1080
1098
-export function unbatchedUpdates<A, R>(fn: (a: A) => R, a: A): R {
1099
- const prevExecutionContext = executionContext;
1100
- executionContext &= ~BatchedContext;
1101
- executionContext |= LegacyUnbatchedContext;
1102
- try {
1103
- return fn(a);
1104
- } finally {
1105
- executionContext = prevExecutionContext;
1106
- // If there were legacy sync updates, flush them at the end of the outer
1107
- // most batchedUpdates-like method.
1108
- if (executionContext === NoContext) {
1109
- resetRenderTimer();
1110
- // TODO: I think this call is redundant, because we flush inside
1111
- // scheduleUpdateOnFiber when LegacyUnbatchedContext is set.
1112
- flushSyncCallbacksOnlyInLegacyMode();
1113
- }
1114
- }
1115
-}
1116
-
1081
export function flushSyncWithoutWarningIfAlreadyRendering<A, R>(
1082
fn: A => R,
1083
a: A,
1918
throw error;
1919
}
1920
1957
- if ((executionContext & LegacyUnbatchedContext) !== NoContext) {
1958
- if (__DEV__) {
1959
- if (enableDebugTracing) {
1960
- logCommitStopped();
1961
- }
1962
- }
1963
-
1964
- if (enableSchedulingProfiler) {
1965
- markCommitStopped();
1966
- }
1967
-
1968
- // This is a legacy edge case. We just committed the initial mount of
1969
- // a ReactDOM.render-ed root inside of batchedUpdates. The commit fired
1970
- // synchronously, but layout updates should be deferred until the end
1971
- // of the batch.
1972
- return null;
1973
- }
1974
-
1921
// If the passive effects are the result of a discrete render, flush them
1922
// synchronously at the end of the current task so that the result is
1923
// immediately observable. Otherwise, we assume that they are not