Skip to content

Commit

Permalink
ensure fallback bootstrap scripts get used in fallback cases
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff committed Jan 12, 2023
1 parent 728e6b2 commit 308599c
Show file tree
Hide file tree
Showing 3 changed files with 425 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2442,27 +2442,29 @@ export function writeEarlyPreamble(
// If we emitted a preamble early it will have flushed <html> and <head>.
// We check that we haven't flushed anything yet which is equivalent
// to checking whether we have not flushed an <html> or <head>
if (responseState.flushed === NONE && responseState.rendered !== NONE) {
let i = 0;
const {htmlChunks, headChunks} = responseState;
if (htmlChunks.length) {
for (i = 0; i < htmlChunks.length; i++) {
writeChunk(destination, htmlChunks[i]);
if (responseState.rendered !== NONE) {
if (responseState.flushed === NONE) {
let i = 0;
const {htmlChunks, headChunks} = responseState;
if (htmlChunks.length) {
for (i = 0; i < htmlChunks.length; i++) {
writeChunk(destination, htmlChunks[i]);
}
} else {
writeChunk(destination, DOCTYPE);
writeChunk(destination, startChunkForTag('html'));
writeChunk(destination, endOfStartTag);
}
} else {
writeChunk(destination, DOCTYPE);
writeChunk(destination, startChunkForTag('html'));
writeChunk(destination, endOfStartTag);
}
if (headChunks.length) {
for (i = 0; i < headChunks.length; i++) {
writeChunk(destination, headChunks[i]);
if (headChunks.length) {
for (i = 0; i < headChunks.length; i++) {
writeChunk(destination, headChunks[i]);
}
} else {
writeChunk(destination, startChunkForTag('head'));
writeChunk(destination, endOfStartTag);
}
} else {
writeChunk(destination, startChunkForTag('head'));
writeChunk(destination, endOfStartTag);
responseState.flushed |= HTML | HEAD;
}
responseState.flushed |= HTML | HEAD;

return writeEarlyResources(
destination,
Expand Down Expand Up @@ -2587,14 +2589,16 @@ export function prepareForFallback(responseState: ResponseState): void {
if (__DEV__) {
(responseState: any).inFallbackDEV = true;
}
// This function would ideally check somethign to see whether embedding
// was required however at the moment the only time we use a Request Fallback
// is when we use renderIntoDocument which is the only variant where which
// utilizes fallback children. We assume we're in that mode if this function
// is called and update the requirement accordingly
// Reset rendered states
responseState.htmlChunks = [];
responseState.headChunks = [];
responseState.rendered = NONE;

// Move fallback bootstrap to bootstrap if configured
const fallbackBootstrapChunks = responseState.fallbackBootstrapChunks;
if (fallbackBootstrapChunks && fallbackBootstrapChunks.length) {
responseState.bootstrapChunks = fallbackBootstrapChunks;
}
}

export function writeCompletedRoot(
Expand Down
Loading

0 comments on commit 308599c

Please sign in to comment.