Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unstable_flushControlled #26397

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/react-dom/index.classic.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/react-dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/react-dom/index.modern.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
95 changes: 0 additions & 95 deletions packages/react-dom/src/__tests__/ReactDOMFiberAsync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 0 additions & 2 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
batchedUpdates,
flushSync as flushSyncWithoutWarningIfAlreadyRendering,
isAlreadyRendering,
flushControlled,
injectIntoDevTools,
} from 'react-reconciler/src/ReactFiberReconciler';
import {runWithPriority} from 'react-reconciler/src/ReactEventPriorities';
Expand Down Expand Up @@ -173,7 +172,6 @@ export {
// exposeConcurrentModeAPIs
createRoot,
hydrateRoot,
flushControlled as unstable_flushControlled,
// Disabled behind disableUnstableRenderSubtreeIntoContainer
renderSubtreeIntoContainer as unstable_renderSubtreeIntoContainer,
// enableCreateEventHandleAPI
Expand Down
2 changes: 0 additions & 2 deletions packages/react-reconciler/src/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import {
batchedUpdates,
flushSync,
isAlreadyRendering,
flushControlled,
deferredUpdates,
discreteUpdates,
flushPassiveEffects,
Expand Down Expand Up @@ -392,7 +391,6 @@ export {
batchedUpdates,
deferredUpdates,
discreteUpdates,
flushControlled,
flushSync,
isAlreadyRendering,
flushPassiveEffects,
Expand Down
22 changes: 0 additions & 22 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down