@bgub/fig-server 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -591,6 +591,7 @@ function prefixedId(request, kind, id) {
591
591
  //#endregion
592
592
  //#region src/renderer-flush.ts
593
593
  const documentHeadMarker = Symbol("fig.document-head");
594
+ const shellDataMarkersSlot = Symbol("fig.shell-data-markers-slot");
594
595
  const leadingNewlineStartMarker = Symbol("fig.leading-newline-start");
595
596
  const leadingNewlineEndMarker = Symbol("fig.leading-newline-end");
596
597
  const RUNTIME_REF = "__figSSR";
@@ -604,8 +605,11 @@ function flushCompletedQueues(request) {
604
605
  try {
605
606
  sealHead(request);
606
607
  if (request.rootSegment.status !== "flushed") {
608
+ request.shellDataRows = claimShellDependencies(request);
609
+ if (request.documentHasHead === null) writeShellDataMarkers(request);
607
610
  flushSegment(request, request.rootSegment);
608
611
  request.pendingDataKeys?.clear();
612
+ writeDataRows(request, request.shellDataRows.splice(0));
609
613
  flushWriteBuffer(request);
610
614
  }
611
615
  if (!drainBoundaryQueue(request, request.clientRenderedBoundaries, flushClientRenderedBoundary) && !drainBoundaryQueue(request, request.completedBoundaries, flushCompletedBoundary)) drainBoundaryQueue(request, request.partialBoundaries, flushPartialBoundary);
@@ -736,6 +740,31 @@ function writeBoundaryRevealScript(request, boundary) {
736
740
  writeScript(request, withAssetGate(blockingIds, boundary.activityId === null ? `${RUNTIME_REF}.c(${boundaryRef},${contentRef}${metadataArgument})` : `${RUNTIME_REF}.ac(${jsString(boundary.activityId)},${boundaryRef},${contentRef}${metadataArgument})`));
737
741
  writeLateDataOperations(request, boundary);
738
742
  }
743
+ function claimShellDependencies(request) {
744
+ if (request.pendingDataKeys === null) return [];
745
+ const reads = /* @__PURE__ */ new Set();
746
+ collectShellReads(request.rootSegment, reads);
747
+ const rows = encodeDataRows(unqueuedData(request, request.dataStore.snapshotDependencies(reads)));
748
+ for (const row of rows) request.writtenDataKeys.add(normalizeDataResourceKey(row.key));
749
+ return rows;
750
+ }
751
+ function collectShellReads(segment, reads) {
752
+ if (segment.boundary?.status === "completed") {
753
+ for (const completed of segment.boundary.completedSegments) collectShellReads(completed, reads);
754
+ return;
755
+ }
756
+ for (const key of segment.dataKeys ?? []) reads.add(key);
757
+ for (const child of segment.children) collectShellReads(child, reads);
758
+ }
759
+ function writeShellDataMarkers(request) {
760
+ const rows = request.shellDataRows;
761
+ if (rows.length === 0) return;
762
+ writeRuntime(request);
763
+ writeDataRows(request, rows.map((row) => ({
764
+ key: row.key,
765
+ pending: true
766
+ })));
767
+ }
739
768
  function takeData(request) {
740
769
  return [...[...new Set(request.queuedDataRows.values())].flatMap((batch) => decodePayloadDataEntries(takeQueuedDataBatch(request, batch))), ...claimData(request, request.dataStore.snapshot())];
741
770
  }
@@ -905,6 +934,10 @@ function writeChunk(request, chunk, segment) {
905
934
  request.write(request.leadingNewlineStack.at(-1) === false && chunk.value.startsWith("\n") ? `\n${chunk.value}` : chunk.value);
906
935
  return;
907
936
  }
937
+ if (chunk === shellDataMarkersSlot) {
938
+ writeShellDataMarkers(request);
939
+ return;
940
+ }
908
941
  if (chunk !== documentHeadMarker) {
909
942
  request.write(chunk);
910
943
  return;
@@ -958,6 +991,7 @@ function createServerRenderRequest(node, options, mode) {
958
991
  streamDataFilter: typeof options.streamData === "object" ? options.streamData.filter ?? null : null,
959
992
  writtenDataKeys: /* @__PURE__ */ new Set(),
960
993
  queuedDataRows: /* @__PURE__ */ new Map(),
994
+ shellDataRows: [],
961
995
  dispose: disposeRequest,
962
996
  abortReason: null,
963
997
  identifierPrefix,
@@ -1506,7 +1540,10 @@ function renderHostElement(type, props, frame) {
1506
1540
  consumePendingLeadingNewline(frame);
1507
1541
  const viewTransition = frame.viewTransition;
1508
1542
  writeElementStart(type, viewTransition === null ? props : viewTransitionHostProps(props, viewTransition), frame.segment, frame.selectProps);
1509
- if (isDocumentHead) frame.segment.write(earlyEventCaptureMarkup(frame.request));
1543
+ if (isDocumentHead) {
1544
+ frame.segment.write(earlyEventCaptureMarkup(frame.request));
1545
+ frame.segment.write(shellDataMarkersSlot);
1546
+ }
1510
1547
  if (isVoid) return;
1511
1548
  const previousPendingLeadingNewline = frame.pendingLeadingNewline;
1512
1549
  const tracksLeadingNewline = type === "pre" || type === "textarea";