Skip to content

Commit 795541b

Browse files
committed
Now we can pipe Fizz into a container
1 parent 54ed2c0 commit 795541b

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ let Suspense;
1919
let textCache;
2020
let document;
2121
let writable;
22+
let container;
2223
let buffer = '';
2324
let hasErrored = false;
2425
let fatalError = undefined;
@@ -38,10 +39,14 @@ describe('ReactDOMFizzServer', () => {
3839
textCache = new Map();
3940

4041
// Test Environment
41-
const jsdom = new JSDOM('<!DOCTYPE html><html><head></head><body>', {
42-
runScripts: 'dangerously',
43-
});
42+
const jsdom = new JSDOM(
43+
'<!DOCTYPE html><html><head></head><body><div id="container">',
44+
{
45+
runScripts: 'dangerously',
46+
},
47+
);
4448
document = jsdom.window.document;
49+
container = document.getElementById('container');
4550

4651
buffer = '';
4752
hasErrored = false;
@@ -80,9 +85,9 @@ describe('ReactDOMFizzServer', () => {
8085
const script = document.createElement('script');
8186
script.textContent = node.textContent;
8287
fakeBody.removeChild(node);
83-
document.body.appendChild(script);
88+
container.appendChild(script);
8489
} else {
85-
document.body.appendChild(node);
90+
container.appendChild(node);
8691
}
8792
}
8893
}
@@ -200,11 +205,11 @@ describe('ReactDOMFizzServer', () => {
200205
writable,
201206
);
202207
});
203-
expect(getVisibleChildren(document.body)).toEqual(<div>Loading...</div>);
208+
expect(getVisibleChildren(container)).toEqual(<div>Loading...</div>);
204209
await act(async () => {
205210
resolveText('Hello World');
206211
});
207-
expect(getVisibleChildren(document.body)).toEqual(<div>Hello World</div>);
212+
expect(getVisibleChildren(container)).toEqual(<div>Hello World</div>);
208213
});
209214

210215
// @gate experimental
@@ -224,20 +229,12 @@ describe('ReactDOMFizzServer', () => {
224229
}
225230

226231
await act(async () => {
227-
ReactDOMFizzServer.pipeToNodeWritable(
228-
// We currently have to wrap the server node in a container because
229-
// otherwise the Fizz nodes get deleted during hydration.
230-
<div id="container">
231-
<App />
232-
</div>,
233-
writable,
234-
);
232+
ReactDOMFizzServer.pipeToNodeWritable(<App />, writable);
235233
});
236234

237235
// We're still showing a fallback.
238236

239237
// Attempt to hydrate the content.
240-
const container = document.body.firstChild;
241238
const root = ReactDOM.unstable_createRoot(container, {hydrate: true});
242239
root.render(<App />);
243240
Scheduler.unstable_flushAll();

0 commit comments

Comments
 (0)