@@ -131,7 +153,7 @@ describe('ReactDOMRoot', () => {
const container2 = document.createElement('div');
container2.innerHTML = markup;
- ReactDOM.hydrateRoot(
+ ReactDOMClient.hydrateRoot(
container2,
@@ -163,7 +185,7 @@ describe('ReactDOMRoot', () => {
it('clears existing children', async () => {
container.innerHTML = '
a
b
';
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render(
c
@@ -184,12 +206,12 @@ describe('ReactDOMRoot', () => {
it('throws a good message on invalid containers', () => {
expect(() => {
- ReactDOM.createRoot(
Hi
);
+ ReactDOMClient.createRoot(
Hi
);
}).toThrow('createRoot(...): Target container is not a DOM element.');
});
it('warns when rendering with legacy API into createRoot() container', () => {
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render(
Hi
);
Scheduler.unstable_flushAll();
expect(container.textContent).toEqual('Hi');
@@ -199,7 +221,7 @@ describe('ReactDOMRoot', () => {
[
// We care about this warning:
'You are calling ReactDOM.render() on a container that was previously ' +
- 'passed to ReactDOM.createRoot(). This is not supported. ' +
+ 'passed to ReactDOMClient.createRoot(). This is not supported. ' +
'Did you mean to call root.render(element)?',
// This is more of a symptom but restructuring the code to avoid it isn't worth it:
'Replacing React-rendered children with a new root component.',
@@ -212,7 +234,7 @@ describe('ReactDOMRoot', () => {
});
it('warns when hydrating with legacy API into createRoot() container', () => {
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render(
Hi
);
Scheduler.unstable_flushAll();
expect(container.textContent).toEqual('Hi');
@@ -222,7 +244,7 @@ describe('ReactDOMRoot', () => {
[
// We care about this warning:
'You are calling ReactDOM.hydrate() on a container that was previously ' +
- 'passed to ReactDOM.createRoot(). This is not supported. ' +
+ 'passed to ReactDOMClient.createRoot(). This is not supported. ' +
'Did you mean to call hydrateRoot(container, element)?',
// This is more of a symptom but restructuring the code to avoid it isn't worth it:
'Replacing React-rendered children with a new root component.',
@@ -232,7 +254,7 @@ describe('ReactDOMRoot', () => {
});
it('warns when unmounting with legacy API (no previous content)', () => {
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render(
Hi
);
Scheduler.unstable_flushAll();
expect(container.textContent).toEqual('Hi');
@@ -243,7 +265,7 @@ describe('ReactDOMRoot', () => {
[
// We care about this warning:
'You are calling ReactDOM.unmountComponentAtNode() on a container that was previously ' +
- 'passed to ReactDOM.createRoot(). This is not supported. Did you mean to call root.unmount()?',
+ 'passed to ReactDOMClient.createRoot(). This is not supported. Did you mean to call root.unmount()?',
// This is more of a symptom but restructuring the code to avoid it isn't worth it:
"The node you're attempting to unmount was rendered by React and is not a top-level container.",
],
@@ -261,7 +283,7 @@ describe('ReactDOMRoot', () => {
// Currently createRoot().render() doesn't clear this.
container.appendChild(document.createElement('div'));
// The rest is the same as test above.
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render(
Hi
);
Scheduler.unstable_flushAll();
expect(container.textContent).toEqual('Hi');
@@ -287,20 +309,20 @@ describe('ReactDOMRoot', () => {
it('warns when passing legacy container to createRoot()', () => {
ReactDOM.render(
Hi
, container);
expect(() => {
- ReactDOM.createRoot(container);
+ ReactDOMClient.createRoot(container);
}).toErrorDev(
- 'You are calling ReactDOM.createRoot() on a container that was previously ' +
+ 'You are calling ReactDOMClient.createRoot() on a container that was previously ' +
'passed to ReactDOM.render(). This is not supported.',
{withoutStack: true},
);
});
it('warns when creating two roots managing the same container', () => {
- ReactDOM.createRoot(container);
+ ReactDOMClient.createRoot(container);
expect(() => {
- ReactDOM.createRoot(container);
+ ReactDOMClient.createRoot(container);
}).toErrorDev(
- 'You are calling ReactDOM.createRoot() on a container that ' +
+ 'You are calling ReactDOMClient.createRoot() on a container that ' +
'has already been passed to createRoot() before. Instead, call ' +
'root.render() on the existing root instead if you want to update it.',
{withoutStack: true},
@@ -308,15 +330,15 @@ describe('ReactDOMRoot', () => {
});
it('does not warn when creating second root after first one is unmounted', () => {
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.unmount();
Scheduler.unstable_flushAll();
- ReactDOM.createRoot(container); // No warning
+ ReactDOMClient.createRoot(container); // No warning
});
it('warns if creating a root on the document.body', async () => {
expect(() => {
- ReactDOM.createRoot(document.body);
+ ReactDOMClient.createRoot(document.body);
}).toErrorDev(
'createRoot(): Creating roots directly with document.body is ' +
'discouraged, since its children are often manipulated by third-party ' +
@@ -328,7 +350,7 @@ describe('ReactDOMRoot', () => {
});
it('warns if updating a root that has had its contents removed', async () => {
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render(
Hi
);
Scheduler.unstable_flushAll();
container.innerHTML = '';
@@ -345,7 +367,7 @@ describe('ReactDOMRoot', () => {
});
it('opts-in to concurrent default updates', async () => {
- const root = ReactDOM.createRoot(container, {
+ const root = ReactDOMClient.createRoot(container, {
unstable_concurrentUpdatesByDefault: true,
});
@@ -377,7 +399,7 @@ describe('ReactDOMRoot', () => {
});
it('unmount is synchronous', async () => {
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
await act(async () => {
root.render('Hi');
});
@@ -391,7 +413,7 @@ describe('ReactDOMRoot', () => {
});
it('throws if an unmounted root is updated', async () => {
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
await act(async () => {
root.render('Hi');
});
@@ -406,9 +428,9 @@ describe('ReactDOMRoot', () => {
it('warns if root is unmounted inside an effect', async () => {
const container1 = document.createElement('div');
- const root1 = ReactDOM.createRoot(container1);
+ const root1 = ReactDOMClient.createRoot(container1);
const container2 = document.createElement('div');
- const root2 = ReactDOM.createRoot(container2);
+ const root2 = ReactDOMClient.createRoot(container2);
function App({step}) {
useEffect(() => {
@@ -441,10 +463,10 @@ describe('ReactDOMRoot', () => {
div.innerHTML = '';
const commentNode = div.childNodes[0];
- expect(() => ReactDOM.createRoot(commentNode)).toThrow(
+ expect(() => ReactDOMClient.createRoot(commentNode)).toThrow(
'createRoot(...): Target container is not a DOM element.',
);
- expect(() => ReactDOM.hydrateRoot(commentNode)).toThrow(
+ expect(() => ReactDOMClient.hydrateRoot(commentNode)).toThrow(
'hydrateRoot(...): Target container is not a DOM element.',
);
@@ -454,7 +476,7 @@ describe('ReactDOMRoot', () => {
it('warn if no children passed to hydrateRoot', async () => {
expect(() =>
- ReactDOM.hydrateRoot(container),
+ ReactDOMClient.hydrateRoot(container),
).toErrorDev(
'Must provide initial children as second argument to hydrateRoot.',
{withoutStack: true},
@@ -466,7 +488,7 @@ describe('ReactDOMRoot', () => {
return 'Child';
}
- expect(() => ReactDOM.createRoot(container,
)).toErrorDev(
+ expect(() => ReactDOMClient.createRoot(container,
)).toErrorDev(
'You passed a JSX element to createRoot. You probably meant to call ' +
'root.render instead',
{
diff --git a/packages/react-dom/src/__tests__/ReactDOMSafariMicrotaskBug-test.js b/packages/react-dom/src/__tests__/ReactDOMSafariMicrotaskBug-test.js
index 1e12bb611ca78..0ba0848d8e3cd 100644
--- a/packages/react-dom/src/__tests__/ReactDOMSafariMicrotaskBug-test.js
+++ b/packages/react-dom/src/__tests__/ReactDOMSafariMicrotaskBug-test.js
@@ -11,7 +11,7 @@
let React;
-let ReactDOM;
+let ReactDOMClient;
let act;
describe('ReactDOMSafariMicrotaskBug-test', () => {
@@ -35,7 +35,7 @@ describe('ReactDOMSafariMicrotaskBug-test', () => {
jest.resetModules();
container = document.createElement('div');
React = require('react');
- ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
act = require('jest-react').act;
document.body.appendChild(container);
@@ -62,7 +62,7 @@ describe('ReactDOMSafariMicrotaskBug-test', () => {
);
}
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
await act(async () => {
root.render(
);
});
diff --git a/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js
index f19c38bc38cd5..7e25788c9232d 100644
--- a/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js
+++ b/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js
@@ -11,6 +11,7 @@
let React = require('react');
let ReactDOM;
+let ReactDOMClient;
let ReactDOMServer;
let Scheduler;
let ReactFeatureFlags;
@@ -100,6 +101,7 @@ describe('ReactDOMServerPartialHydration', () => {
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
act = require('jest-react').act;
ReactDOMServer = require('react-dom/server');
Scheduler = require('scheduler');
@@ -164,7 +166,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(container,
);
Scheduler.unstable_flushAll();
jest.runAllTimers();
@@ -217,7 +219,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- ReactDOM.hydrateRoot(container,
, {
+ ReactDOMClient.hydrateRoot(container,
, {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(error.message);
},
@@ -310,7 +312,7 @@ describe('ReactDOMServerPartialHydration', () => {
suspend = true;
client = true;
- ReactDOM.hydrateRoot(container,
, {
+ ReactDOMClient.hydrateRoot(container,
, {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(error.message);
},
@@ -426,7 +428,7 @@ describe('ReactDOMServerPartialHydration', () => {
// hydrating anyway.
suspend = true;
suspend2 = true;
- const root = ReactDOM.hydrateRoot(container,
, {
+ const root = ReactDOMClient.hydrateRoot(container,
, {
onHydrated(node) {
hydrated.push(node);
},
@@ -483,7 +485,7 @@ describe('ReactDOMServerPartialHydration', () => {
const container = document.createElement('div');
container.innerHTML = finalHTML;
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(container,
);
Scheduler.unstable_flushAll();
jest.runAllTimers();
@@ -517,7 +519,7 @@ describe('ReactDOMServerPartialHydration', () => {
expect(() => {
act(() => {
- ReactDOM.hydrateRoot(container,
, {
+ ReactDOMClient.hydrateRoot(container,
, {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(error.message);
},
@@ -590,7 +592,7 @@ describe('ReactDOMServerPartialHydration', () => {
shouldSuspend = true;
act(() => {
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(container,
);
});
resolve();
@@ -651,7 +653,7 @@ describe('ReactDOMServerPartialHydration', () => {
expect(() => {
act(() => {
- ReactDOM.hydrateRoot(container,
, {
+ ReactDOMClient.hydrateRoot(container,
, {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(error.message);
},
@@ -709,7 +711,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- const root = ReactDOM.hydrateRoot(container,
, {
+ const root = ReactDOMClient.hydrateRoot(container,
, {
onDeleted(node) {
deleted.push(node);
},
@@ -770,7 +772,7 @@ describe('ReactDOMServerPartialHydration', () => {
}).toErrorDev(
'Warning: Cannot hydrate Suspense in legacy mode. Switch from ' +
'ReactDOM.hydrate(element, container) to ' +
- 'ReactDOM.hydrateRoot(container,
)' +
+ 'ReactDOMClient.hydrateRoot(container,
)' +
'.render(element) or remove the Suspense components from the server ' +
'rendered components.' +
'\n in Suspense (at **)' +
@@ -850,7 +852,7 @@ describe('ReactDOMServerPartialHydration', () => {
suspend = true;
act(() => {
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(container,
);
});
expect(container.firstChild.firstChild.tagName).not.toBe('DIV');
@@ -906,7 +908,7 @@ describe('ReactDOMServerPartialHydration', () => {
// hydrating anyway.
suspend = true;
act(() => {
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(container,
);
});
expect(container.firstChild.children[1].textContent).toBe('Middle');
@@ -955,7 +957,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- const root = ReactDOM.hydrateRoot(
+ const root = ReactDOMClient.hydrateRoot(
container,
,
);
@@ -1029,7 +1031,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- const root = ReactDOM.hydrateRoot(
+ const root = ReactDOMClient.hydrateRoot(
container,
,
);
@@ -1102,7 +1104,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- const root = ReactDOM.hydrateRoot(
+ const root = ReactDOMClient.hydrateRoot(
container,
,
{
@@ -1188,7 +1190,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- const root = ReactDOM.hydrateRoot(
+ const root = ReactDOMClient.hydrateRoot(
container,
,
{
@@ -1273,7 +1275,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- const root = ReactDOM.hydrateRoot(
+ const root = ReactDOMClient.hydrateRoot(
container,
,
{
@@ -1357,7 +1359,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- const root = ReactDOM.hydrateRoot(
+ const root = ReactDOMClient.hydrateRoot(
container,
,
);
@@ -1439,7 +1441,10 @@ describe('ReactDOMServerPartialHydration', () => {
const container = document.createElement('div');
container.innerHTML = finalHTML;
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(
+ container,
+
,
+ );
await act(async () => {
suspend = true;
@@ -1509,7 +1514,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- const root = ReactDOM.hydrateRoot(
+ const root = ReactDOMClient.hydrateRoot(
container,
@@ -1591,7 +1596,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- const root = ReactDOM.hydrateRoot(
+ const root = ReactDOMClient.hydrateRoot(
container,
@@ -1680,7 +1685,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we have the data available quickly for some reason.
suspend = false;
- ReactDOM.hydrateRoot(container, , {
+ ReactDOMClient.hydrateRoot(container, , {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(error.message);
},
@@ -1742,7 +1747,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we have the data available quickly for some reason.
suspend = false;
- ReactDOM.hydrateRoot(container, , {
+ ReactDOMClient.hydrateRoot(container, , {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(error.message);
},
@@ -1809,7 +1814,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we have the data available quickly for some reason.
suspend = false;
- ReactDOM.hydrateRoot(container, , {
+ ReactDOMClient.hydrateRoot(container, , {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(error.message);
},
@@ -1882,7 +1887,10 @@ describe('ReactDOMServerPartialHydration', () => {
const spanB = container.getElementsByTagName('span')[1];
- const root = ReactDOM.hydrateRoot(container, );
+ const root = ReactDOMClient.hydrateRoot(
+ container,
+ ,
+ );
suspend = true;
Scheduler.unstable_flushAll();
@@ -1962,7 +1970,10 @@ describe('ReactDOMServerPartialHydration', () => {
const spanA = container.getElementsByTagName('span')[0];
- const root = ReactDOM.hydrateRoot(container, );
+ const root = ReactDOMClient.hydrateRoot(
+ container,
+ ,
+ );
suspend = true;
Scheduler.unstable_flushAll();
@@ -2048,7 +2059,7 @@ describe('ReactDOMServerPartialHydration', () => {
const b = container.getElementsByTagName('span')[1];
expect(b.textContent).toBe('B');
- const root = ReactDOM.hydrateRoot(container, );
+ const root = ReactDOMClient.hydrateRoot(container, );
// Increase hydration priority to higher than "offscreen".
root.unstable_scheduleHydration(b);
@@ -2119,7 +2130,7 @@ describe('ReactDOMServerPartialHydration', () => {
const container = document.createElement('div');
container.innerHTML = html;
- ReactDOM.hydrateRoot(container, , {
+ ReactDOMClient.hydrateRoot(container, , {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(error.message);
},
@@ -2184,7 +2195,7 @@ describe('ReactDOMServerPartialHydration', () => {
const span = container.getElementsByTagName('span')[1];
suspend = false;
- ReactDOM.hydrateRoot(container, , {
+ ReactDOMClient.hydrateRoot(container, , {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(error.message);
},
@@ -2233,7 +2244,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
Scheduler.unstable_flushAll();
jest.runAllTimers();
@@ -2285,7 +2296,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- const root = ReactDOM.hydrateRoot(
+ const root = ReactDOMClient.hydrateRoot(
container,
@@ -2388,7 +2399,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
Scheduler.unstable_flushAll();
jest.runAllTimers();
@@ -2475,7 +2486,7 @@ describe('ReactDOMServerPartialHydration', () => {
// hydrating anyway.
suspend = true;
isServerRendering = false;
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// We'll do one click before hydrating.
a.click();
@@ -2565,7 +2576,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// We'll do one click before hydrating.
await act(async () => {
@@ -2660,7 +2671,7 @@ describe('ReactDOMServerPartialHydration', () => {
// hydrating anyway.
suspend = true;
isServerRendering = false;
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// We'll do one click before hydrating.
a.click();
@@ -2747,7 +2758,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
Scheduler.unstable_flushAll();
jest.runAllTimers();
@@ -2822,7 +2833,7 @@ describe('ReactDOMServerPartialHydration', () => {
// We're going to use a different root as a parent.
// This lets us detect whether an event goes through React's event system.
- const parentRoot = ReactDOM.createRoot(parentContainer);
+ const parentRoot = ReactDOMClient.createRoot(parentContainer);
parentRoot.render();
Scheduler.unstable_flushAll();
@@ -2835,7 +2846,7 @@ describe('ReactDOMServerPartialHydration', () => {
suspend = true;
// Hydrate asynchronously.
- ReactDOM.hydrateRoot(childContainer, );
+ ReactDOMClient.hydrateRoot(childContainer, );
jest.runAllTimers();
Scheduler.unstable_flushAll();
@@ -2933,7 +2944,7 @@ describe('ReactDOMServerPartialHydration', () => {
// hydrating anyway.
suspend1 = true;
suspend2 = true;
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
Scheduler.unstable_flushAll();
jest.runAllTimers();
@@ -3019,7 +3030,10 @@ describe('ReactDOMServerPartialHydration', () => {
container.innerHTML = finalHTML;
suspend = true;
- const root = ReactDOM.hydrateRoot(container, );
+ const root = ReactDOMClient.hydrateRoot(
+ container,
+ ,
+ );
expect(Scheduler).toFlushAndYield([]);
expect(ref.current).toBe(null);
@@ -3105,7 +3119,7 @@ describe('ReactDOMServerPartialHydration', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
Scheduler.unstable_flushAll();
jest.runAllTimers();
@@ -3170,7 +3184,7 @@ describe('ReactDOMServerPartialHydration', () => {
const span = container.getElementsByTagName('span')[0];
expect(span.innerHTML).toBe('Hidden child');
- ReactDOM.hydrateRoot(container, , {
+ ReactDOMClient.hydrateRoot(container, , {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(
'Log recoverable error: ' + error.message,
@@ -3205,7 +3219,7 @@ describe('ReactDOMServerPartialHydration', () => {
const span = container.getElementsByTagName('span')[0];
expect(span.innerHTML).toBe('Hidden child');
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
Scheduler.unstable_flushAll();
expect(ref.current).toBe(span);
expect(span.innerHTML).toBe('Hidden child');
@@ -3230,7 +3244,7 @@ describe('ReactDOMServerPartialHydration', () => {
const span = container.getElementsByTagName('span')[0];
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
Scheduler.unstable_flushAll();
expect(ref.current).toBe(span);
expect(ref.current.innerHTML).toBe('Hidden child');
@@ -3243,7 +3257,7 @@ describe('ReactDOMServerPartialHydration', () => {
const finalHTML = ReactDOMServer.renderToString();
container.innerHTML = finalHTML;
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
Scheduler.unstable_flushAll();
});
}
@@ -3321,7 +3335,7 @@ describe('ReactDOMServerPartialHydration', () => {
expect(() => {
act(() => {
- ReactDOM.hydrateRoot(container, , {
+ ReactDOMClient.hydrateRoot(container, , {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(
'Log recoverable error: ' + error.message,
@@ -3373,7 +3387,7 @@ describe('ReactDOMServerPartialHydration', () => {
);
expect(() => {
act(() => {
- ReactDOM.hydrateRoot(container, , {
+ ReactDOMClient.hydrateRoot(container, , {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(error.message);
},
@@ -3414,11 +3428,15 @@ describe('ReactDOMServerPartialHydration', () => {
);
expect(() => {
act(() => {
- ReactDOM.hydrateRoot(container2, , {
- onRecoverableError(error) {
- Scheduler.unstable_yieldValue(error.message);
+ ReactDOMClient.hydrateRoot(
+ container2,
+ ,
+ {
+ onRecoverableError(error) {
+ Scheduler.unstable_yieldValue(error.message);
+ },
},
- });
+ );
});
}).toErrorDev(
[
diff --git a/packages/react-dom/src/__tests__/ReactDOMServerSelectiveHydration-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMServerSelectiveHydration-test.internal.js
index 435e90d9b1820..91321ea6dd5bf 100644
--- a/packages/react-dom/src/__tests__/ReactDOMServerSelectiveHydration-test.internal.js
+++ b/packages/react-dom/src/__tests__/ReactDOMServerSelectiveHydration-test.internal.js
@@ -13,6 +13,7 @@ import {createEventTarget} from 'dom-event-testing-library';
let React;
let ReactDOM;
+let ReactDOMClient;
let ReactDOMServer;
let ReactFeatureFlags;
let Scheduler;
@@ -117,6 +118,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
ReactFeatureFlags.enableCreateEventHandleAPI = true;
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
act = require('jest-react').act;
Scheduler = require('scheduler');
@@ -165,7 +167,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
const span = container.getElementsByTagName('span')[1];
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// Nothing has been hydrated so far.
expect(Scheduler).toHaveYielded([]);
@@ -243,7 +245,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
// A and D will be suspended. We'll click on D which should take
// priority, after we unsuspend.
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// Nothing has been hydrated so far.
expect(Scheduler).toHaveYielded([]);
@@ -341,7 +343,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
// A and D will be suspended. We'll click on D which should take
// priority, after we unsuspend.
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// Nothing has been hydrated so far.
expect(Scheduler).toHaveYielded([]);
@@ -440,7 +442,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
isServerRendering = false;
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// Nothing has been hydrated so far.
expect(Scheduler).toHaveYielded([]);
@@ -525,7 +527,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
// A and D will be suspended. We'll click on D which should take
// priority, after we unsuspend.
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// Nothing has been hydrated so far.
expect(Scheduler).toHaveYielded([]);
@@ -623,7 +625,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
// A and D will be suspended. We'll click on D which should take
// priority, after we unsuspend.
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// Nothing has been hydrated so far.
expect(Scheduler).toHaveYielded([]);
@@ -732,7 +734,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
// A and D will be suspended. We'll click on D which should take
// priority, after we unsuspend.
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// Nothing has been hydrated so far.
expect(Scheduler).toHaveYielded([]);
@@ -882,7 +884,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
// A and D will be suspended. We'll click on D which should take
// priority, after we unsuspend.
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// Nothing has been hydrated so far.
expect(Scheduler).toHaveYielded([]);
@@ -974,18 +976,18 @@ describe('ReactDOMServerSelectiveHydration', () => {
beforeEach(async () => {
document.body.innerHTML = '';
jest.resetModuleRegistry();
- let OuterReactDOM;
- let InnerReactDOM;
+ let OuterReactDOMClient;
+ let InnerReactDOMClient;
jest.isolateModules(() => {
- OuterReactDOM = require('react-dom');
+ OuterReactDOMClient = require('react-dom/client');
OuterScheduler = require('scheduler');
});
jest.isolateModules(() => {
- InnerReactDOM = require('react-dom');
+ InnerReactDOMClient = require('react-dom/client');
InnerScheduler = require('scheduler');
});
- expect(OuterReactDOM).not.toBe(InnerReactDOM);
+ expect(OuterReactDOMClient).not.toBe(InnerReactDOMClient);
expect(OuterScheduler).not.toBe(InnerScheduler);
const outerContainer = document.createElement('div');
@@ -1071,8 +1073,8 @@ describe('ReactDOMServerSelectiveHydration', () => {
suspendOuter = true;
suspendInner = true;
- OuterReactDOM.hydrateRoot(outerContainer, );
- InnerReactDOM.hydrateRoot(innerContainer, );
+ OuterReactDOMClient.hydrateRoot(outerContainer, );
+ InnerReactDOMClient.hydrateRoot(innerContainer, );
expect(OuterScheduler).toFlushAndYield(['Suspend Outer']);
expect(InnerScheduler).toFlushAndYield(['Suspend Inner']);
@@ -1271,7 +1273,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
container.innerHTML = finalHTML;
suspend = true;
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
const childDiv = container.firstElementChild;
dispatchMouseHoverEvent(childDiv);
@@ -1365,7 +1367,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
// A and D will be suspended. We'll click on D which should take
// priority, after we unsuspend.
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// Nothing has been hydrated so far.
expect(Scheduler).toHaveYielded([]);
@@ -1423,7 +1425,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
const spanB = container.getElementsByTagName('span')[1];
const spanC = container.getElementsByTagName('span')[2];
- const root = ReactDOM.hydrateRoot(container, );
+ const root = ReactDOMClient.hydrateRoot(container, );
// Nothing has been hydrated so far.
expect(Scheduler).toHaveYielded([]);
@@ -1481,7 +1483,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
const spanC = container.getElementsByTagName('span')[4];
act(() => {
- const root = ReactDOM.hydrateRoot(container, );
+ const root = ReactDOMClient.hydrateRoot(container, );
// Hydrate the shell.
expect(Scheduler).toFlushAndYieldThrough(['App', 'Commit']);
@@ -1607,7 +1609,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
const span = container.getElementsByTagName('span')[1];
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// Nothing has been hydrated so far.
expect(Scheduler).toHaveYielded([]);
@@ -1679,7 +1681,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
suspend = true;
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
// Nothing has been hydrated so far.
expect(Scheduler).toHaveYielded([]);
diff --git a/packages/react-dom/src/__tests__/ReactDOMServerSuspense-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMServerSuspense-test.internal.js
index 1611b904bef1a..83c8605e496ef 100644
--- a/packages/react-dom/src/__tests__/ReactDOMServerSuspense-test.internal.js
+++ b/packages/react-dom/src/__tests__/ReactDOMServerSuspense-test.internal.js
@@ -13,6 +13,7 @@ const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegratio
let React;
let ReactDOM;
+let ReactDOMClient;
let ReactDOMServer;
let ReactTestUtils;
let act;
@@ -24,6 +25,7 @@ function initModules() {
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
ReactTestUtils = require('react-dom/test-utils');
act = require('jest-react').act;
@@ -163,7 +165,7 @@ describe('ReactDOMServerSuspense', () => {
expect(divB.textContent).toBe('B');
act(() => {
- ReactDOM.hydrateRoot(parent, example);
+ ReactDOMClient.hydrateRoot(parent, example);
});
const parent2 = element.parentNode;
diff --git a/packages/react-dom/src/__tests__/ReactDOMUseId-test.js b/packages/react-dom/src/__tests__/ReactDOMUseId-test.js
index d3fb8b3ae70a6..4148eeaa2e640 100644
--- a/packages/react-dom/src/__tests__/ReactDOMUseId-test.js
+++ b/packages/react-dom/src/__tests__/ReactDOMUseId-test.js
@@ -9,7 +9,7 @@
let JSDOM;
let React;
-let ReactDOM;
+let ReactDOMClient;
let Scheduler;
let clientAct;
let ReactDOMFizzServer;
@@ -29,7 +29,7 @@ describe('useId', () => {
jest.resetModules();
JSDOM = require('jsdom').JSDOM;
React = require('react');
- ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
clientAct = require('jest-react').act;
ReactDOMFizzServer = require('react-dom/server');
@@ -136,7 +136,7 @@ describe('useId', () => {
pipe(writable);
});
await clientAct(async () => {
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
});
expect(container).toMatchInlineSnapshot(`
{
pipe(writable);
});
await clientAct(async () => {
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(container,
);
});
expect(container).toMatchInlineSnapshot(`
{
pipe(writable);
});
await clientAct(async () => {
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(container,
);
});
expect(container).toMatchInlineSnapshot(`
{
pipe(writable);
});
await clientAct(async () => {
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(container,
);
});
expect(container).toMatchInlineSnapshot(`
{
pipe(writable);
});
await clientAct(async () => {
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(container,
);
});
const divs = container.querySelectorAll('div');
@@ -335,7 +335,7 @@ describe('useId', () => {
pipe(writable);
});
await clientAct(async () => {
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(container,
);
});
// We append a suffix to the end of the id to distinguish them
expect(container).toMatchInlineSnapshot(`
@@ -362,7 +362,7 @@ describe('useId', () => {
pipe(writable);
});
await clientAct(async () => {
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(container,
);
});
expect(container).toMatchInlineSnapshot(`
{
pipe(writable);
});
await clientAct(async () => {
- ReactDOM.hydrateRoot(container,
);
+ ReactDOMClient.hydrateRoot(container,
);
});
expect(container).toMatchInlineSnapshot(`
{
});
const dehydratedSpan = container.getElementsByTagName('span')[0];
await clientAct(async () => {
- const root = ReactDOM.hydrateRoot(container,
);
+ const root = ReactDOMClient.hydrateRoot(container,
);
expect(Scheduler).toFlushUntilNextPaint([]);
expect(container).toMatchInlineSnapshot(`
{
});
const dehydratedSpan = container.getElementsByTagName('span')[0];
await clientAct(async () => {
- const root = ReactDOM.hydrateRoot(container,
);
+ const root = ReactDOMClient.hydrateRoot(container,
);
expect(Scheduler).toFlushUntilNextPaint([]);
expect(container).toMatchInlineSnapshot(`
{
});
let root;
await clientAct(async () => {
- root = ReactDOM.hydrateRoot(container,
, {
+ root = ReactDOMClient.hydrateRoot(container,
, {
identifierPrefix: 'custom-prefix-',
});
});
diff --git a/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js b/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js
index 3d63954a0857f..11a7a510afd3e 100644
--- a/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js
+++ b/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js
@@ -11,6 +11,7 @@
let React;
let ReactDOM;
+let ReactDOMClient;
let ReactDOMServer;
let Scheduler;
@@ -21,6 +22,7 @@ describe('ReactDOMServerHydration', () => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
Scheduler = require('scheduler');
});
@@ -403,7 +405,7 @@ describe('ReactDOMServerHydration', () => {
const finalHTML = ReactDOMServer.renderToString(
);
const container = document.createElement('div');
container.innerHTML = finalHTML;
- const root = ReactDOM.hydrateRoot(container,
);
+ const root = ReactDOMClient.hydrateRoot(container,
);
Scheduler.unstable_flushAll();
root.render(null);
Scheduler.unstable_flushAll();
diff --git a/packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js b/packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js
index 71adc286d08ba..ca7aa3317c5cc 100644
--- a/packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js
+++ b/packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js
@@ -9,6 +9,7 @@
let React;
let ReactDOM;
+let ReactDOMClient;
let ReactTestUtils;
let Scheduler;
let act;
@@ -31,7 +32,7 @@ describe('ReactTestUtils.act()', () => {
if (__EXPERIMENTAL__) {
let concurrentRoot = null;
const renderConcurrent = (el, dom) => {
- concurrentRoot = ReactDOM.createRoot(dom);
+ concurrentRoot = ReactDOMClient.createRoot(dom);
if (__DEV__) {
act(() => concurrentRoot.render(el));
} else {
@@ -100,7 +101,7 @@ describe('ReactTestUtils.act()', () => {
// @gate __DEV__
it('does not warn in concurrent mode', () => {
- const root = ReactDOM.createRoot(document.createElement('div'));
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
act(() => root.render(
));
Scheduler.unstable_flushAll();
});
@@ -113,6 +114,7 @@ function runActTests(label, render, unmount, rerender) {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
ReactTestUtils = require('react-dom/test-utils');
Scheduler = require('scheduler');
act = ReactTestUtils.act;
diff --git a/packages/react-dom/src/__tests__/ReactUpdates-test.js b/packages/react-dom/src/__tests__/ReactUpdates-test.js
index 42647abf53b4a..9e81a3b20ff1c 100644
--- a/packages/react-dom/src/__tests__/ReactUpdates-test.js
+++ b/packages/react-dom/src/__tests__/ReactUpdates-test.js
@@ -11,6 +11,7 @@
let React;
let ReactDOM;
+let ReactDOMClient;
let ReactTestUtils;
let act;
let Scheduler;
@@ -20,6 +21,7 @@ describe('ReactUpdates', () => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
ReactTestUtils = require('react-dom/test-utils');
act = require('jest-react').act;
Scheduler = require('scheduler');
@@ -1332,7 +1334,7 @@ describe('ReactUpdates', () => {
);
}
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
let hiddenDiv;
act(() => {
root.render(
);
@@ -1709,7 +1711,7 @@ describe('ReactUpdates', () => {
}
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
expect(() => {
ReactDOM.flushSync(() => {
root.render(
);
diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js
index c3f9e3fcb47e1..e85a580aed72a 100644
--- a/packages/react-dom/src/client/ReactDOM.js
+++ b/packages/react-dom/src/client/ReactDOM.js
@@ -9,6 +9,11 @@
import type {ReactNodeList} from 'shared/ReactTypes';
import type {Container} from './ReactDOMHostConfig';
+import type {
+ RootType,
+ HydrateRootOptions,
+ CreateRootOptions,
+} from './ReactDOMRoot';
import {
findDOMNode,
@@ -17,7 +22,11 @@ import {
unstable_renderSubtreeIntoContainer,
unmountComponentAtNode,
} from './ReactDOMLegacy';
-import {createRoot, hydrateRoot, isValidContainer} from './ReactDOMRoot';
+import {
+ createRoot as createRootImpl,
+ hydrateRoot as hydrateRootImpl,
+ isValidContainer,
+} from './ReactDOMRoot';
import {createEventHandle} from './ReactDOMEventHandle';
import {
@@ -125,6 +134,7 @@ function renderSubtreeIntoContainer(
}
const Internals = {
+ usingClientEntryPoint: false,
// Keep in sync with ReactTestUtils.js.
// This is an array for better minification.
Events: [
@@ -137,6 +147,37 @@ const Internals = {
],
};
+function createRoot(
+ container: Container,
+ options?: CreateRootOptions,
+): RootType {
+ if (__DEV__) {
+ if (!Internals.usingClientEntryPoint) {
+ console.error(
+ 'You are importing createRoot from "react-dom" which is not supported. ' +
+ 'You should instead import it from "react-dom/client".',
+ );
+ }
+ }
+ return createRootImpl(container, options);
+}
+
+function hydrateRoot(
+ container: Container,
+ initialChildren: ReactNodeList,
+ options?: HydrateRootOptions,
+): RootType {
+ if (__DEV__) {
+ if (!Internals.usingClientEntryPoint) {
+ console.error(
+ 'You are importing hydrateRoot from "react-dom" which is not supported. ' +
+ 'You should instead import it from "react-dom/client".',
+ );
+ }
+ }
+ return hydrateRootImpl(container, initialChildren, options);
+}
+
// Overload the definition to the two valid signatures.
// Warning, this opts-out of checking the function body.
declare function flushSync
(fn: () => R): R;
diff --git a/packages/react-dom/src/client/ReactDOMLegacy.js b/packages/react-dom/src/client/ReactDOMLegacy.js
index 1c53b5620b677..3b751405a3034 100644
--- a/packages/react-dom/src/client/ReactDOMLegacy.js
+++ b/packages/react-dom/src/client/ReactDOMLegacy.js
@@ -256,7 +256,7 @@ export function hydrate(
if (isModernRoot) {
console.error(
'You are calling ReactDOM.hydrate() on a container that was previously ' +
- 'passed to ReactDOM.createRoot(). This is not supported. ' +
+ 'passed to ReactDOMClient.createRoot(). This is not supported. ' +
'Did you mean to call hydrateRoot(container, element)?',
);
}
@@ -296,7 +296,7 @@ export function render(
if (isModernRoot) {
console.error(
'You are calling ReactDOM.render() on a container that was previously ' +
- 'passed to ReactDOM.createRoot(). This is not supported. ' +
+ 'passed to ReactDOMClient.createRoot(). This is not supported. ' +
'Did you mean to call root.render(element)?',
);
}
@@ -356,7 +356,7 @@ export function unmountComponentAtNode(container: Container) {
if (isModernRoot) {
console.error(
'You are calling ReactDOM.unmountComponentAtNode() on a container that was previously ' +
- 'passed to ReactDOM.createRoot(). This is not supported. Did you mean to call root.unmount()?',
+ 'passed to ReactDOMClient.createRoot(). This is not supported. Did you mean to call root.unmount()?',
);
}
}
diff --git a/packages/react-dom/src/client/ReactDOMRoot.js b/packages/react-dom/src/client/ReactDOMRoot.js
index 57bbe7ab96d68..d71de3bb0c26d 100644
--- a/packages/react-dom/src/client/ReactDOMRoot.js
+++ b/packages/react-dom/src/client/ReactDOMRoot.js
@@ -184,7 +184,7 @@ export function createRoot(
if (__DEV__) {
if ((options: any).hydrate) {
console.warn(
- 'hydrate through createRoot is deprecated. Use ReactDOM.hydrateRoot(container, ) instead.',
+ 'hydrate through createRoot is deprecated. Use ReactDOMClient.hydrateRoot(container, ) instead.',
);
} else {
if (
@@ -369,12 +369,12 @@ function warnIfReactDOMContainerInDEV(container) {
if (isContainerMarkedAsRoot(container)) {
if (container._reactRootContainer) {
console.error(
- 'You are calling ReactDOM.createRoot() on a container that was previously ' +
+ 'You are calling ReactDOMClient.createRoot() on a container that was previously ' +
'passed to ReactDOM.render(). This is not supported.',
);
} else {
console.error(
- 'You are calling ReactDOM.createRoot() on a container that ' +
+ 'You are calling ReactDOMClient.createRoot() on a container that ' +
'has already been passed to createRoot() before. Instead, call ' +
'root.render() on the existing root instead if you want to update it.',
);
diff --git a/packages/react-dom/src/events/__tests__/DOMPluginEventSystem-test.internal.js b/packages/react-dom/src/events/__tests__/DOMPluginEventSystem-test.internal.js
index 248c07020e551..bcc3f15c44e79 100644
--- a/packages/react-dom/src/events/__tests__/DOMPluginEventSystem-test.internal.js
+++ b/packages/react-dom/src/events/__tests__/DOMPluginEventSystem-test.internal.js
@@ -14,6 +14,7 @@ import {createEventTarget} from 'dom-event-testing-library';
let React;
let ReactFeatureFlags;
let ReactDOM;
+let ReactDOMClient;
let ReactDOMServer;
let Scheduler;
let act;
@@ -64,6 +65,7 @@ describe('DOMPluginEventSystem', () => {
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
ReactDOMServer = require('react-dom/server');
act = require('jest-react').act;
@@ -616,7 +618,7 @@ describe('DOMPluginEventSystem', () => {
// We're going to use a different root as a parent.
// This lets us detect whether an event goes through React's event system.
- const parentRoot = ReactDOM.createRoot(parentContainer);
+ const parentRoot = ReactDOMClient.createRoot(parentContainer);
parentRoot.render();
Scheduler.unstable_flushAll();
@@ -629,7 +631,7 @@ describe('DOMPluginEventSystem', () => {
suspend = true;
// Hydrate asynchronously.
- ReactDOM.hydrateRoot(childContainer, );
+ ReactDOMClient.hydrateRoot(childContainer, );
jest.runAllTimers();
Scheduler.unstable_flushAll();
@@ -1258,6 +1260,7 @@ describe('DOMPluginEventSystem', () => {
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
ReactDOMServer = require('react-dom/server');
act = require('jest-react').act;
@@ -1940,7 +1943,7 @@ describe('DOMPluginEventSystem', () => {
return ;
}
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render();
expect(Scheduler).toFlushAndYield(['Test']);
@@ -2561,7 +2564,7 @@ describe('DOMPluginEventSystem', () => {
const container2 = document.createElement('div');
document.body.appendChild(container2);
- const root = ReactDOM.createRoot(container2);
+ const root = ReactDOMClient.createRoot(container2);
act(() => {
root.render();
@@ -2648,7 +2651,7 @@ describe('DOMPluginEventSystem', () => {
const container2 = document.createElement('div');
document.body.appendChild(container2);
- const root = ReactDOM.createRoot(container2);
+ const root = ReactDOMClient.createRoot(container2);
act(() => {
root.render();
@@ -2715,7 +2718,7 @@ describe('DOMPluginEventSystem', () => {
const container2 = document.createElement('div');
document.body.appendChild(container2);
- const root = ReactDOM.createRoot(container2);
+ const root = ReactDOMClient.createRoot(container2);
act(() => {
root.render();
});
@@ -2872,6 +2875,7 @@ describe('DOMPluginEventSystem', () => {
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
ReactDOMServer = require('react-dom/server');
});
diff --git a/packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js b/packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js
index b1a5649624aeb..db2fd6f7562f3 100644
--- a/packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js
+++ b/packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js
@@ -11,6 +11,7 @@
let React;
let ReactDOM;
+let ReactDOMClient;
let ReactFeatureFlags;
let Scheduler;
let act;
@@ -56,6 +57,7 @@ describe('ChangeEventPlugin', () => {
};
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
act = require('jest-react').act;
Scheduler = require('scheduler');
container = document.createElement('div');
@@ -496,7 +498,7 @@ describe('ChangeEventPlugin', () => {
describe('concurrent mode', () => {
it('text input', () => {
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
let input;
class ControlledInput extends React.Component {
@@ -538,7 +540,7 @@ describe('ChangeEventPlugin', () => {
});
it('checkbox input', () => {
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
let input;
class ControlledInput extends React.Component {
@@ -593,7 +595,7 @@ describe('ChangeEventPlugin', () => {
});
it('textarea', () => {
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
let textarea;
class ControlledTextarea extends React.Component {
@@ -635,7 +637,7 @@ describe('ChangeEventPlugin', () => {
});
it('parent of input', () => {
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
let input;
class ControlledInput extends React.Component {
@@ -681,7 +683,7 @@ describe('ChangeEventPlugin', () => {
});
it('is sync for non-input events', async () => {
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
let input;
class ControlledInput extends React.Component {
@@ -729,7 +731,7 @@ describe('ChangeEventPlugin', () => {
it('mouse enter/leave should be user-blocking but not discrete', async () => {
const {useState} = React;
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
const target = React.createRef(null);
function Foo() {
diff --git a/packages/react-dom/src/events/plugins/__tests__/SimpleEventPlugin-test.js b/packages/react-dom/src/events/plugins/__tests__/SimpleEventPlugin-test.js
index ba830d939c5f5..cc37fcd0498bc 100644
--- a/packages/react-dom/src/events/plugins/__tests__/SimpleEventPlugin-test.js
+++ b/packages/react-dom/src/events/plugins/__tests__/SimpleEventPlugin-test.js
@@ -12,6 +12,7 @@
describe('SimpleEventPlugin', function() {
let React;
let ReactDOM;
+ let ReactDOMClient;
let Scheduler;
let act;
@@ -39,6 +40,7 @@ describe('SimpleEventPlugin', function() {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
onClick = jest.fn();
@@ -235,6 +237,7 @@ describe('SimpleEventPlugin', function() {
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
act = require('jest-react').act;
@@ -242,7 +245,7 @@ describe('SimpleEventPlugin', function() {
it('flushes pending interactive work before exiting event handler', async () => {
container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
document.body.appendChild(container);
let button;
@@ -317,7 +320,7 @@ describe('SimpleEventPlugin', function() {
// was dispatched.
it('end result of many interactive updates is deterministic', async () => {
container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
document.body.appendChild(container);
let button;
diff --git a/packages/react-interactions/events/src/dom/create-event-handle/__tests__/useFocusWithin-test.internal.js b/packages/react-interactions/events/src/dom/create-event-handle/__tests__/useFocusWithin-test.internal.js
index df151bbf72c24..9128692809945 100644
--- a/packages/react-interactions/events/src/dom/create-event-handle/__tests__/useFocusWithin-test.internal.js
+++ b/packages/react-interactions/events/src/dom/create-event-handle/__tests__/useFocusWithin-test.internal.js
@@ -14,6 +14,7 @@ import {createEventTarget, setPointerEvent} from 'dom-event-testing-library';
let React;
let ReactFeatureFlags;
let ReactDOM;
+let ReactDOMClient;
let useFocusWithin;
let act;
let Scheduler;
@@ -26,6 +27,7 @@ function initializeModules(hasPointerEvents) {
ReactFeatureFlags.enableCreateEventHandleAPI = true;
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
act = require('jest-react').act;
@@ -504,7 +506,7 @@ describe.each(table)(`useFocus`, hasPointerEvents => {
);
};
- const root = ReactDOM.createRoot(container2);
+ const root = ReactDOMClient.createRoot(container2);
act(() => {
root.render();
@@ -563,7 +565,7 @@ describe.each(table)(`useFocus`, hasPointerEvents => {
);
};
- const root = ReactDOM.createRoot(container2);
+ const root = ReactDOMClient.createRoot(container2);
act(() => {
root.render();
diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.new.js b/packages/react-reconciler/src/ReactFiberBeginWork.new.js
index 4435fef438938..27a414004c1a7 100644
--- a/packages/react-reconciler/src/ReactFiberBeginWork.new.js
+++ b/packages/react-reconciler/src/ReactFiberBeginWork.new.js
@@ -2628,7 +2628,7 @@ function mountDehydratedSuspenseComponent(
console.error(
'Cannot hydrate Suspense in legacy mode. Switch from ' +
'ReactDOM.hydrate(element, container) to ' +
- 'ReactDOM.hydrateRoot(container, )' +
+ 'ReactDOMClient.hydrateRoot(container, )' +
'.render(element) or remove the Suspense components from ' +
'the server rendered components.',
);
diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.old.js b/packages/react-reconciler/src/ReactFiberBeginWork.old.js
index b037863aa40de..297d5e7d2b5b7 100644
--- a/packages/react-reconciler/src/ReactFiberBeginWork.old.js
+++ b/packages/react-reconciler/src/ReactFiberBeginWork.old.js
@@ -2628,7 +2628,7 @@ function mountDehydratedSuspenseComponent(
console.error(
'Cannot hydrate Suspense in legacy mode. Switch from ' +
'ReactDOM.hydrate(element, container) to ' +
- 'ReactDOM.hydrateRoot(container, )' +
+ 'ReactDOMClient.hydrateRoot(container, )' +
'.render(element) or remove the Suspense components from ' +
'the server rendered components.',
);
diff --git a/packages/react-reconciler/src/ReactFiberDevToolsHook.new.js b/packages/react-reconciler/src/ReactFiberDevToolsHook.new.js
index 8c245e1efb32d..999431c694568 100644
--- a/packages/react-reconciler/src/ReactFiberDevToolsHook.new.js
+++ b/packages/react-reconciler/src/ReactFiberDevToolsHook.new.js
@@ -11,7 +11,11 @@ import type {Lane, Lanes} from './ReactFiberLane.new';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {ReactNodeList, Wakeable} from 'shared/ReactTypes';
import type {EventPriority} from './ReactEventPriorities.new';
-import type {DevToolsProfilingHooks} from 'react-devtools-shared/src/backend/types';
+// import type {DevToolsProfilingHooks} from 'react-devtools-shared/src/backend/types';
+// TODO: This import doesn't work because the DevTools depend on the DOM version of React
+// and to properly type check against DOM React we can't also type check again non-DOM
+// React which this hook might be in.
+type DevToolsProfilingHooks = any;
import {
getLabelForLane,
diff --git a/packages/react-reconciler/src/ReactFiberDevToolsHook.old.js b/packages/react-reconciler/src/ReactFiberDevToolsHook.old.js
index defaf397deb78..000219aa06092 100644
--- a/packages/react-reconciler/src/ReactFiberDevToolsHook.old.js
+++ b/packages/react-reconciler/src/ReactFiberDevToolsHook.old.js
@@ -11,7 +11,11 @@ import type {Lane, Lanes} from './ReactFiberLane.old';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {ReactNodeList, Wakeable} from 'shared/ReactTypes';
import type {EventPriority} from './ReactEventPriorities.old';
-import type {DevToolsProfilingHooks} from 'react-devtools-shared/src/backend/types';
+// import type {DevToolsProfilingHooks} from 'react-devtools-shared/src/backend/types';
+// TODO: This import doesn't work because the DevTools depend on the DOM version of React
+// and to properly type check against DOM React we can't also type check again non-DOM
+// React which this hook might be in.
+type DevToolsProfilingHooks = any;
import {
getLabelForLane,
diff --git a/packages/react-reconciler/src/__tests__/ReactScope-test.internal.js b/packages/react-reconciler/src/__tests__/ReactScope-test.internal.js
index 9dd7d85b5b40d..2120aae18b189 100644
--- a/packages/react-reconciler/src/__tests__/ReactScope-test.internal.js
+++ b/packages/react-reconciler/src/__tests__/ReactScope-test.internal.js
@@ -25,10 +25,12 @@ describe('ReactScope', () => {
describe('ReactDOM', () => {
let ReactDOM;
+ let ReactDOMClient;
let container;
beforeEach(() => {
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
container = document.createElement('div');
document.body.appendChild(container);
@@ -312,7 +314,7 @@ describe('ReactScope', () => {
// On the client we don't have all data yet but we want to start
// hydrating anyway.
suspend = true;
- ReactDOM.hydrateRoot(container2, );
+ ReactDOMClient.hydrateRoot(container2, );
Scheduler.unstable_flushAll();
jest.runAllTimers();
diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemanticsDOM-test.js b/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemanticsDOM-test.js
index 8ed56bd5f2d96..cb1196baffe6a 100644
--- a/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemanticsDOM-test.js
+++ b/packages/react-reconciler/src/__tests__/ReactSuspenseEffectsSemanticsDOM-test.js
@@ -10,7 +10,7 @@
'use strict';
let React;
-let ReactDOM;
+let ReactDOMClient;
let act;
describe('ReactSuspenseEffectsSemanticsDOM', () => {
@@ -18,7 +18,7 @@ describe('ReactSuspenseEffectsSemanticsDOM', () => {
jest.resetModules();
React = require('react');
- ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
act = require('jest-react').act;
});
@@ -63,7 +63,7 @@ describe('ReactSuspenseEffectsSemanticsDOM', () => {
}
act(() => {
- const root = ReactDOM.createRoot(document.createElement('div'));
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
root.render();
});
diff --git a/packages/react-reconciler/src/__tests__/ReactUpdaters-test.internal.js b/packages/react-reconciler/src/__tests__/ReactUpdaters-test.internal.js
index 44301017338cb..b4b0b17ef1db0 100644
--- a/packages/react-reconciler/src/__tests__/ReactUpdaters-test.internal.js
+++ b/packages/react-reconciler/src/__tests__/ReactUpdaters-test.internal.js
@@ -12,6 +12,7 @@
let React;
let ReactFeatureFlags;
let ReactDOM;
+let ReactDOMClient;
let Scheduler;
let mockDevToolsHook;
let allSchedulerTags;
@@ -90,6 +91,7 @@ describe('updaters', () => {
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
act = require('jest-react').act;
@@ -209,7 +211,7 @@ describe('updaters', () => {
return count;
};
- const root = ReactDOM.createRoot(document.createElement('div'));
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
await act(async () => {
root.render();
expect(Scheduler).toFlushAndYieldThrough([
@@ -354,7 +356,7 @@ describe('updaters', () => {
throw new Error('Hello');
};
- const root = ReactDOM.createRoot(document.createElement('div'));
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
await act(async () => {
root.render();
});
@@ -404,7 +406,7 @@ describe('updaters', () => {
return null;
};
- const root = ReactDOM.createRoot(document.createElement('div'));
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
root.render(
diff --git a/packages/react-reconciler/src/__tests__/useMutableSourceHydration-test.js b/packages/react-reconciler/src/__tests__/useMutableSourceHydration-test.js
index 4e9bd2f0c9973..cb2d7d2ac81b2 100644
--- a/packages/react-reconciler/src/__tests__/useMutableSourceHydration-test.js
+++ b/packages/react-reconciler/src/__tests__/useMutableSourceHydration-test.js
@@ -10,7 +10,7 @@
'use strict';
let React;
-let ReactDOM;
+let ReactDOMClient;
let ReactDOMServer;
let Scheduler;
let act;
@@ -22,7 +22,7 @@ describe('useMutableSourceHydration', () => {
jest.resetModules();
React = require('react');
- ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
Scheduler = require('scheduler');
@@ -160,7 +160,7 @@ describe('useMutableSourceHydration', () => {
expect(source.listenerCount).toBe(0);
act(() => {
- ReactDOM.hydrateRoot(container, , {
+ ReactDOMClient.hydrateRoot(container, , {
mutableSources: [mutableSource],
});
});
@@ -195,7 +195,7 @@ describe('useMutableSourceHydration', () => {
expect(() => {
act(() => {
- ReactDOM.hydrateRoot(container, , {
+ ReactDOMClient.hydrateRoot(container, , {
mutableSources: [mutableSource],
onRecoverableError(error) {
Scheduler.unstable_yieldValue('Log error: ' + error.message);
@@ -256,7 +256,7 @@ describe('useMutableSourceHydration', () => {
act(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
- ReactDOM.hydrateRoot(container, , {
+ ReactDOMClient.hydrateRoot(container, , {
mutableSources: [mutableSource],
onRecoverableError(error) {
Scheduler.unstable_yieldValue('Log error: ' + error.message);
@@ -264,7 +264,7 @@ describe('useMutableSourceHydration', () => {
});
});
} else {
- ReactDOM.hydrateRoot(container, , {
+ ReactDOMClient.hydrateRoot(container, , {
mutableSources: [mutableSource],
onRecoverableError(error) {
Scheduler.unstable_yieldValue('Log error: ' + error.message);
@@ -349,7 +349,7 @@ describe('useMutableSourceHydration', () => {
);
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
- ReactDOM.hydrateRoot(container, fragment, {
+ ReactDOMClient.hydrateRoot(container, fragment, {
mutableSources: [mutableSource],
onRecoverableError(error) {
Scheduler.unstable_yieldValue('Log error: ' + error.message);
@@ -357,7 +357,7 @@ describe('useMutableSourceHydration', () => {
});
});
} else {
- ReactDOM.hydrateRoot(container, fragment, {
+ ReactDOMClient.hydrateRoot(container, fragment, {
mutableSources: [mutableSource],
onRecoverableError(error) {
Scheduler.unstable_yieldValue('Log error: ' + error.message);
diff --git a/packages/react-refresh/src/__tests__/ReactFresh-test.js b/packages/react-refresh/src/__tests__/ReactFresh-test.js
index 0a31aa9c62f72..378f44d4ffccf 100644
--- a/packages/react-refresh/src/__tests__/ReactFresh-test.js
+++ b/packages/react-refresh/src/__tests__/ReactFresh-test.js
@@ -13,6 +13,7 @@
let React;
let ReactDOM;
+let ReactDOMClient;
let ReactFreshRuntime;
let Scheduler;
let act;
@@ -28,6 +29,7 @@ describe('ReactFresh', () => {
ReactFreshRuntime = require('react-refresh/runtime');
ReactFreshRuntime.injectIntoGlobalHook(global);
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
act = require('jest-react').act;
createReactClass = require('create-react-class/factory')(
@@ -2437,7 +2439,7 @@ describe('ReactFresh', () => {
};
});
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render();
expect(Scheduler).toFlushAndYieldThrough(['App#layout']);
const el = container.firstChild;
diff --git a/packages/react-server-dom-relay/src/__tests__/ReactFlightDOMRelay-test.internal.js b/packages/react-server-dom-relay/src/__tests__/ReactFlightDOMRelay-test.internal.js
index 11d25a5a11966..dc981b9bd5304 100644
--- a/packages/react-server-dom-relay/src/__tests__/ReactFlightDOMRelay-test.internal.js
+++ b/packages/react-server-dom-relay/src/__tests__/ReactFlightDOMRelay-test.internal.js
@@ -9,7 +9,7 @@
let act;
let React;
-let ReactDOM;
+let ReactDOMClient;
let JSResourceReference;
let ReactDOMFlightRelayServer;
let ReactDOMFlightRelayClient;
@@ -21,7 +21,7 @@ describe('ReactFlightDOMRelay', () => {
act = require('jest-react').act;
React = require('react');
- ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
ReactDOMFlightRelayServer = require('react-server-dom-relay/server');
ReactDOMFlightRelayClient = require('react-server-dom-relay');
JSResourceReference = require('JSResourceReference');
@@ -100,7 +100,7 @@ describe('ReactFlightDOMRelay', () => {
const modelClient = readThrough(transport);
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
act(() => {
root.render(modelClient.greeting);
});
diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js
index bcae6c50f7c7f..4ca3f903e779c 100644
--- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js
+++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js
@@ -27,7 +27,7 @@ global.__webpack_require__ = function(id) {
let act;
let Stream;
let React;
-let ReactDOM;
+let ReactDOMClient;
let ReactServerDOMWriter;
let ReactServerDOMReader;
@@ -39,7 +39,7 @@ describe('ReactFlightDOM', () => {
act = require('jest-react').act;
Stream = require('stream');
React = require('react');
- ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
ReactServerDOMWriter = require('react-server-dom-webpack/writer.node.server');
ReactServerDOMReader = require('react-server-dom-webpack');
});
@@ -174,7 +174,7 @@ describe('ReactFlightDOM', () => {
const response = ReactServerDOMReader.createFromReadableStream(readable);
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
await act(async () => {
root.render();
});
@@ -212,7 +212,7 @@ describe('ReactFlightDOM', () => {
const response = ReactServerDOMReader.createFromReadableStream(readable);
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
await act(async () => {
root.render();
});
@@ -248,7 +248,7 @@ describe('ReactFlightDOM', () => {
const response = ReactServerDOMReader.createFromReadableStream(readable);
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
await act(async () => {
root.render();
});
@@ -388,7 +388,7 @@ describe('ReactFlightDOM', () => {
const response = ReactServerDOMReader.createFromReadableStream(readable);
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
await act(async () => {
root.render(
(loading)}>
@@ -487,7 +487,7 @@ describe('ReactFlightDOM', () => {
}
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
const stream1 = getTestStream();
const {pipe} = ReactServerDOMWriter.renderToPipeableStream(
diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js
index 09ea1515c9997..c7b97707c166f 100644
--- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js
+++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js
@@ -23,7 +23,7 @@ global.__webpack_require__ = function(id) {
let act;
let React;
-let ReactDOM;
+let ReactDOMClient;
let ReactServerDOMWriter;
let ReactServerDOMReader;
@@ -34,7 +34,7 @@ describe('ReactFlightDOMBrowser', () => {
webpackMap = {};
act = require('jest-react').act;
React = require('react');
- ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
ReactServerDOMWriter = require('react-server-dom-webpack/writer.browser.server');
ReactServerDOMReader = require('react-server-dom-webpack');
});
@@ -270,7 +270,7 @@ describe('ReactFlightDOMBrowser', () => {
const response = ReactServerDOMReader.createFromReadableStream(stream);
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
await act(async () => {
root.render(
(loading)}>
diff --git a/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee b/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee
index 3cf0e40b65dbc..772905b7e0142 100644
--- a/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee
+++ b/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee
@@ -8,6 +8,7 @@ LICENSE file in the root directory of this source tree.
PropTypes = null
React = null
ReactDOM = null
+ReactDOMClient = null
act = null
describe 'ReactCoffeeScriptClass', ->
@@ -20,10 +21,11 @@ describe 'ReactCoffeeScriptClass', ->
beforeEach ->
React = require 'react'
ReactDOM = require 'react-dom'
+ ReactDOMClient = require 'react-dom/client'
act = require('jest-react').act
PropTypes = require 'prop-types'
container = document.createElement 'div'
- root = ReactDOM.createRoot container
+ root = ReactDOMClient.createRoot container
attachedListener = null
renderedName = null
InnerComponent = class extends React.Component
diff --git a/packages/react/src/__tests__/ReactES6Class-test.js b/packages/react/src/__tests__/ReactES6Class-test.js
index 3c15930a3798a..67b9e11a49805 100644
--- a/packages/react/src/__tests__/ReactES6Class-test.js
+++ b/packages/react/src/__tests__/ReactES6Class-test.js
@@ -12,6 +12,7 @@
let PropTypes;
let React;
let ReactDOM;
+let ReactDOMClient;
let act;
describe('ReactES6Class', () => {
@@ -29,9 +30,10 @@ describe('ReactES6Class', () => {
PropTypes = require('prop-types');
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
act = require('jest-react').act;
container = document.createElement('div');
- root = ReactDOM.createRoot(container);
+ root = ReactDOMClient.createRoot(container);
attachedListener = null;
renderedName = null;
Inner = class extends React.Component {
diff --git a/packages/react/src/__tests__/ReactStrictMode-test.internal.js b/packages/react/src/__tests__/ReactStrictMode-test.internal.js
index 081be41e1bc88..18f5a4a3caa4c 100644
--- a/packages/react/src/__tests__/ReactStrictMode-test.internal.js
+++ b/packages/react/src/__tests__/ReactStrictMode-test.internal.js
@@ -11,13 +11,13 @@
describe('ReactStrictMode', () => {
let React;
- let ReactDOM;
+ let ReactDOMClient;
let act;
beforeEach(() => {
jest.resetModules();
React = require('react');
- ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
act = require('jest-react').act;
@@ -51,7 +51,7 @@ describe('ReactStrictMode', () => {
it('should default to not strict', () => {
act(() => {
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render();
});
@@ -66,7 +66,7 @@ describe('ReactStrictMode', () => {
it('should support enabling strict mode via createRoot option', () => {
act(() => {
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container, {
+ const root = ReactDOMClient.createRoot(container, {
unstable_strictMode: true,
});
root.render();
@@ -87,7 +87,7 @@ describe('ReactStrictMode', () => {
it('should include legacy + strict effects mode', () => {
act(() => {
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render(
@@ -110,7 +110,7 @@ describe('ReactStrictMode', () => {
it('should allow level to be increased with nesting', () => {
act(() => {
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render(
<>
diff --git a/packages/react/src/__tests__/ReactStrictMode-test.js b/packages/react/src/__tests__/ReactStrictMode-test.js
index 84fbead1f4926..81416f260ae90 100644
--- a/packages/react/src/__tests__/ReactStrictMode-test.js
+++ b/packages/react/src/__tests__/ReactStrictMode-test.js
@@ -11,6 +11,7 @@
let React;
let ReactDOM;
+let ReactDOMClient;
let ReactDOMServer;
let Scheduler;
let PropTypes;
@@ -22,6 +23,7 @@ describe('ReactStrictMode', () => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
});
@@ -361,6 +363,7 @@ describe('Concurrent Mode', () => {
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
});
@@ -406,7 +409,7 @@ describe('Concurrent Mode', () => {
}
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render();
expect(() => Scheduler.unstable_flushAll()).toErrorDev(
[
@@ -468,7 +471,7 @@ Please update the following components: App`,
}
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render();
expect(() => {
@@ -544,7 +547,7 @@ Please update the following components: Parent`,
}
const container = document.createElement('div');
- const root = ReactDOM.createRoot(container);
+ const root = ReactDOMClient.createRoot(container);
root.render();
expect(() =>
Scheduler.unstable_flushAll(),
@@ -623,6 +626,7 @@ describe('symbol checks', () => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
});
it('should switch from StrictMode to a Fragment and reset state', () => {
@@ -735,6 +739,7 @@ describe('string refs', () => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
});
it('should warn within a strict tree', () => {
@@ -820,6 +825,7 @@ describe('context legacy', () => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
PropTypes = require('prop-types');
});
@@ -900,6 +906,7 @@ describe('context legacy', () => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
});
if (ReactFeatureFlags.consoleManagedByDevToolsDuringStrictMode) {
diff --git a/packages/react/src/__tests__/ReactTypeScriptClass-test.ts b/packages/react/src/__tests__/ReactTypeScriptClass-test.ts
index d9456404bb5ed..8d53739d338cd 100644
--- a/packages/react/src/__tests__/ReactTypeScriptClass-test.ts
+++ b/packages/react/src/__tests__/ReactTypeScriptClass-test.ts
@@ -1,6 +1,7 @@
///
///
///
+///
///
/*!
@@ -12,6 +13,7 @@
import React = require('react');
import ReactDOM = require('react-dom');
+import ReactDOMClient = require('react-dom/client');
import ReactDOMTestUtils = require('react-dom/test-utils');
import PropTypes = require('prop-types');
import internalAct = require('jest-react');
@@ -317,7 +319,7 @@ class ClassicRefs extends React.Component {
describe('ReactTypeScriptClass', function() {
beforeEach(function() {
container = document.createElement('div');
- root = ReactDOM.createRoot(container);
+ root = ReactDOMClient.createRoot(container);
attachedListener = null;
renderedName = null;
});
diff --git a/packages/react/src/__tests__/testDefinitions/ReactDOM.d.ts b/packages/react/src/__tests__/testDefinitions/ReactDOM.d.ts
index 1d0e883ab1621..90ee316124d95 100644
--- a/packages/react/src/__tests__/testDefinitions/ReactDOM.d.ts
+++ b/packages/react/src/__tests__/testDefinitions/ReactDOM.d.ts
@@ -13,7 +13,6 @@
*/
declare module 'react-dom' {
- export function createRoot(container : any) : any
export function render(element : any, container : any) : any
export function unmountComponentAtNode(container : any) : void
export function findDOMNode(instance : any) : any
diff --git a/packages/react/src/__tests__/testDefinitions/ReactDOMClient.d.ts b/packages/react/src/__tests__/testDefinitions/ReactDOMClient.d.ts
new file mode 100644
index 0000000000000..a97ad21ce6a1c
--- /dev/null
+++ b/packages/react/src/__tests__/testDefinitions/ReactDOMClient.d.ts
@@ -0,0 +1,18 @@
+/*!
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+/**
+ * TypeScript Definition File for React.
+ *
+ * Full type definitions are not yet officially supported. These are mostly
+ * just helpers for the unit test.
+ */
+
+declare module 'react-dom/client' {
+ export function createRoot(container : any, options?: any) : any
+ export function hydrateRoot(container : any, children: any, options?: any) : any
+}
diff --git a/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShared-test.js b/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShared-test.js
index 2a628990049b6..5b0ce4f1a4afe 100644
--- a/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShared-test.js
+++ b/packages/use-sync-external-store/src/__tests__/useSyncExternalStoreShared-test.js
@@ -13,6 +13,7 @@ let useSyncExternalStore;
let useSyncExternalStoreWithSelector;
let React;
let ReactDOM;
+let ReactDOMClient;
let Scheduler;
let act;
let useState;
@@ -46,6 +47,7 @@ describe('Shared useSyncExternalStore behavior (shim and built-in)', () => {
React = require('react');
ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
useState = React.useState;
useEffect = React.useEffect;
@@ -90,7 +92,7 @@ describe('Shared useSyncExternalStore behavior (shim and built-in)', () => {
// the correct behavior, despite the fact that the legacy root API
// triggers a warning in 18), write a test that uses
// createLegacyRoot directly.
- return ReactDOM.createRoot(container);
+ return ReactDOMClient.createRoot(container);
} else {
ReactDOM.render(null, container);
return {
@@ -745,7 +747,7 @@ describe('Shared useSyncExternalStore behavior (shim and built-in)', () => {
if (gate(flags => !flags.enableUseSyncExternalStoreShim)) {
act(() => {
- ReactDOM.hydrateRoot(container, );
+ ReactDOMClient.hydrateRoot(container, );
});
expect(Scheduler).toHaveYielded([
// First it hydrates the server rendered HTML
diff --git a/scripts/jest/typescript/preprocessor.js b/scripts/jest/typescript/preprocessor.js
index dbf910754f9b2..a4100be8aec43 100644
--- a/scripts/jest/typescript/preprocessor.js
+++ b/scripts/jest/typescript/preprocessor.js
@@ -42,7 +42,7 @@ function compile(content, contentFilename) {
let source;
const libRegex = /lib\.(.+\.)?d\.ts$/;
const jestRegex = /jest\.d\.ts/;
- const reactRegex = /(?:React|ReactDOM|ReactInternalAct|PropTypes)(?:\.d)?\.ts$/;
+ const reactRegex = /(?:React|ReactDOM|ReactDOMClient|ReactInternalAct|PropTypes)(?:\.d)?\.ts$/;
// `path.normalize` is used to turn forward slashes in
// the file path into backslashes on Windows.
diff --git a/scripts/shared/inlinedHostConfigs.js b/scripts/shared/inlinedHostConfigs.js
index b2b9639505a7b..4e47b4fd6ffcb 100644
--- a/scripts/shared/inlinedHostConfigs.js
+++ b/scripts/shared/inlinedHostConfigs.js
@@ -18,12 +18,17 @@ module.exports = [
],
paths: [
'react-dom',
+ 'react-dom/client',
'react-dom/src/server/ReactDOMFizzServerNode.js', // react-dom/server.node
'react-server-dom-webpack',
'react-server-dom-webpack/writer',
'react-server-dom-webpack/writer.node.server',
'react-server-dom-webpack/src/ReactFlightDOMServerNode.js', // react-server-dom-webpack/writer.node.server
'react-client/src/ReactFlightClientStream.js', // We can only type check this in streaming configurations.
+ 'react-devtools',
+ 'react-devtools-core',
+ 'react-devtools-shell',
+ 'react-devtools-shared',
'react-interactions',
],
isFlowTyped: true,
@@ -40,12 +45,17 @@ module.exports = [
],
paths: [
'react-dom',
+ 'react-dom/client',
'react-dom/unstable_testing',
'react-dom/src/server/ReactDOMFizzServerBrowser.js', // react-dom/server.browser
'react-server-dom-webpack',
'react-server-dom-webpack/writer.browser.server',
'react-server-dom-webpack/src/ReactFlightDOMServerBrowser.js', // react-server-dom-webpack/writer.browser.server
'react-client/src/ReactFlightClientStream.js', // We can only type check this in streaming configurations.
+ 'react-devtools',
+ 'react-devtools-core',
+ 'react-devtools-shell',
+ 'react-devtools-shared',
],
isFlowTyped: true,
isServerSupported: true,