Skip to content

Commit

Permalink
Clean up flushSync flow types
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Jul 15, 2021
1 parent d5de458 commit 0a21dd9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('ReactDOMFiberAsync', () => {
it('flushSync logs an error if already performing work', () => {
class Component extends React.Component {
componentDidUpdate() {
ReactDOM.flushSync(() => {});
ReactDOM.flushSync();
}
render() {
return null;
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 @@ -913,7 +913,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
}
},

flushSync(fn: () => mixed) {
flushSync<T>(fn: ?() => T): ?T {
NoopRenderer.flushSync(fn);
},

Expand Down
13 changes: 5 additions & 8 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,10 +1093,7 @@ export function discreteUpdates<A, B, C, D, R>(
}
}

export function flushSyncWithoutWarningIfAlreadyRendering<A, R>(
fn: A => R,
a: A,
): R {
export function flushSyncWithoutWarningIfAlreadyRendering<R>(fn: ?() => R): ?R {
// In legacy mode, we flush pending passive effects at the beginning of the
// next event, not at the end of the previous one.
if (
Expand All @@ -1116,9 +1113,9 @@ export function flushSyncWithoutWarningIfAlreadyRendering<A, R>(
ReactCurrentBatchConfig.transition = 0;
setCurrentUpdatePriority(DiscreteEventPriority);
if (fn) {
return fn(a);
return fn();
} else {
return (undefined: $FlowFixMe);
return undefined;
}
} finally {
setCurrentUpdatePriority(previousPriority);
Expand All @@ -1133,7 +1130,7 @@ export function flushSyncWithoutWarningIfAlreadyRendering<A, R>(
}
}

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

export function flushControlled(fn: () => mixed): void {
Expand Down
13 changes: 5 additions & 8 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,10 +1093,7 @@ export function discreteUpdates<A, B, C, D, R>(
}
}

export function flushSyncWithoutWarningIfAlreadyRendering<A, R>(
fn: A => R,
a: A,
): R {
export function flushSyncWithoutWarningIfAlreadyRendering<R>(fn: ?() => R): ?R {
// In legacy mode, we flush pending passive effects at the beginning of the
// next event, not at the end of the previous one.
if (
Expand All @@ -1116,9 +1113,9 @@ export function flushSyncWithoutWarningIfAlreadyRendering<A, R>(
ReactCurrentBatchConfig.transition = 0;
setCurrentUpdatePriority(DiscreteEventPriority);
if (fn) {
return fn(a);
return fn();
} else {
return (undefined: $FlowFixMe);
return undefined;
}
} finally {
setCurrentUpdatePriority(previousPriority);
Expand All @@ -1133,7 +1130,7 @@ export function flushSyncWithoutWarningIfAlreadyRendering<A, R>(
}
}

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

export function flushControlled(fn: () => mixed): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-test-renderer/src/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ function create(element: React$Element<any>, options: TestRendererOptions) {
return getPublicRootInstance(root);
},

unstable_flushSync<T>(fn: () => T): T {
unstable_flushSync<R>(fn: ?() => R): ?R {
return flushSync(fn);
},
};
Expand Down

0 comments on commit 0a21dd9

Please sign in to comment.