Skip to content

Commit 7dd5547

Browse files
author
Sebastian Silbermann
committed
Convert ReactDOMSuspensePlaceholder to createRoot
1 parent d29f7d9 commit 7dd5547

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

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

+22-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
let React;
1313
let ReactDOM;
14+
let ReactDOMClient;
1415
let Suspense;
1516
let Scheduler;
1617
let act;
@@ -23,6 +24,7 @@ describe('ReactDOMSuspensePlaceholder', () => {
2324
jest.resetModules();
2425
React = require('react');
2526
ReactDOM = require('react-dom');
27+
ReactDOMClient = require('react-dom/client');
2628
Scheduler = require('scheduler');
2729
act = require('internal-test-utils').act;
2830
Suspense = React.Suspense;
@@ -98,7 +100,7 @@ describe('ReactDOMSuspensePlaceholder', () => {
98100
return text;
99101
}
100102

101-
it('hides and unhides timed out DOM elements', async () => {
103+
it('hides and unhides timed out DOM elements in legacy roots', async () => {
102104
const divs = [
103105
React.createRef(null),
104106
React.createRef(null),
@@ -144,18 +146,22 @@ describe('ReactDOMSuspensePlaceholder', () => {
144146
</Suspense>
145147
);
146148
}
147-
ReactDOM.render(<App />, container);
149+
const root = ReactDOMClient.createRoot(container);
150+
await act(() => {
151+
root.render(<App />);
152+
});
153+
148154
expect(container.textContent).toEqual('Loading...');
149155

150-
await act(async () => {
151-
await resolveText('B');
156+
await act(() => {
157+
resolveText('B');
152158
});
153159

154160
expect(container.textContent).toEqual('ABC');
155161
});
156162

157163
it(
158-
'outside concurrent mode, re-hides children if their display is updated ' +
164+
'in legacy roots, re-hides children if their display is updated ' +
159165
'but the boundary is still showing the fallback',
160166
async () => {
161167
const {useState} = React;
@@ -207,7 +213,7 @@ describe('ReactDOMSuspensePlaceholder', () => {
207213
);
208214

209215
// Regression test for https://github.com/facebook/react/issues/14188
210-
it('can call findDOMNode() in a suspended component commit phase', async () => {
216+
it('can call findDOMNode() in a suspended component commit phase in legacy roots', async () => {
211217
const log = [];
212218
const Lazy = React.lazy(
213219
() =>
@@ -267,7 +273,7 @@ describe('ReactDOMSuspensePlaceholder', () => {
267273
});
268274

269275
// Regression test for https://github.com/facebook/react/issues/14188
270-
it('can call findDOMNode() in a suspended component commit phase (#2)', () => {
276+
it('can call legacy findDOMNode() in a suspended component commit phase (#2)', async () => {
271277
let suspendOnce = Promise.resolve();
272278
function Suspend() {
273279
if (suspendOnce) {
@@ -304,9 +310,16 @@ describe('ReactDOMSuspensePlaceholder', () => {
304310
);
305311
}
306312

307-
ReactDOM.render(<App />, container);
313+
const root = ReactDOMClient.createRoot(container);
314+
await act(() => {
315+
root.render(<App />);
316+
});
317+
308318
expect(log).toEqual(['cDM']);
309-
ReactDOM.render(<App />, container);
319+
await act(() => {
320+
root.render(<App />);
321+
});
322+
310323
expect(log).toEqual(['cDM', 'cDU']);
311324
});
312325
});

0 commit comments

Comments
 (0)