@samitouri / QOS-React-2 / commits / 99aa082be0

Remove unstable_flushControlled (#26397)

This API has been fully replaced by `flushSync`.

Jan Kassens committed Mar 15, 2023 at 16:13 UTC 99aa082be0a2a62fef8ed747348ddf85c5641902
8 files changed -125
packages/react-dom/index.classic.fb.js
-1
@@ -29,7 +29,6 @@ export {
29 unmountComponentAtNode,
30 unstable_batchedUpdates,
31 unstable_createEventHandle,
32 - unstable_flushControlled,
32 unstable_renderSubtreeIntoContainer,
33 unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
34 prefetchDNS,
packages/react-dom/index.js
-1
@@ -21,7 +21,6 @@ export {
21 unmountComponentAtNode,
22 unstable_batchedUpdates,
23 unstable_createEventHandle,
24 - unstable_flushControlled,
24 unstable_renderSubtreeIntoContainer,
25 unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
26 prefetchDNS,
packages/react-dom/index.modern.fb.js
-1
@@ -15,7 +15,6 @@ export {
15 flushSync,
16 unstable_batchedUpdates,
17 unstable_createEventHandle,
18 - unstable_flushControlled,
18 unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
19 prefetchDNS,
20 preconnect,
packages/react-dom/src/__tests__/ReactDOMFiberAsync-test.js
-95
@@ -306,101 +306,6 @@ describe('ReactDOMFiberAsync', () => {
306 expect(container.textContent).toEqual('ABCD');
307 });
308
309 - // @gate www
310 - it('flushControlled flushes updates before yielding to browser', async () => {
311 - let inst;
312 - class Counter extends React.Component {
313 - state = {counter: 0};
314 - increment = () =>
315 - this.setState(state => ({counter: state.counter + 1}));
316 - render() {
317 - inst = this;
318 - return this.state.counter;
319 - }
320 - }
321 - const root = ReactDOMClient.createRoot(container);
322 - await act(() => root.render(<Counter />));
323 - expect(container.textContent).toEqual('0');
324 -
325 - // Test that a normal update is async
326 - await act(() => {
327 - inst.increment();
328 - expect(container.textContent).toEqual('0');
329 - });
330 - expect(container.textContent).toEqual('1');
331 -
332 - const ops = [];
333 - ReactDOM.unstable_flushControlled(() => {
334 - inst.increment();
335 - ReactDOM.unstable_flushControlled(() => {
336 - inst.increment();
337 - ops.push('end of inner flush: ' + container.textContent);
338 - });
339 - ops.push('end of outer flush: ' + container.textContent);
340 - });
341 - ops.push('after outer flush: ' + container.textContent);
342 - expect(ops).toEqual([
343 - 'end of inner flush: 1',
344 - 'end of outer flush: 1',
345 - 'after outer flush: 3',
346 - ]);
347 - });
348 -
349 - // @gate www
350 - it('flushControlled does not flush until end of outermost batchedUpdates', () => {
351 - let inst;
352 - class Counter extends React.Component {
353 - state = {counter: 0};
354 - increment = () =>
355 - this.setState(state => ({counter: state.counter + 1}));
356 - render() {
357 - inst = this;
358 - return this.state.counter;
359 - }
360 - }
361 - ReactDOM.render(<Counter />, container);
362 -
363 - const ops = [];
364 - ReactDOM.unstable_batchedUpdates(() => {
365 - inst.increment();
366 - ReactDOM.unstable_flushControlled(() => {
367 - inst.increment();
368 - ops.push('end of flushControlled fn: ' + container.textContent);
369 - });
370 - ops.push('end of batchedUpdates fn: ' + container.textContent);
371 - });
372 - ops.push('after batchedUpdates: ' + container.textContent);
373 - expect(ops).toEqual([
374 - 'end of flushControlled fn: 0',
375 - 'end of batchedUpdates fn: 0',
376 - 'after batchedUpdates: 2',
377 - ]);
378 - });
379 -
380 - // @gate www
381 - it('flushControlled returns nothing', () => {
382 - // In the future, we may want to return a thenable "work" object.
383 - let inst;
384 - class Counter extends React.Component {
385 - state = {counter: 0};
386 - increment = () =>
387 - this.setState(state => ({counter: state.counter + 1}));
388 - render() {
389 - inst = this;
390 - return this.state.counter;
391 - }
392 - }
393 - ReactDOM.render(<Counter />, container);
394 - expect(container.textContent).toEqual('0');
395 -
396 - const returnValue = ReactDOM.unstable_flushControlled(() => {
397 - inst.increment();
398 - return 'something';
399 - });
400 - expect(container.textContent).toEqual('1');
401 - expect(returnValue).toBe(undefined);
402 - });
403 -
309 it('ignores discrete events on a pending removed element', async () => {
310 const disableButtonRef = React.createRef();
311 const submitButtonRef = React.createRef();
packages/react-dom/src/__tests__/react-dom-server-rendering-stub-test.js
-1
@@ -35,7 +35,6 @@ describe('react-dom-server-rendering-stub', () => {
35 expect(ReactDOM.unmountComponentAtNode).toBe(undefined);
36 expect(ReactDOM.unstable_batchedUpdates).toBe(undefined);
37 expect(ReactDOM.unstable_createEventHandle).toBe(undefined);
38 - expect(ReactDOM.unstable_flushControlled).toBe(undefined);
38 expect(ReactDOM.unstable_renderSubtreeIntoContainer).toBe(undefined);
39 expect(ReactDOM.unstable_runWithPriority).toBe(undefined);
40 });
packages/react-dom/src/client/ReactDOM.js
-2
@@ -36,7 +36,6 @@ import {
36 batchedUpdates,
37 flushSync as flushSyncWithoutWarningIfAlreadyRendering,
38 isAlreadyRendering,
39 - flushControlled,
39 injectIntoDevTools,
40 } from 'react-reconciler/src/ReactFiberReconciler';
41 import {runWithPriority} from 'react-reconciler/src/ReactEventPriorities';
@@ -173,7 +172,6 @@ export {
172 // exposeConcurrentModeAPIs
173 createRoot,
174 hydrateRoot,
176 - flushControlled as unstable_flushControlled,
175 // Disabled behind disableUnstableRenderSubtreeIntoContainer
176 renderSubtreeIntoContainer as unstable_renderSubtreeIntoContainer,
177 // enableCreateEventHandleAPI
packages/react-reconciler/src/ReactFiberReconciler.js
-2
@@ -64,7 +64,6 @@ import {
64 batchedUpdates,
65 flushSync,
66 isAlreadyRendering,
67 - flushControlled,
67 deferredUpdates,
68 discreteUpdates,
69 flushPassiveEffects,
@@ -392,7 +391,6 @@ export {
391 batchedUpdates,
392 deferredUpdates,
393 discreteUpdates,
395 - flushControlled,
394 flushSync,
395 isAlreadyRendering,
396 flushPassiveEffects,
packages/react-reconciler/src/ReactFiberWorkLoop.js
-22
@@ -1665,28 +1665,6 @@ export function isInvalidExecutionContextForEventFunction(): boolean {
1665 return (executionContext & RenderContext) !== NoContext;
1666 }
1667
1668 -export function flushControlled(fn: () => mixed): void {
1669 - const prevExecutionContext = executionContext;
1670 - executionContext |= BatchedContext;
1671 - const prevTransition = ReactCurrentBatchConfig.transition;
1672 - const previousPriority = getCurrentUpdatePriority();
1673 - try {
1674 - ReactCurrentBatchConfig.transition = null;
1675 - setCurrentUpdatePriority(DiscreteEventPriority);
1676 - fn();
1677 - } finally {
1678 - setCurrentUpdatePriority(previousPriority);
1679 - ReactCurrentBatchConfig.transition = prevTransition;
1680 -
1681 - executionContext = prevExecutionContext;
1682 - if (executionContext === NoContext) {
1683 - // Flush the immediate callbacks that were scheduled during this batch
1684 - resetRenderTimer();
1685 - flushSyncCallbacks();
1686 - }
1687 - }
1688 -}
1689 -
1668 // This is called by the HiddenContext module when we enter or leave a
1669 // hidden subtree. The stack logic is managed there because that's the only
1670 // place that ever modifies it. Which module it lives in doesn't matter for