MCPcopy
hub / github.com/facebook/react / replaySuspenseBoundary

Function replaySuspenseBoundary

packages/react-server/src/ReactFizzServer.js:1621–1795  ·  view source on GitHub ↗
(
  request: Request,
  task: ReplayTask,
  keyPath: KeyNode,
  props: Object,
  id: number,
  childNodes: Array<ReplayNode>,
  childSlots: ResumeSlots,
  fallbackNodes: Array<ReplayNode>,
  fallbackSlots: ResumeSlots,
)

Source from the content-addressed store, hash-verified

1619}
1620
1621function replaySuspenseBoundary(
1622 request: Request,
1623 task: ReplayTask,
1624 keyPath: KeyNode,
1625 props: Object,
1626 id: number,
1627 childNodes: Array<ReplayNode>,
1628 childSlots: ResumeSlots,
1629 fallbackNodes: Array<ReplayNode>,
1630 fallbackSlots: ResumeSlots,
1631): void {
1632 const prevKeyPath = task.keyPath;
1633 const prevContext = task.formatContext;
1634 const prevRow = task.row;
1635 const previousReplaySet: ReplaySet = task.replay;
1636
1637 const parentBoundary = task.blockedBoundary;
1638 const parentHoistableState = task.hoistableState;
1639
1640 const content: ReactNodeList = props.children;
1641 const fallback: ReactNodeList = props.fallback;
1642
1643 const fallbackAbortSet: Set<Task> = new Set();
1644 let resumedBoundary: SuspenseBoundary;
1645 if (canHavePreamble(task.formatContext)) {
1646 resumedBoundary = createSuspenseBoundary(
1647 request,
1648 task.row,
1649 fallbackAbortSet,
1650 createPreambleState(),
1651 createPreambleState(),
1652 );
1653 } else {
1654 resumedBoundary = createSuspenseBoundary(
1655 request,
1656 task.row,
1657 fallbackAbortSet,
1658 null,
1659 null,
1660 );
1661 }
1662 resumedBoundary.parentFlushed = true;
1663 // We restore the same id of this boundary as was used during prerender.
1664 resumedBoundary.rootSegmentID = id;
1665
1666 // We can reuse the current context and task to render the content immediately without
1667 // context switching. We just need to temporarily switch which boundary and replay node
1668 // we're writing to. If something suspends, it'll spawn new suspended task with that context.
1669 task.blockedBoundary = resumedBoundary;
1670 task.hoistableState = resumedBoundary.contentState;
1671 task.keyPath = keyPath;
1672 task.formatContext = getSuspenseContentFormatContext(
1673 request.resumableState,
1674 prevContext,
1675 );
1676 task.row = null;
1677 task.replay = {nodes: childNodes, slots: childSlots, pendingTasks: 1};
1678

Callers 1

replayElementFunction · 0.85

Calls 14

canHavePreambleFunction · 0.90
createPreambleStateFunction · 0.90
createSuspenseBoundaryFunction · 0.85
renderNodeFunction · 0.85
getThrownInfoFunction · 0.85
encodeErrorForBoundaryFunction · 0.85
createReplayTaskFunction · 0.85
pushComponentStackFunction · 0.85
logPostponeFunction · 0.70

Tested by

no test coverage detected