Skip to content

Commit

Permalink
"Just remove the duck"
Browse files Browse the repository at this point in the history
  • Loading branch information
acdlite committed Jun 30, 2021
1 parent 8a27dbb commit 98d0e34
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
10 changes: 7 additions & 3 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
batchedUpdates,
discreteUpdates,
flushSync,
flushSyncWithWarningIfAlreadyRendering,
flushSyncWithoutWarningIfAlreadyRendering,
flushControlled,
injectIntoDevTools,
attemptSynchronousHydration,
Expand Down Expand Up @@ -97,7 +97,11 @@ if (__DEV__) {
}

setRestoreImplementation(restoreControlledState);
setBatchingImplementation(batchedUpdates, discreteUpdates, flushSync);
setBatchingImplementation(
batchedUpdates,
discreteUpdates,
flushSyncWithoutWarningIfAlreadyRendering,
);

function createPortal(
children: ReactNodeList,
Expand Down Expand Up @@ -162,7 +166,7 @@ const Internals = {
export {
createPortal,
batchedUpdates as unstable_batchedUpdates,
flushSyncWithWarningIfAlreadyRendering as flushSync,
flushSync,
Internals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
ReactVersion as version,
// Disabled behind disableLegacyReactDOMAPIs
Expand Down
2 changes: 1 addition & 1 deletion packages/react-noop-renderer/src/createReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
},

flushSync(fn: () => mixed) {
NoopRenderer.flushSyncWithWarningIfAlreadyRendering(fn);
NoopRenderer.flushSync(fn);
},

flushPassiveEffects: NoopRenderer.flushPassiveEffects,
Expand Down
10 changes: 5 additions & 5 deletions packages/react-reconciler/src/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
discreteUpdates as discreteUpdates_old,
flushControlled as flushControlled_old,
flushSync as flushSync_old,
flushSyncWithWarningIfAlreadyRendering as flushSyncWithWarningIfAlreadyRendering_old,
flushSyncWithoutWarningIfAlreadyRendering as flushSyncWithoutWarningIfAlreadyRendering_old,
flushPassiveEffects as flushPassiveEffects_old,
getPublicRootInstance as getPublicRootInstance_old,
attemptSynchronousHydration as attemptSynchronousHydration_old,
Expand Down Expand Up @@ -61,7 +61,7 @@ import {
discreteUpdates as discreteUpdates_new,
flushControlled as flushControlled_new,
flushSync as flushSync_new,
flushSyncWithWarningIfAlreadyRendering as flushSyncWithWarningIfAlreadyRendering_new,
flushSyncWithoutWarningIfAlreadyRendering as flushSyncWithoutWarningIfAlreadyRendering_new,
flushPassiveEffects as flushPassiveEffects_new,
getPublicRootInstance as getPublicRootInstance_new,
attemptSynchronousHydration as attemptSynchronousHydration_new,
Expand Down Expand Up @@ -112,9 +112,9 @@ export const flushControlled = enableNewReconciler
? flushControlled_new
: flushControlled_old;
export const flushSync = enableNewReconciler ? flushSync_new : flushSync_old;
export const flushSyncWithWarningIfAlreadyRendering = enableNewReconciler
? flushSyncWithWarningIfAlreadyRendering_new
: flushSyncWithWarningIfAlreadyRendering_old;
export const flushSyncWithoutWarningIfAlreadyRendering = enableNewReconciler
? flushSyncWithoutWarningIfAlreadyRendering_new
: flushSyncWithoutWarningIfAlreadyRendering_old;
export const flushPassiveEffects = enableNewReconciler
? flushPassiveEffects_new
: flushPassiveEffects_old;
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberReconciler.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
flushControlled,
deferredUpdates,
discreteUpdates,
flushSyncWithWarningIfAlreadyRendering,
flushSyncWithoutWarningIfAlreadyRendering,
flushPassiveEffects,
} from './ReactFiberWorkLoop.new';
import {
Expand Down Expand Up @@ -332,7 +332,7 @@ export {
discreteUpdates,
flushControlled,
flushSync,
flushSyncWithWarningIfAlreadyRendering,
flushSyncWithoutWarningIfAlreadyRendering,
flushPassiveEffects,
};

Expand Down
12 changes: 6 additions & 6 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,10 @@ export function unbatchedUpdates<A, R>(fn: (a: A) => R, a: A): R {
}
}

export function flushSync<A, R>(fn: A => R, a: A): R {
export function flushSyncWithoutWarningIfAlreadyRendering<A, R>(
fn: A => R,
a: A,
): R {
const prevExecutionContext = executionContext;
executionContext |= BatchedContext;

Expand All @@ -1141,10 +1144,7 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
}
}

export function flushSyncWithWarningIfAlreadyRendering<A, R>(
fn: A => R,
a: A,
): R {
export function flushSync<A, R>(fn: A => R, a: A): R {
if (__DEV__) {
if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
console.error(
Expand All @@ -1154,7 +1154,7 @@ export function flushSyncWithWarningIfAlreadyRendering<A, R>(
);
}
}
return flushSync(fn, a);
return flushSyncWithoutWarningIfAlreadyRendering(fn, a);
}

export function flushControlled(fn: () => mixed): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-test-renderer/src/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
getPublicRootInstance,
createContainer,
updateContainer,
flushSyncWithWarningIfAlreadyRendering,
flushSync,
injectIntoDevTools,
batchedUpdates,
} from 'react-reconciler/src/ReactFiberReconciler';
Expand Down Expand Up @@ -543,7 +543,7 @@ function create(element: React$Element<any>, options: TestRendererOptions) {
},

unstable_flushSync<T>(fn: () => T): T {
return flushSyncWithWarningIfAlreadyRendering(fn);
return flushSync(fn);
},
};

Expand Down

0 comments on commit 98d0e34

Please sign in to comment.