Skip to content

Commit 860f673

Browse files
authored
Remove Blocking Mode (again) (#20974)
* Remove Blocking Mode (again) * Rename batchingmode file and comment
1 parent acde654 commit 860f673

36 files changed

+121
-332
lines changed

packages/react-dom/index.classic.fb.js

-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ export {
3030
unmountComponentAtNode,
3131
createRoot,
3232
createRoot as unstable_createRoot,
33-
createBlockingRoot,
34-
createBlockingRoot as unstable_createBlockingRoot,
3533
unstable_flushControlled,
3634
unstable_scheduleHydration,
3735
unstable_runWithPriority,

packages/react-dom/index.experimental.js

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export {
2020
unmountComponentAtNode,
2121
// exposeConcurrentModeAPIs
2222
createRoot as unstable_createRoot,
23-
createBlockingRoot as unstable_createBlockingRoot,
2423
unstable_flushControlled,
2524
unstable_scheduleHydration,
2625
// DO NOT USE: Temporarily exposing this to migrate off of Scheduler.runWithPriority.

packages/react-dom/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ export {
2121
unmountComponentAtNode,
2222
createRoot,
2323
createRoot as unstable_createRoot,
24-
createBlockingRoot,
25-
createBlockingRoot as unstable_createBlockingRoot,
2624
unstable_flushControlled,
2725
unstable_scheduleHydration,
2826
unstable_runWithPriority,

packages/react-dom/index.modern.fb.js

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export {
1515
version,
1616
createRoot,
1717
createRoot as unstable_createRoot,
18-
createBlockingRoot,
19-
createBlockingRoot as unstable_createBlockingRoot,
2018
unstable_flushControlled,
2119
unstable_scheduleHydration,
2220
unstable_runWithPriority,

packages/react-dom/src/__tests__/ReactDOMFiberAsync-test.js

+19-21
Original file line numberDiff line numberDiff line change
@@ -574,31 +574,29 @@ describe('ReactDOMFiberAsync', () => {
574574
expect(containerC.textContent).toEqual('Finished');
575575
});
576576

577-
describe('createBlockingRoot', () => {
578-
// @gate experimental
579-
it('updates flush without yielding in the next event', () => {
580-
const root = ReactDOM.unstable_createBlockingRoot(container);
577+
// @gate experimental
578+
it('updates flush without yielding in the next event', () => {
579+
const root = ReactDOM.unstable_createRoot(container);
581580

582-
function Text(props) {
583-
Scheduler.unstable_yieldValue(props.text);
584-
return props.text;
585-
}
581+
function Text(props) {
582+
Scheduler.unstable_yieldValue(props.text);
583+
return props.text;
584+
}
586585

587-
root.render(
588-
<>
589-
<Text text="A" />
590-
<Text text="B" />
591-
<Text text="C" />
592-
</>,
593-
);
586+
root.render(
587+
<>
588+
<Text text="A" />
589+
<Text text="B" />
590+
<Text text="C" />
591+
</>,
592+
);
594593

595-
// Nothing should have rendered yet
596-
expect(container.textContent).toEqual('');
594+
// Nothing should have rendered yet
595+
expect(container.textContent).toEqual('');
597596

598-
// Everything should render immediately in the next event
599-
expect(Scheduler).toFlushExpired(['A', 'B', 'C']);
600-
expect(container.textContent).toEqual('ABC');
601-
});
597+
// Everything should render immediately in the next event
598+
expect(Scheduler).toFlushAndYield(['A', 'B', 'C']);
599+
expect(container.textContent).toEqual('ABC');
602600
});
603601

604602
// @gate experimental

packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ describe('ReactDOMServerPartialHydration', () => {
357357
}).toErrorDev(
358358
'Warning: Cannot hydrate Suspense in legacy mode. Switch from ' +
359359
'ReactDOM.hydrate(element, container) to ' +
360-
'ReactDOM.createBlockingRoot(container, { hydrate: true })' +
360+
'ReactDOM.createRoot(container, { hydrate: true })' +
361361
'.render(element) or remove the Suspense components from the server ' +
362362
'rendered components.' +
363363
'\n in Suspense (at **)' +

packages/react-dom/src/__tests__/ReactDOMServerSuspense-test.internal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('ReactDOMServerSuspense', () => {
127127
expect(divB.textContent).toBe('B');
128128

129129
act(() => {
130-
const root = ReactDOM.createBlockingRoot(parent, {hydrate: true});
130+
const root = ReactDOM.createRoot(parent, {hydrate: true});
131131
root.render(example);
132132
});
133133

packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js

+6-52
Original file line numberDiff line numberDiff line change
@@ -72,33 +72,6 @@ describe('ReactTestUtils.act()', () => {
7272

7373
runActTests('legacy mode', renderLegacy, unmountLegacy, rerenderLegacy);
7474

75-
// and then in blocking mode
76-
if (__EXPERIMENTAL__) {
77-
let blockingRoot = null;
78-
const renderBatched = (el, dom) => {
79-
blockingRoot = ReactDOM.unstable_createBlockingRoot(dom);
80-
blockingRoot.render(el);
81-
};
82-
83-
const unmountBatched = dom => {
84-
if (blockingRoot !== null) {
85-
blockingRoot.unmount();
86-
blockingRoot = null;
87-
}
88-
};
89-
90-
const rerenderBatched = el => {
91-
blockingRoot.render(el);
92-
};
93-
94-
runActTests(
95-
'blocking mode',
96-
renderBatched,
97-
unmountBatched,
98-
rerenderBatched,
99-
);
100-
}
101-
10275
describe('unacted effects', () => {
10376
function App() {
10477
React.useEffect(() => {}, []);
@@ -124,19 +97,6 @@ describe('ReactTestUtils.act()', () => {
12497
]);
12598
});
12699

127-
// @gate experimental
128-
it('warns in blocking mode', () => {
129-
expect(() => {
130-
const root = ReactDOM.unstable_createBlockingRoot(
131-
document.createElement('div'),
132-
);
133-
root.render(<App />);
134-
Scheduler.unstable_flushAll();
135-
}).toErrorDev([
136-
'An update to App ran an effect, but was not wrapped in act(...)',
137-
]);
138-
});
139-
140100
// @gate experimental
141101
it('warns in concurrent mode', () => {
142102
expect(() => {
@@ -731,14 +691,10 @@ function runActTests(label, render, unmount, rerender) {
731691

732692
it('triggers fallbacks if available', async () => {
733693
if (label !== 'legacy mode') {
734-
// FIXME: Support for Blocking* and Concurrent Mode were
735-
// intentionally removed from the public version of `act`. It will
736-
// be added back in a future major version, before Blocking and and
737-
// Concurrent Mode are officially released. Consider disabling all
738-
// non-Legacy tests in this suite until then.
739-
//
740-
// *Blocking Mode actually does happen to work, though
741-
// not "officially" since it's an unreleased feature.
694+
// FIXME: Support for Concurrent Root intentionally removed
695+
// from the public version of `act`. It will be added back in
696+
// a future major version, before the Concurrent Root is released.
697+
// Consider skipping all non-Legacy tests in this suite until then.
742698
return;
743699
}
744700

@@ -794,10 +750,8 @@ function runActTests(label, render, unmount, rerender) {
794750
// In Concurrent Mode, refresh transitions delay indefinitely.
795751
expect(document.querySelector('[data-test-id=spinner]')).toBeNull();
796752
} else {
797-
// In Legacy Mode and Blocking Mode, all fallbacks are forced to
798-
// display, even during a refresh transition.
799-
// TODO: Consider delaying indefinitely in Blocking Mode, to match
800-
// Concurrent Mode semantics.
753+
// In Legacy Mode, all fallbacks are forced to display,
754+
// even during a refresh transition.
801755
expect(
802756
document.querySelector('[data-test-id=spinner]'),
803757
).not.toBeNull();

packages/react-dom/src/__tests__/ReactUnmockedSchedulerWarning-test.js

-19
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,3 @@ it('should warn when rendering in concurrent mode', () => {
4343
ReactDOM.unstable_createRoot(document.createElement('div')).render(<App />);
4444
}).toErrorDev([]);
4545
});
46-
47-
// @gate experimental
48-
it('should warn when rendering in blocking mode', () => {
49-
expect(() => {
50-
ReactDOM.unstable_createBlockingRoot(document.createElement('div')).render(
51-
<App />,
52-
);
53-
}).toErrorDev(
54-
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
55-
'to guarantee consistent behaviour across tests and browsers.',
56-
{withoutStack: true},
57-
);
58-
// does not warn twice
59-
expect(() => {
60-
ReactDOM.unstable_createBlockingRoot(document.createElement('div')).render(
61-
<App />,
62-
);
63-
}).toErrorDev([]);
64-
});

packages/react-dom/src/client/ReactDOM.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
unstable_renderSubtreeIntoContainer,
1919
unmountComponentAtNode,
2020
} from './ReactDOMLegacy';
21-
import {createRoot, createBlockingRoot, isValidContainer} from './ReactDOMRoot';
21+
import {createRoot, isValidContainer} from './ReactDOMRoot';
2222
import {createEventHandle} from './ReactDOMEventHandle';
2323

2424
import {
@@ -201,7 +201,6 @@ export {
201201
unmountComponentAtNode,
202202
// exposeConcurrentModeAPIs
203203
createRoot,
204-
createBlockingRoot,
205204
flushControlled as unstable_flushControlled,
206205
scheduleHydration as unstable_scheduleHydration,
207206
// Disabled behind disableUnstableRenderSubtreeIntoContainer

packages/react-dom/src/client/ReactDOMRoot.js

+6-26
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,17 @@ import {
5151
registerMutableSourceForHydration,
5252
} from 'react-reconciler/src/ReactFiberReconciler';
5353
import invariant from 'shared/invariant';
54-
import {
55-
BlockingRoot,
56-
ConcurrentRoot,
57-
LegacyRoot,
58-
} from 'react-reconciler/src/ReactRootTags';
54+
import {ConcurrentRoot, LegacyRoot} from 'react-reconciler/src/ReactRootTags';
5955

6056
function ReactDOMRoot(container: Container, options: void | RootOptions) {
6157
this._internalRoot = createRootImpl(container, ConcurrentRoot, options);
6258
}
6359

64-
function ReactDOMBlockingRoot(
65-
container: Container,
66-
tag: RootTag,
67-
options: void | RootOptions,
68-
) {
69-
this._internalRoot = createRootImpl(container, tag, options);
60+
function ReactDOMLegacyRoot(container: Container, options: void | RootOptions) {
61+
this._internalRoot = createRootImpl(container, LegacyRoot, options);
7062
}
7163

72-
ReactDOMRoot.prototype.render = ReactDOMBlockingRoot.prototype.render = function(
64+
ReactDOMRoot.prototype.render = ReactDOMLegacyRoot.prototype.render = function(
7365
children: ReactNodeList,
7466
): void {
7567
const root = this._internalRoot;
@@ -99,7 +91,7 @@ ReactDOMRoot.prototype.render = ReactDOMBlockingRoot.prototype.render = function
9991
updateContainer(children, root, null, null);
10092
};
10193

102-
ReactDOMRoot.prototype.unmount = ReactDOMBlockingRoot.prototype.unmount = function(): void {
94+
ReactDOMRoot.prototype.unmount = ReactDOMLegacyRoot.prototype.unmount = function(): void {
10395
if (__DEV__) {
10496
if (typeof arguments[0] === 'function') {
10597
console.error(
@@ -169,23 +161,11 @@ export function createRoot(
169161
return new ReactDOMRoot(container, options);
170162
}
171163

172-
export function createBlockingRoot(
173-
container: Container,
174-
options?: RootOptions,
175-
): RootType {
176-
invariant(
177-
isValidContainer(container),
178-
'createRoot(...): Target container is not a DOM element.',
179-
);
180-
warnIfReactDOMContainerInDEV(container);
181-
return new ReactDOMBlockingRoot(container, BlockingRoot, options);
182-
}
183-
184164
export function createLegacyRoot(
185165
container: Container,
186166
options?: RootOptions,
187167
): RootType {
188-
return new ReactDOMBlockingRoot(container, LegacyRoot, options);
168+
return new ReactDOMLegacyRoot(container, options);
189169
}
190170

191171
export function isValidContainer(node: mixed): boolean {

packages/react-noop-renderer/src/ReactNoop.js

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export const {
2323
getPendingChildren,
2424
getOrCreateRootContainer,
2525
createRoot,
26-
createBlockingRoot,
2726
createLegacyRoot,
2827
getChildrenAsJSX,
2928
getPendingChildrenAsJSX,

packages/react-noop-renderer/src/ReactNoopPersistent.js

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export const {
2323
getPendingChildren,
2424
getOrCreateRootContainer,
2525
createRoot,
26-
createBlockingRoot,
2726
createLegacyRoot,
2827
getChildrenAsJSX,
2928
getPendingChildrenAsJSX,

packages/react-noop-renderer/src/createReactNoop.js

+1-32
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ import type {RootTag} from 'react-reconciler/src/ReactRootTags';
2121

2222
import * as Scheduler from 'scheduler/unstable_mock';
2323
import {REACT_FRAGMENT_TYPE, REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
24-
import {
25-
ConcurrentRoot,
26-
BlockingRoot,
27-
LegacyRoot,
28-
} from 'react-reconciler/src/ReactRootTags';
24+
import {ConcurrentRoot, LegacyRoot} from 'react-reconciler/src/ReactRootTags';
2925

3026
import ReactSharedInternals from 'shared/ReactSharedInternals';
3127
import enqueueTask from 'shared/enqueueTask';
@@ -752,33 +748,6 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
752748
};
753749
},
754750

755-
createBlockingRoot() {
756-
const container = {
757-
rootID: '' + idCounter++,
758-
pendingChildren: [],
759-
children: [],
760-
};
761-
const fiberRoot = NoopRenderer.createContainer(
762-
container,
763-
BlockingRoot,
764-
false,
765-
null,
766-
null,
767-
);
768-
return {
769-
_Scheduler: Scheduler,
770-
render(children: ReactNodeList) {
771-
NoopRenderer.updateContainer(children, fiberRoot, null, null);
772-
},
773-
getChildren() {
774-
return getChildren(container);
775-
},
776-
getChildrenAsJSX() {
777-
return getChildrenAsJSX(container);
778-
},
779-
};
780-
},
781-
782751
createLegacyRoot() {
783752
const container = {
784753
rootID: '' + idCounter++,

0 commit comments

Comments
 (0)