Skip to content

Commit fe7e9b2

Browse files
committed
Always load the external runtime if one is provided
1 parent ee7fee8 commit fe7e9b2

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5089,15 +5089,10 @@ export function writePreambleStart(
50895089
destination: Destination,
50905090
resumableState: ResumableState,
50915091
renderState: RenderState,
5092-
willFlushAllSegments: boolean,
50935092
skipExpect?: boolean, // Used as an override by ReactFizzConfigMarkup
50945093
): void {
50955094
// This function must be called exactly once on every request
5096-
if (
5097-
enableFizzExternalRuntime &&
5098-
!willFlushAllSegments &&
5099-
renderState.externalRuntimeScript
5100-
) {
5095+
if (enableFizzExternalRuntime && renderState.externalRuntimeScript) {
51015096
// If the root segment is incomplete due to suspended tasks
51025097
// (e.g. willFlushAllSegments = false) and we are using data
51035098
// streaming format, ensure the external runtime is sent.

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3587,6 +3587,9 @@ describe('ReactDOMFizzServer', () => {
35873587
'<script type="importmap">' +
35883588
JSON.stringify(importMap) +
35893589
'</script><script async="" src="foo"></script>' +
3590+
(gate(flags => flags.shouldUseFizzExternalRuntime)
3591+
? '<script src="react-dom-bindings/src/server/ReactDOMServerExternalRuntime.js" async=""></script>'
3592+
: '') +
35903593
'<link rel="expect" href="#«R»" blocking="render">',
35913594
);
35923595
});
@@ -4501,7 +4504,7 @@ describe('ReactDOMFizzServer', () => {
45014504
expect(document.getElementsByTagName('script').length).toEqual(1);
45024505
});
45034506

4504-
it('does not send the external runtime for static pages', async () => {
4507+
it('does (unfortunately) send the external runtime for static pages', async () => {
45054508
await act(() => {
45064509
const {pipe} = renderToPipeableStream(
45074510
<html>
@@ -4515,11 +4518,11 @@ describe('ReactDOMFizzServer', () => {
45154518
});
45164519

45174520
// no scripts should be sent
4518-
expect(document.getElementsByTagName('script').length).toEqual(0);
4521+
expect(document.getElementsByTagName('script').length).toEqual(1);
45194522

45204523
// the html should be as-is
45214524
expect(document.documentElement.innerHTML).toEqual(
4522-
'<head><link rel="expect" href="#«R»" blocking="render"></head><body><p>hello world!</p><template id="«R»"></template></body>',
4525+
'<head><script src="react-dom-bindings/src/server/ReactDOMServerExternalRuntime.js" async=""></script><link rel="expect" href="#«R»" blocking="render"></head><body><p>hello world!</p><template id="«R»"></template></body>',
45234526
);
45244527
});
45254528

@@ -5317,7 +5320,9 @@ describe('ReactDOMFizzServer', () => {
53175320
});
53185321

53195322
expect(container.innerHTML).toEqual(
5320-
'<div>hello<b>world, <!-- -->Foo</b>!</div>',
5323+
(gate(flags => flags.shouldUseFizzExternalRuntime)
5324+
? '<script src="react-dom-bindings/src/server/ReactDOMServerExternalRuntime.js" async=""></script>'
5325+
: '') + '<div>hello<b>world, <!-- -->Foo</b>!</div>',
53215326
);
53225327
const errors = [];
53235328
ReactDOMClient.hydrateRoot(container, <App name="Foo" />, {
@@ -5518,7 +5523,7 @@ describe('ReactDOMFizzServer', () => {
55185523
pipe(writable);
55195524
});
55205525

5521-
expect(container.firstElementChild.outerHTML).toEqual(
5526+
expect(container.lastElementChild.outerHTML).toEqual(
55225527
'<div>hello<b>world<!-- --></b></div>',
55235528
);
55245529

@@ -5556,7 +5561,7 @@ describe('ReactDOMFizzServer', () => {
55565561
pipe(writable);
55575562
});
55585563

5559-
expect(container.firstElementChild.outerHTML).toEqual(
5564+
expect(container.lastElementChild.outerHTML).toEqual(
55605565
'<div>hello<b>world</b></div>',
55615566
);
55625567

@@ -5696,7 +5701,10 @@ describe('ReactDOMFizzServer', () => {
56965701
});
56975702

56985703
expect(container.innerHTML).toEqual(
5699-
'<div><!--$-->hello<!-- -->world<!-- --><!--/$--><!--$-->world<!-- --><!--/$--><!--$-->hello<!-- -->world<!-- --><br><!--/$--><!--$-->world<!-- --><br><!--/$--></div>',
5704+
(gate(flags => flags.shouldUseFizzExternalRuntime)
5705+
? '<script src="react-dom-bindings/src/server/ReactDOMServerExternalRuntime.js" async=""></script>'
5706+
: '') +
5707+
'<div><!--$-->hello<!-- -->world<!-- --><!--/$--><!--$-->world<!-- --><!--/$--><!--$-->hello<!-- -->world<!-- --><br><!--/$--><!--$-->world<!-- --><br><!--/$--></div>',
57005708
);
57015709

57025710
const errors = [];
@@ -6499,7 +6507,11 @@ describe('ReactDOMFizzServer', () => {
64996507
});
65006508

65016509
expect(document.documentElement.outerHTML).toEqual(
6502-
'<html><head><link rel="expect" href="#«R»" blocking="render"></head><body><script>try { foo() } catch (e) {} ;</script><template id="«R»"></template></body></html>',
6510+
'<html><head>' +
6511+
(gate(flags => flags.shouldUseFizzExternalRuntime)
6512+
? '<script src="react-dom-bindings/src/server/ReactDOMServerExternalRuntime.js" async=""></script>'
6513+
: '') +
6514+
'<link rel="expect" href="#«R»" blocking="render"></head><body><script>try { foo() } catch (e) {} ;</script><template id="«R»"></template></body></html>',
65036515
);
65046516
});
65056517

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,9 @@ describe('ReactDOMFloat', () => {
701701
});
702702
expect(chunks).toEqual([
703703
'<!DOCTYPE html><html><head><script async="" src="foo"></script>' +
704+
(gate(flags => flags.shouldUseFizzExternalRuntime)
705+
? '<script src="react-dom-bindings/src/server/ReactDOMServerExternalRuntime.js" async=""></script>'
706+
: '') +
704707
'<link rel="expect" href="#«R»" blocking="render"/><title>foo</title></head>' +
705708
'<body>bar<template id="«R»"></template>',
706709
'</body></html>',

packages/react-markup/src/ReactFizzConfigMarkup.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,12 @@ export function writePreambleStart(
208208
destination: Destination,
209209
resumableState: ResumableState,
210210
renderState: RenderState,
211-
willFlushAllSegments: boolean,
212211
skipExpect?: boolean, // Used as an override by ReactFizzConfigMarkup
213212
): void {
214213
return writePreambleStartImpl(
215214
destination,
216215
resumableState,
217216
renderState,
218-
willFlushAllSegments,
219217
true, // skipExpect
220218
);
221219
}

packages/react-server/src/ReactFizzServer.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4835,14 +4835,7 @@ function flushPreamble(
48354835
preambleSegments: Array<Array<Segment>>,
48364836
) {
48374837
// The preamble is ready.
4838-
const willFlushAllSegments =
4839-
request.allPendingTasks === 0 && request.trackedPostpones === null;
4840-
writePreambleStart(
4841-
destination,
4842-
request.resumableState,
4843-
request.renderState,
4844-
willFlushAllSegments,
4845-
);
4838+
writePreambleStart(destination, request.resumableState, request.renderState);
48464839
for (let i = 0; i < preambleSegments.length; i++) {
48474840
const segments = preambleSegments[i];
48484841
for (let j = 0; j < segments.length; j++) {

0 commit comments

Comments
 (0)