42
React = require('react');
43
ReactDOM = require('react-dom');
44
ReactDOMFizzServer = require('react-dom/server.browser');
45
- if (__EXPERIMENTAL__) {
46
- ReactDOMFizzStatic = require('react-dom/static.browser');
47
- }
45
+ ReactDOMFizzStatic = require('react-dom/static.browser');
46
Suspense = React.Suspense;
47
container = document.createElement('div');
48
document.body.appendChild(container);
129
await insertNodesAndExecuteScripts(temp, container, null);
130
}
131
134
- // @gate experimental
132
it('should call prerender', async () => {
133
const result = await serverAct(() =>
134
ReactDOMFizzStatic.prerender(<div>hello world</div>),
137
expect(prelude).toMatchInlineSnapshot(`"<div>hello world</div>"`);
138
});
139
143
- // @gate experimental
140
it('should emit DOCTYPE at the root of the document', async () => {
141
const result = await serverAct(() =>
142
ReactDOMFizzStatic.prerender(
151
);
152
});
153
158
- // @gate experimental
154
it('should emit bootstrap script src at the end', async () => {
155
const result = await serverAct(() =>
156
ReactDOMFizzStatic.prerender(<div>hello world</div>, {
165
);
166
});
167
173
- // @gate experimental
168
it('emits all HTML as one unit', async () => {
169
let hasLoaded = false;
170
let resolve;
196
expect(prelude).toMatchInlineSnapshot(`"<div><!--$-->Done<!--/$--></div>"`);
197
});
198
205
- // @gate experimental
199
it('should reject the promise when an error is thrown at the root', async () => {
200
const reportedErrors = [];
201
let caughtError = null;
219
expect(reportedErrors).toEqual([theError]);
220
});
221
229
- // @gate experimental
222
it('should reject the promise when an error is thrown inside a fallback', async () => {
223
const reportedErrors = [];
224
let caughtError = null;
244
expect(reportedErrors).toEqual([theError]);
245
});
246
255
- // @gate experimental
247
it('should not error the stream when an error is thrown inside suspense boundary', async () => {
248
const reportedErrors = [];
249
const result = await serverAct(() =>
266
expect(reportedErrors).toEqual([theError]);
267
});
268
278
- // @gate experimental
269
it('should be able to complete by aborting even if the promise never resolves', async () => {
270
const errors = [];
271
const controller = new AbortController();
296
expect(errors).toEqual(['The operation was aborted.']);
297
});
298
309
- // @gate experimental
299
// @gate !enableHalt
300
it('should reject if aborting before the shell is complete and enableHalt is disabled', async () => {
301
const errors = [];
365
expect(content).toBe('');
366
});
367
379
- // @gate experimental
368
it('should be able to abort before something suspends', async () => {
369
const errors = [];
370
const controller = new AbortController();
407
}
408
});
409
422
- // @gate experimental
410
// @gate !enableHalt
411
it('should reject if passing an already aborted signal and enableHalt is disabled', async () => {
412
const errors = [];
480
expect(content).toBe('');
481
});
482
496
- // @gate experimental
483
it('supports custom abort reasons with a string', async () => {
484
const promise = new Promise(r => {});
485
function Wait() {
522
expect(errors).toEqual(['foobar', 'foobar']);
523
});
524
539
- // @gate experimental
525
it('supports custom abort reasons with an Error', async () => {
526
const promise = new Promise(r => {});
527
function Wait() {
1595
);
1596
});
1597
1613
- // @gate experimental
1598
it('logs an error if onHeaders throws but continues the prerender', async () => {
1599
const errors = [];
1600
function onError(error) {
1611
onError,
1612
}),
1613
);
1630
- expect(prerendered.postponed).toBe(null);
1614
+ expect(prerendered.postponed).toBe(
1615
+ gate(flags => flags.enableHalt || flags.enablePostpone)
1616
+ ? null
1617
+ : undefined,
1618
+ );
1619
expect(errors).toEqual(['bad onHeaders']);
1620
1621
await readIntoContainer(prerendered.prelude);