Repository: facebook/react
File: packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js (JavaScript)

Code before:
  return (
    // There are no remaining boundaries which might contain a preamble so
    // the preamble is as complete as it is going to get
    hasPendingPreambles === false ||
    // we have a head and body tag. we don't need to wait for any more
    // because it would be invalid to render additional copies of these tags
    !!(preamble.headChunks && preamble.bodyChunks)
  );
}

function writeBootstrap(
  destination: Destination,
  renderState: RenderState,
): boolean {
  const bootstrapChunks = renderState.bootstrapChunks;
  let i = 0;
  for (; i < bootstrapChunks.length - 1; i++) {
    writeChunk(destination, bootstrapChunks[i]);
  }
  if (i < bootstrapChunks.length) {
    const lastChunk = bootstrapChunks[i];
    bootstrapChunks.length = 0;
    return writeChunkAndReturn(destination, lastChunk);
  }
  return true;
}

export function writeCompletedRoot(
  destination: Destination,
  resumableState: ResumableState,
  renderState: RenderState,
): boolean {
  const preamble = renderState.preamble;
  if (preamble.htmlChunks || preamble.headChunks) {
    // If we rendered the whole document, then we emitted a rel="expect" that needs a
    // matching target. Normally we use one of the bootstrap scripts for this but if
    // there are none, then we need to emit a tag to complete the shell.
    const bootstrapChunks = renderState.bootstrapChunks;
    if (bootstrapChunks.length === 0) {
      bootstrapChunks.push(startChunkForTag('template'));
      pushCompletedShellIdAttribute(bootstrapChunks, resumableState);
      bootstrapChunks.push(endOfStartTag, endChunkForTag('template'));
    }
  }
  return writeBootstrap(destination, renderState);
}

// Structural Nodes

// A placeholder is a node inside a hidden partial tree that can be filled in later, but before
// display. It's never visible to users. We use the template tag because it can be used in every

Review comment (suggestion):
The condition here isn't symmetrical with the one in `writePreambleStart`. Maybe that's ok because the ID is essentially reserved and inert without the associated expect link but if we want to actually be precise we need to know if we are in a mode that never emits the paint blocking link

Code after:
}

function writeBootstrap(
  destination: Destination,
  renderState: RenderState,
): boolean {
  const bootstrapChunks = renderState.bootstrapChunks;
  let i = 0;
  for (; i < bootstrapChunks.length - 1; i++) {
    writeChunk(destination, bootstrapChunks[i]);
  }
  if (i < bootstrapChunks.length) {
    const lastChunk = bootstrapChunks[i];
    bootstrapChunks.length = 0;
    return writeChunkAndReturn(destination, lastChunk);
  }
  return true;
}

export function writeCompletedRoot(
  destination: Destination,
  resumableState: ResumableState,
  renderState: RenderState,
): boolean {
  const preamble = renderState.preamble;
  if (preamble.htmlChunks || preamble.headChunks) {
    // If we rendered the whole document, then we emitted a rel="expect" that needs a
    // matching target. Normally we use one of the bootstrap scripts for this but if
    // there are none, then we need to emit a tag to complete the shell.
    if ((resumableState.instructions & SentCompletedShellId) === NothingSent) {
      const bootstrapChunks = renderState.bootstrapChunks;
      bootstrapChunks.push(startChunkForTag('template'));
      pushCompletedShellIdAttribute(bootstrapChunks, resumableState);
      bootstrapChunks.push(endOfStartTag, endChunkForTag('template'));
    }
  }
  return writeBootstrap(destination, renderState);
}

// Structural Nodes

// A placeholder is a node inside a hidden partial tree that can be filled in later, but before
// display. It's never visible to users. We use the template tag because it can be used in every
// type of parent. <script> tags also work in every other tag except <colgroup>.
const placeholder1 = stringToPrecomputedChunk('<template id="');
const placeholder2 = stringToPrecomputedChunk('"></template>');
export function writePlaceholder(
  destination: Destination,
  renderState: RenderState,
  id: number,
): boolean {