Remove unstable_flushControlled (#26397)

This API has been fully replaced by `flushSync`.
This commit is contained in:
Jan Kassens
2023-03-15 16:13:54 -04:00
committed by GitHub
parent 47cf4e578c
commit 99aa082be0
8 changed files with 0 additions and 125 deletions
-1
View File
@@ -29,7 +29,6 @@ export {
unmountComponentAtNode,
unstable_batchedUpdates,
unstable_createEventHandle,
unstable_flushControlled,
unstable_renderSubtreeIntoContainer,
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
prefetchDNS,
-1
View File
@@ -21,7 +21,6 @@ export {
unmountComponentAtNode,
unstable_batchedUpdates,
unstable_createEventHandle,
unstable_flushControlled,
unstable_renderSubtreeIntoContainer,
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
prefetchDNS,
-1
View File
@@ -15,7 +15,6 @@ export {
flushSync,
unstable_batchedUpdates,
unstable_createEventHandle,
unstable_flushControlled,
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
prefetchDNS,
preconnect,
@@ -306,101 +306,6 @@ describe('ReactDOMFiberAsync', () => {
expect(container.textContent).toEqual('ABCD');
});
// @gate www
it('flushControlled flushes updates before yielding to browser', async () => {
let inst;
class Counter extends React.Component {
state = {counter: 0};
increment = () =>
this.setState(state => ({counter: state.counter + 1}));
render() {
inst = this;
return this.state.counter;
}
}
const root = ReactDOMClient.createRoot(container);
await act(() => root.render(<Counter />));
expect(container.textContent).toEqual('0');
// Test that a normal update is async
await act(() => {
inst.increment();
expect(container.textContent).toEqual('0');
});
expect(container.textContent).toEqual('1');
const ops = [];
ReactDOM.unstable_flushControlled(() => {
inst.increment();
ReactDOM.unstable_flushControlled(() => {
inst.increment();
ops.push('end of inner flush: ' + container.textContent);
});
ops.push('end of outer flush: ' + container.textContent);
});
ops.push('after outer flush: ' + container.textContent);
expect(ops).toEqual([
'end of inner flush: 1',
'end of outer flush: 1',
'after outer flush: 3',
]);
});
// @gate www
it('flushControlled does not flush until end of outermost batchedUpdates', () => {
let inst;
class Counter extends React.Component {
state = {counter: 0};
increment = () =>
this.setState(state => ({counter: state.counter + 1}));
render() {
inst = this;
return this.state.counter;
}
}
ReactDOM.render(<Counter />, container);
const ops = [];
ReactDOM.unstable_batchedUpdates(() => {
inst.increment();
ReactDOM.unstable_flushControlled(() => {
inst.increment();
ops.push('end of flushControlled fn: ' + container.textContent);
});
ops.push('end of batchedUpdates fn: ' + container.textContent);
});
ops.push('after batchedUpdates: ' + container.textContent);
expect(ops).toEqual([
'end of flushControlled fn: 0',
'end of batchedUpdates fn: 0',
'after batchedUpdates: 2',
]);
});
// @gate www
it('flushControlled returns nothing', () => {
// In the future, we may want to return a thenable "work" object.
let inst;
class Counter extends React.Component {
state = {counter: 0};
increment = () =>
this.setState(state => ({counter: state.counter + 1}));
render() {
inst = this;
return this.state.counter;
}
}
ReactDOM.render(<Counter />, container);
expect(container.textContent).toEqual('0');
const returnValue = ReactDOM.unstable_flushControlled(() => {
inst.increment();
return 'something';
});
expect(container.textContent).toEqual('1');
expect(returnValue).toBe(undefined);
});
it('ignores discrete events on a pending removed element', async () => {
const disableButtonRef = React.createRef();
const submitButtonRef = React.createRef();
@@ -35,7 +35,6 @@ describe('react-dom-server-rendering-stub', () => {
expect(ReactDOM.unmountComponentAtNode).toBe(undefined);
expect(ReactDOM.unstable_batchedUpdates).toBe(undefined);
expect(ReactDOM.unstable_createEventHandle).toBe(undefined);
expect(ReactDOM.unstable_flushControlled).toBe(undefined);
expect(ReactDOM.unstable_renderSubtreeIntoContainer).toBe(undefined);
expect(ReactDOM.unstable_runWithPriority).toBe(undefined);
});
-2
View File
@@ -36,7 +36,6 @@ import {
batchedUpdates,
flushSync as flushSyncWithoutWarningIfAlreadyRendering,
isAlreadyRendering,
flushControlled,
injectIntoDevTools,
} from 'react-reconciler/src/ReactFiberReconciler';
import {runWithPriority} from 'react-reconciler/src/ReactEventPriorities';
@@ -173,7 +172,6 @@ export {
// exposeConcurrentModeAPIs
createRoot,
hydrateRoot,
flushControlled as unstable_flushControlled,
// Disabled behind disableUnstableRenderSubtreeIntoContainer
renderSubtreeIntoContainer as unstable_renderSubtreeIntoContainer,
// enableCreateEventHandleAPI
-2
View File
@@ -64,7 +64,6 @@ import {
batchedUpdates,
flushSync,
isAlreadyRendering,
flushControlled,
deferredUpdates,
discreteUpdates,
flushPassiveEffects,
@@ -392,7 +391,6 @@ export {
batchedUpdates,
deferredUpdates,
discreteUpdates,
flushControlled,
flushSync,
isAlreadyRendering,
flushPassiveEffects,
-22
View File
@@ -1665,28 +1665,6 @@ export function isInvalidExecutionContextForEventFunction(): boolean {
return (executionContext & RenderContext) !== NoContext;
}
export function flushControlled(fn: () => mixed): void {
const prevExecutionContext = executionContext;
executionContext |= BatchedContext;
const prevTransition = ReactCurrentBatchConfig.transition;
const previousPriority = getCurrentUpdatePriority();
try {
ReactCurrentBatchConfig.transition = null;
setCurrentUpdatePriority(DiscreteEventPriority);
fn();
} finally {
setCurrentUpdatePriority(previousPriority);
ReactCurrentBatchConfig.transition = prevTransition;
executionContext = prevExecutionContext;
if (executionContext === NoContext) {
// Flush the immediate callbacks that were scheduled during this batch
resetRenderTimer();
flushSyncCallbacks();
}
}
}
// This is called by the HiddenContext module when we enter or leave a
// hidden subtree. The stack logic is managed there because that's the only
// place that ever modifies it. Which module it lives in doesn't matter for