Skip to content

Commit 45a1577

Browse files
committed
ensure fallback bootstrap scripts get used in fallback cases
1 parent 307c090 commit 45a1577

File tree

7 files changed

+480
-26
lines changed

7 files changed

+480
-26
lines changed

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,27 +2442,29 @@ export function writeEarlyPreamble(
24422442
// If we emitted a preamble early it will have flushed <html> and <head>.
24432443
// We check that we haven't flushed anything yet which is equivalent
24442444
// to checking whether we have not flushed an <html> or <head>
2445-
if (responseState.flushed === NONE && responseState.rendered !== NONE) {
2446-
let i = 0;
2447-
const {htmlChunks, headChunks} = responseState;
2448-
if (htmlChunks.length) {
2449-
for (i = 0; i < htmlChunks.length; i++) {
2450-
writeChunk(destination, htmlChunks[i]);
2445+
if (responseState.rendered !== NONE) {
2446+
if (responseState.flushed === NONE) {
2447+
let i = 0;
2448+
const {htmlChunks, headChunks} = responseState;
2449+
if (htmlChunks.length) {
2450+
for (i = 0; i < htmlChunks.length; i++) {
2451+
writeChunk(destination, htmlChunks[i]);
2452+
}
2453+
} else {
2454+
writeChunk(destination, DOCTYPE);
2455+
writeChunk(destination, startChunkForTag('html'));
2456+
writeChunk(destination, endOfStartTag);
24512457
}
2452-
} else {
2453-
writeChunk(destination, DOCTYPE);
2454-
writeChunk(destination, startChunkForTag('html'));
2455-
writeChunk(destination, endOfStartTag);
2456-
}
2457-
if (headChunks.length) {
2458-
for (i = 0; i < headChunks.length; i++) {
2459-
writeChunk(destination, headChunks[i]);
2458+
if (headChunks.length) {
2459+
for (i = 0; i < headChunks.length; i++) {
2460+
writeChunk(destination, headChunks[i]);
2461+
}
2462+
} else {
2463+
writeChunk(destination, startChunkForTag('head'));
2464+
writeChunk(destination, endOfStartTag);
24602465
}
2461-
} else {
2462-
writeChunk(destination, startChunkForTag('head'));
2463-
writeChunk(destination, endOfStartTag);
2466+
responseState.flushed |= HTML | HEAD;
24642467
}
2465-
responseState.flushed |= HTML | HEAD;
24662468

24672469
return writeEarlyResources(
24682470
destination,
@@ -2587,14 +2589,16 @@ export function prepareForFallback(responseState: ResponseState): void {
25872589
if (__DEV__) {
25882590
(responseState: any).inFallbackDEV = true;
25892591
}
2590-
// This function would ideally check somethign to see whether embedding
2591-
// was required however at the moment the only time we use a Request Fallback
2592-
// is when we use renderIntoDocument which is the only variant where which
2593-
// utilizes fallback children. We assume we're in that mode if this function
2594-
// is called and update the requirement accordingly
2592+
// Reset rendered states
25952593
responseState.htmlChunks = [];
25962594
responseState.headChunks = [];
25972595
responseState.rendered = NONE;
2596+
2597+
// Move fallback bootstrap to bootstrap if configured
2598+
const fallbackBootstrapChunks = responseState.fallbackBootstrapChunks;
2599+
if (fallbackBootstrapChunks && fallbackBootstrapChunks.length) {
2600+
responseState.bootstrapChunks = fallbackBootstrapChunks;
2601+
}
25982602
}
25992603

26002604
export function writeCompletedRoot(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export type ResponseState = {
4444
requiresEmbedding: boolean,
4545
rendered: DocumentStructureTag,
4646
flushed: DocumentStructureTag,
47+
charsetChunks: Array<Chunk | PrecomputedChunk>,
48+
hoistableChunks: Array<Chunk | PrecomputedChunk>,
4749
placeholderPrefix: PrecomputedChunk,
4850
segmentPrefix: PrecomputedChunk,
4951
boundaryPrefix: string,
@@ -87,6 +89,8 @@ export function createResponseState(
8789
requiresEmbedding: false,
8890
rendered: NONE,
8991
flushed: NONE,
92+
charsetChunks: [],
93+
hoistableChunks: [],
9094
placeholderPrefix: responseState.placeholderPrefix,
9195
segmentPrefix: responseState.segmentPrefix,
9296
boundaryPrefix: responseState.boundaryPrefix,

0 commit comments

Comments
 (0)