1044
return executionContext;
1045
}
1046
1047
-export function flushDiscreteUpdates() {
1048
- // TODO: Should be able to flush inside batchedUpdates, but not inside `act`.
1049
- // However, `act` uses `batchedUpdates`, so there's no way to distinguish
1050
- // those two cases. Need to fix this before exposing flushDiscreteUpdates
1051
- // as a public API.
1052
- if (
1053
- (executionContext & (BatchedContext | RenderContext | CommitContext)) !==
1054
- NoContext
1055
- ) {
1056
- if (__DEV__) {
1057
- if ((executionContext & RenderContext) !== NoContext) {
1058
- console.error(
1059
- 'unstable_flushDiscreteUpdates: Cannot flush updates when React is ' +
1060
- 'already rendering.',
1061
- );
1062
- }
1063
- }
1064
- // We're already rendering, so we can't synchronously flush pending work.
1065
- // This is probably a nested event dispatch triggered by a lifecycle/effect,
1066
- // like `el.focus()`. Exit.
1067
- return;
1068
- }
1069
- flushSyncCallbacks();
1070
- // If the discrete updates scheduled passive effects, flush them now so that
1071
- // they fire before the next serial event.
1072
- flushPassiveEffects();
1073
-}
1074
-
1047
export function deferredUpdates<A>(fn: () => A): A {
1048
const previousPriority = getCurrentUpdatePriority();
1049
const prevTransition = ReactCurrentBatchConfig.transition;
1114
}
1115
}
1116
1145
-export function flushSync<A, R>(fn: A => R, a: A): R {
1117
+export function flushSyncWithoutWarningIfAlreadyRendering<A, R>(
1118
+ fn: A => R,
1119
+ a: A,
1120
+): R {
1121
const prevExecutionContext = executionContext;
1122
executionContext |= BatchedContext;
1123
1140
// the stack.
1141
if ((executionContext & (RenderContext | CommitContext)) === NoContext) {
1142
flushSyncCallbacks();
1168
- } else {
1169
- if (__DEV__) {
1170
- console.error(
1171
- 'flushSync was called from inside a lifecycle method. React cannot ' +
1172
- 'flush when React is already rendering. Consider moving this call to ' +
1173
- 'a scheduler task or micro task.',
1174
- );
1175
- }
1143
}
1144
}
1145
}
1146
1147
+export function flushSync<A, R>(fn: A => R, a: A): R {
1148
+ if (__DEV__) {
1149
+ if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
1150
+ console.error(
1151
+ 'flushSync was called from inside a lifecycle method. React cannot ' +
1152
+ 'flush when React is already rendering. Consider moving this call to ' +
1153
+ 'a scheduler task or micro task.',
1154
+ );
1155
+ }
1156
+ }
1157
+ return flushSyncWithoutWarningIfAlreadyRendering(fn, a);
1158
+}
1159
+
1160
export function flushControlled(fn: () => mixed): void {
1161
const prevExecutionContext = executionContext;
1162
executionContext |= BatchedContext;