Skip to content

Commit

Permalink
Remove old CM exports (#18710)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed May 5, 2020
1 parent 9751935 commit cd4a960
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 139 deletions.
2 changes: 0 additions & 2 deletions packages/react-dom/index.classic.fb.js
Expand Up @@ -30,8 +30,6 @@ export {
unmountComponentAtNode,
createRoot,
createBlockingRoot,
unstable_discreteUpdates,
unstable_flushDiscreteUpdates,
unstable_flushControlled,
unstable_scheduleHydration,
unstable_renderSubtreeIntoContainer,
Expand Down
2 changes: 0 additions & 2 deletions packages/react-dom/index.experimental.js
Expand Up @@ -21,8 +21,6 @@ export {
// exposeConcurrentModeAPIs
createRoot,
createBlockingRoot,
unstable_discreteUpdates,
unstable_flushDiscreteUpdates,
unstable_flushControlled,
unstable_scheduleHydration,
// Disabled behind disableUnstableRenderSubtreeIntoContainer
Expand Down
2 changes: 0 additions & 2 deletions packages/react-dom/index.modern.fb.js
Expand Up @@ -15,8 +15,6 @@ export {
version,
createRoot,
createBlockingRoot,
unstable_discreteUpdates,
unstable_flushDiscreteUpdates,
unstable_flushControlled,
unstable_scheduleHydration,
} from './src/client/ReactDOM';
2 changes: 0 additions & 2 deletions packages/react-dom/src/client/ReactDOM.js
Expand Up @@ -200,8 +200,6 @@ export {
// exposeConcurrentModeAPIs
createRoot,
createBlockingRoot,
discreteUpdates as unstable_discreteUpdates,
flushDiscreteUpdates as unstable_flushDiscreteUpdates,
flushControlled as unstable_flushControlled,
scheduleHydration as unstable_scheduleHydration,
// Disabled behind disableUnstableRenderSubtreeIntoContainer
Expand Down
Expand Up @@ -104,76 +104,6 @@ describe('mixing responders with the heritage event system', () => {
document.body.removeChild(newContainer);
});

// @gate experimental
it('should properly flush sync when the event systems are mixed with unstable_flushDiscreteUpdates', () => {
const useTap = require('react-interactions/events/tap').useTap;
const ref = React.createRef();
let renderCounts = 0;

function MyComponent() {
const [, updateCounter] = React.useState(0);
renderCounts++;

function handleTap() {
updateCounter(count => count + 1);
}

const listener = useTap({
onTapEnd: handleTap,
});

return (
<div>
<button
ref={ref}
DEPRECATED_flareListeners={listener}
onClick={() => {
// This should flush synchronously
ReactDOM.unstable_flushDiscreteUpdates();
updateCounter(count => count + 1);
}}>
Press me
</button>
</div>
);
}

const newContainer = document.createElement('div');
const root = ReactDOM.createRoot(newContainer);
document.body.appendChild(newContainer);
root.render(<MyComponent />);
Scheduler.unstable_flushAll();

const target = createEventTarget(ref.current);
target.pointerdown({timeStamp: 100});
target.pointerup({timeStamp: 100});

if (__DEV__) {
expect(renderCounts).toBe(4);
} else {
expect(renderCounts).toBe(2);
}
Scheduler.unstable_flushAll();
if (__DEV__) {
expect(renderCounts).toBe(6);
} else {
expect(renderCounts).toBe(3);
}

target.pointerdown({timeStamp: 100});
// Ensure the timeStamp logic works
target.pointerup({timeStamp: 101});

if (__DEV__) {
expect(renderCounts).toBe(8);
} else {
expect(renderCounts).toBe(4);
}

Scheduler.unstable_flushAll();
document.body.removeChild(newContainer);
});

// @gate experimental
it(
'should only flush before outermost discrete event handler when mixing ' +
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberHotReloading.new.js
Expand Up @@ -18,7 +18,7 @@ import {
scheduleUpdateOnFiber,
flushPassiveEffects,
} from './ReactFiberWorkLoop.new';
import {updateContainer, syncUpdates} from './ReactFiberReconciler.new';
import {updateContainer} from './ReactFiberReconciler.new';
import {emptyContextObject} from './ReactFiberContext.new';
import {SyncLane} from './ReactFiberLane';
import {
Expand Down Expand Up @@ -258,7 +258,7 @@ export const scheduleRoot: ScheduleRoot = (
return;
}
flushPassiveEffects();
syncUpdates(() => {
flushSync(() => {
updateContainer(element, root, null, null);
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberHotReloading.old.js
Expand Up @@ -18,7 +18,7 @@ import {
scheduleUpdateOnFiber,
flushPassiveEffects,
} from './ReactFiberWorkLoop.old';
import {updateContainer, syncUpdates} from './ReactFiberReconciler.old';
import {updateContainer} from './ReactFiberReconciler.old';
import {emptyContextObject} from './ReactFiberContext.old';
import {Sync} from './ReactFiberExpirationTime.old';
import {
Expand Down Expand Up @@ -258,7 +258,7 @@ export const scheduleRoot: ScheduleRoot = (
return;
}
flushPassiveEffects();
syncUpdates(() => {
flushSync(() => {
updateContainer(element, root, null, null);
});
}
Expand Down
5 changes: 0 additions & 5 deletions packages/react-reconciler/src/ReactFiberReconciler.js
Expand Up @@ -21,7 +21,6 @@ import {
batchedUpdates as batchedUpdates_old,
unbatchedUpdates as unbatchedUpdates_old,
deferredUpdates as deferredUpdates_old,
syncUpdates as syncUpdates_old,
discreteUpdates as discreteUpdates_old,
flushDiscreteUpdates as flushDiscreteUpdates_old,
flushControlled as flushControlled_old,
Expand Down Expand Up @@ -49,7 +48,6 @@ import {
batchedUpdates as batchedUpdates_new,
unbatchedUpdates as unbatchedUpdates_new,
deferredUpdates as deferredUpdates_new,
syncUpdates as syncUpdates_new,
discreteUpdates as discreteUpdates_new,
flushDiscreteUpdates as flushDiscreteUpdates_new,
flushControlled as flushControlled_new,
Expand Down Expand Up @@ -88,9 +86,6 @@ export const unbatchedUpdates = enableNewReconciler
export const deferredUpdates = enableNewReconciler
? deferredUpdates_new
: deferredUpdates_old;
export const syncUpdates = enableNewReconciler
? syncUpdates_new
: syncUpdates_old;
export const discreteUpdates = enableNewReconciler
? discreteUpdates_new
: discreteUpdates_old;
Expand Down
2 changes: 0 additions & 2 deletions packages/react-reconciler/src/ReactFiberReconciler.new.js
Expand Up @@ -56,7 +56,6 @@ import {
flushSync,
flushControlled,
deferredUpdates,
syncUpdates,
discreteUpdates,
flushDiscreteUpdates,
flushPassiveEffects,
Expand Down Expand Up @@ -306,7 +305,6 @@ export {
batchedUpdates,
unbatchedUpdates,
deferredUpdates,
syncUpdates,
discreteUpdates,
flushDiscreteUpdates,
flushControlled,
Expand Down
2 changes: 0 additions & 2 deletions packages/react-reconciler/src/ReactFiberReconciler.old.js
Expand Up @@ -56,7 +56,6 @@ import {
flushSync,
flushControlled,
deferredUpdates,
syncUpdates,
discreteUpdates,
flushDiscreteUpdates,
flushPassiveEffects,
Expand Down Expand Up @@ -308,7 +307,6 @@ export {
batchedUpdates,
unbatchedUpdates,
deferredUpdates,
syncUpdates,
discreteUpdates,
flushDiscreteUpdates,
flushControlled,
Expand Down
15 changes: 5 additions & 10 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Expand Up @@ -1008,15 +1008,6 @@ export function deferredUpdates<A>(fn: () => A): A {
return runWithPriority(NormalSchedulerPriority, fn);
}

export function syncUpdates<A, B, C, R>(
fn: (A, B, C) => R,
a: A,
b: B,
c: C,
): R {
return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a, b, c));
}

function flushPendingDiscreteUpdates() {
if (rootsWithPendingDiscreteUpdates !== null) {
// For each root with pending discrete updates, schedule a callback to
Expand Down Expand Up @@ -1113,7 +1104,11 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
}
executionContext |= BatchedContext;
try {
return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
if (fn) {
return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
} else {
return (undefined: $FlowFixMe);
}
} finally {
executionContext = prevExecutionContext;
// Flush the immediate callbacks that were scheduled during this batch.
Expand Down
15 changes: 5 additions & 10 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Expand Up @@ -1065,15 +1065,6 @@ export function deferredUpdates<A>(fn: () => A): A {
return runWithPriority(NormalPriority, fn);
}

export function syncUpdates<A, B, C, R>(
fn: (A, B, C) => R,
a: A,
b: B,
c: C,
): R {
return runWithPriority(ImmediatePriority, fn.bind(null, a, b, c));
}

function flushPendingDiscreteUpdates() {
if (rootsWithPendingDiscreteUpdates !== null) {
// For each root with pending discrete updates, schedule a callback to
Expand Down Expand Up @@ -1167,7 +1158,11 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
}
executionContext |= BatchedContext;
try {
return runWithPriority(ImmediatePriority, fn.bind(null, a));
if (fn) {
return runWithPriority(ImmediatePriority, fn.bind(null, a));
} else {
return (undefined: $FlowFixMe);
}
} finally {
executionContext = prevExecutionContext;
// Flush the immediate callbacks that were scheduled during this batch.
Expand Down
Expand Up @@ -1656,7 +1656,7 @@ describe('ReactHooksWithNoopRenderer', () => {
});
});

it('flushes passive effects when flushing discrete updates', () => {
it('does not flush non-discrete passive effects when flushing sync', () => {
let _updateCount;
function Counter(props) {
const [count, updateCount] = useState(0);
Expand All @@ -1678,28 +1678,28 @@ describe('ReactHooksWithNoopRenderer', () => {
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
}).toErrorDev(['An update to Counter ran an effect']);

// A discrete event forces the passive effect to be flushed --
// updateCount(1) happens first, so 2 wins.
ReactNoop.flushDiscreteUpdates();
ReactNoop.discreteUpdates(() => {
// (use batchedUpdates to silence the act() warning)
ReactNoop.batchedUpdates(() => {
// A flush sync doesn't cause the passive effects to fire.
// So we haven't added the other update yet.
act(() => {
ReactNoop.flushSync(() => {
_updateCount(2);
});
});
expect(Scheduler).toHaveYielded(['Will set count to 1']);
expect(() => {
expect(Scheduler).toFlushAndYield(['Count: 2']);
}).toErrorDev([
'An update to Counter ran an effect',
'An update to Counter ran an effect',

// As a result we, somewhat surprisingly, commit them in the opposite order.
// This should be fine because any non-discrete set of work doesn't guarantee order
// and easily could've happened slightly later too.
expect(Scheduler).toHaveYielded([
'Will set count to 1',
'Count: 2',
'Count: 1',
]);

expect(ReactNoop.getChildren()).toEqual([span('Count: 2')]);
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
});

// @gate enableSchedulerTracing
it('flushes passive effects when flushing discrete updates (with tracing)', () => {
it('does not flush non-discrete passive effects when flushing sync (with tracing)', () => {
const onInteractionScheduledWorkCompleted = jest.fn();
const onWorkCanceled = jest.fn();
SchedulerTracing.unstable_subscribe({
Expand Down Expand Up @@ -1744,24 +1744,20 @@ describe('ReactHooksWithNoopRenderer', () => {

expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(0);

// A discrete event forces the passive effect to be flushed --
// updateCount(1) happens first, so 2 wins.
ReactNoop.flushDiscreteUpdates();
ReactNoop.discreteUpdates(() => {
// (use batchedUpdates to silence the act() warning)
ReactNoop.batchedUpdates(() => {
// A flush sync doesn't cause the passive effects to fire.
act(() => {
ReactNoop.flushSync(() => {
_updateCount(2);
});
});
expect(Scheduler).toHaveYielded(['Will set count to 1']);
expect(() => {
expect(Scheduler).toFlushAndYield(['Count: 2']);
}).toErrorDev([
'An update to Counter ran an effect',
'An update to Counter ran an effect',

expect(Scheduler).toHaveYielded([
'Will set count to 1',
'Count: 2',
'Count: 1',
]);

expect(ReactNoop.getChildren()).toEqual([span('Count: 2')]);
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);

expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
expect(onWorkCanceled).toHaveBeenCalledTimes(0);
Expand Down

0 comments on commit cd4a960

Please sign in to comment.