@bgub/fig-server 0.1.0-alpha.6 → 0.1.0-alpha.7
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/escaping-C2DNLoj9.js +34 -0
- package/dist/escaping-C2DNLoj9.js.map +1 -0
- package/dist/html-entry.js +1 -1
- package/dist/{image-preloads-BIFcrqm9.js → image-preloads-CWbCdmNa.js} +44 -46
- package/dist/image-preloads-CWbCdmNa.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +363 -448
- package/dist/index.js.map +1 -1
- package/dist/payload.d.ts +1 -1
- package/dist/payload.js +163 -183
- package/dist/payload.js.map +1 -1
- package/dist/{types-mrjoQDOc.d.ts → types-CZvaho7_.d.ts} +1 -1
- package/dist-development/escaping-C2DNLoj9.js +34 -0
- package/dist-development/escaping-C2DNLoj9.js.map +1 -0
- package/dist-development/html-entry.js +1 -1
- package/dist-development/{image-preloads-D3OBEaWp.js → image-preloads-C7OgNxdv.js} +44 -46
- package/dist-development/image-preloads-C7OgNxdv.js.map +1 -0
- package/dist-development/index.js +363 -448
- package/dist-development/index.js.map +1 -1
- package/dist-development/payload.js +162 -182
- package/dist-development/payload.js.map +1 -1
- package/package.json +3 -3
- package/dist/escaping-DAot8sFu.js +0 -26
- package/dist/escaping-DAot8sFu.js.map +0 -1
- package/dist/image-preloads-BIFcrqm9.js.map +0 -1
- package/dist-development/escaping-DAot8sFu.js +0 -26
- package/dist-development/escaping-DAot8sFu.js.map +0 -1
- package/dist-development/image-preloads-D3OBEaWp.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { i as escapeText, n as escapeScriptJson, t as escapeAttribute } from "./escaping-
|
|
2
|
-
import { a as
|
|
1
|
+
import { i as escapeText, n as escapeScriptJson, t as escapeAttribute } from "./escaping-C2DNLoj9.js";
|
|
2
|
+
import { a as createStaticDispatcher, c as nonceAttribute, d as streamFlowBlocked, f as streamHighWaterMark, i as cloneContextValues, l as noop, n as suppressesImagePreloads, o as deferred, p as withContextValue, r as STREAMED_METADATA_ATTRIBUTE, s as noLane, t as imagePreloadFromHostProps, u as serverErrorPayload } from "./image-preloads-C7OgNxdv.js";
|
|
3
3
|
import { Fragment, createElement, isValidElement } from "@bgub/fig";
|
|
4
|
-
import { ACTIVITY_TEMPLATE_ATTRIBUTE, EARLY_EVENT_HANDLER_PROPERTY, EARLY_EVENT_QUEUE_PROPERTY, HYDRATION_SKIP_ATTRIBUTE, REPLAYABLE_EVENT_TYPES, SUSPENSE_CLIENT_MARKER, SUSPENSE_COMPLETED_MARKER, SUSPENSE_END_MARKER, SUSPENSE_MARKER_PREFIX, SUSPENSE_PENDING_PREFIX, TEXT_SEPARATOR_DATA, VIEW_TRANSITION_CLASS_ATTRIBUTE, VIEW_TRANSITION_NAME_ATTRIBUTE, VIEW_TRANSITION_PENDING_PROPERTY, VIEW_TRANSITION_TIMEOUT_MS, assetResourceFromHostProps,
|
|
4
|
+
import { ACTIVITY_TEMPLATE_ATTRIBUTE, EARLY_EVENT_HANDLER_PROPERTY, EARLY_EVENT_QUEUE_PROPERTY, HYDRATION_SKIP_ATTRIBUTE, REPLAYABLE_EVENT_TYPES, SUSPENSE_CLIENT_MARKER, SUSPENSE_COMPLETED_MARKER, SUSPENSE_END_MARKER, SUSPENSE_MARKER_PREFIX, SUSPENSE_PENDING_PREFIX, TEXT_SEPARATOR_DATA, VIEW_TRANSITION_CLASS_ATTRIBUTE, VIEW_TRANSITION_NAME_ATTRIBUTE, VIEW_TRANSITION_PENDING_PROPERTY, VIEW_TRANSITION_TIMEOUT_MS, assetResourceFromHostProps, assetResourceHostProps, assetResourceKey, attachDataStore, collectChildren, createRendererDataStore, invalidChildError, isActivity, isAssets, isClientReference, isContext, isErrorBoundary, isFigAssetResource, isPortal, isSuspense, isThenable, isViewTransition, readThenable, setCurrentDataStore, setCurrentDispatcher, validateInstanceNesting, validateTextNesting } from "@bgub/fig/internal";
|
|
5
5
|
//#region src/html.ts
|
|
6
6
|
const voidElements = /* @__PURE__ */ new Set([
|
|
7
7
|
"area",
|
|
@@ -19,12 +19,19 @@ const voidElements = /* @__PURE__ */ new Set([
|
|
|
19
19
|
"track",
|
|
20
20
|
"wbr"
|
|
21
21
|
]);
|
|
22
|
+
const attributeNamePattern = /[\s"'<>/=]/;
|
|
23
|
+
const eventPropPattern = /^on[A-Z]/;
|
|
24
|
+
const styleNamePattern = /[A-Z]/g;
|
|
25
|
+
const tagNamePattern = /^[A-Za-z][A-Za-z0-9:._-]*$/;
|
|
26
|
+
function hyphenateStyleLetter(letter) {
|
|
27
|
+
return `-${letter.toLowerCase()}`;
|
|
28
|
+
}
|
|
22
29
|
function writeText(value, sink) {
|
|
23
30
|
sink.write(escapeText(value));
|
|
24
31
|
}
|
|
25
|
-
function writeElementStart(type, props, sink,
|
|
32
|
+
function writeElementStart(type, props, sink, selectProps = null) {
|
|
26
33
|
validateTagName(type);
|
|
27
|
-
sink.write(`<${type}${serializeAttributes(type, props,
|
|
34
|
+
sink.write(`<${type}${serializeAttributes(type, props, selectProps)}>`);
|
|
28
35
|
}
|
|
29
36
|
function writeElementEnd(type, sink) {
|
|
30
37
|
sink.write(`</${type}>`);
|
|
@@ -35,7 +42,7 @@ function isVoidElement(type) {
|
|
|
35
42
|
function hasRenderableChild(node) {
|
|
36
43
|
if (Array.isArray(node)) return node.some(hasRenderableChild);
|
|
37
44
|
if (isPortal(node)) return false;
|
|
38
|
-
return
|
|
45
|
+
return node !== null && node !== void 0 && typeof node !== "boolean";
|
|
39
46
|
}
|
|
40
47
|
function formTextContent(type, props) {
|
|
41
48
|
if (type !== "textarea") return null;
|
|
@@ -47,7 +54,7 @@ function unsafeHTMLContent(props) {
|
|
|
47
54
|
if (typeof value === "string") return value;
|
|
48
55
|
throw new Error("The unsafeHTML prop must be a string during server render.");
|
|
49
56
|
}
|
|
50
|
-
function serializeAttributes(type, props,
|
|
57
|
+
function serializeAttributes(type, props, selectProps) {
|
|
51
58
|
let attributes = "";
|
|
52
59
|
for (const name of Object.keys(props)) {
|
|
53
60
|
const value = props[name];
|
|
@@ -61,14 +68,15 @@ function serializeAttributes(type, props, inheritedProps) {
|
|
|
61
68
|
}
|
|
62
69
|
attributes += serializeProp(type, name, value);
|
|
63
70
|
}
|
|
64
|
-
if (type === "option" && props.selected === void 0 && optionSelected(optionValue(props),
|
|
71
|
+
if (type === "option" && props.selected === void 0 && optionSelected(optionValue(props), selectProps)) attributes += " selected";
|
|
65
72
|
return attributes;
|
|
66
73
|
}
|
|
67
74
|
function serializeProp(type, name, value) {
|
|
68
|
-
|
|
75
|
+
const isValueProp = name === "value" || name === "defaultValue";
|
|
76
|
+
if ((type === "textarea" || type === "select") && isValueProp) return "";
|
|
69
77
|
let attributeName = name;
|
|
70
78
|
let attributeValue = value;
|
|
71
|
-
if (
|
|
79
|
+
if (isValueProp) {
|
|
72
80
|
attributeName = "value";
|
|
73
81
|
if (serializableAttributeValue(value)) attributeValue = String(value);
|
|
74
82
|
} else if (name === "defaultChecked") {
|
|
@@ -82,11 +90,14 @@ function serializeProp(type, name, value) {
|
|
|
82
90
|
throw new Error(`Cannot serialize prop "${name}" to HTML.`);
|
|
83
91
|
}
|
|
84
92
|
function optionSelected(value, selectProps) {
|
|
93
|
+
if (selectProps === null) return false;
|
|
85
94
|
const selectValue = selectProps.value !== void 0 ? selectProps.value : selectProps.defaultValue;
|
|
86
95
|
if (emptyValue(selectValue)) return false;
|
|
87
96
|
const optionValue = formString(value);
|
|
88
97
|
if (optionValue === null) return false;
|
|
89
|
-
return
|
|
98
|
+
if (!Array.isArray(selectValue)) return String(selectValue) === optionValue;
|
|
99
|
+
for (const selectedValue of selectValue) if (String(selectedValue) === optionValue) return true;
|
|
100
|
+
return false;
|
|
90
101
|
}
|
|
91
102
|
function optionValue(props) {
|
|
92
103
|
return props.value === void 0 ? optionTextValue(props.children) : formString(props.value);
|
|
@@ -109,26 +120,22 @@ function formString(value) {
|
|
|
109
120
|
if (serializableAttributeValue(value)) return String(value);
|
|
110
121
|
return null;
|
|
111
122
|
}
|
|
112
|
-
function selectedValueSet(value) {
|
|
113
|
-
return new Set(Array.isArray(value) ? value.map(String) : [String(value)]);
|
|
114
|
-
}
|
|
115
123
|
function serializableAttributeValue(value) {
|
|
116
124
|
return value === true || typeof value === "string" || typeof value === "number" || typeof value === "bigint";
|
|
117
125
|
}
|
|
118
126
|
function emptyValue(value) {
|
|
119
127
|
return value === null || value === void 0 || value === false;
|
|
120
128
|
}
|
|
121
|
-
function emptyChild(value) {
|
|
122
|
-
return value === null || value === void 0 || typeof value === "boolean";
|
|
123
|
-
}
|
|
124
129
|
function serializeAttribute(name, value) {
|
|
125
130
|
return ` ${name}="${escapeAttribute(value)}"`;
|
|
126
131
|
}
|
|
127
132
|
function serializeStyle(value) {
|
|
128
133
|
if (emptyValue(value)) return "";
|
|
129
134
|
if (typeof value !== "object" || value === null) throw new Error("The style prop must be an object during server render.");
|
|
135
|
+
const styles = value;
|
|
130
136
|
let serialized = "";
|
|
131
|
-
for (const
|
|
137
|
+
for (const name of Object.keys(styles)) {
|
|
138
|
+
const item = styles[name];
|
|
132
139
|
if (emptyValue(item)) continue;
|
|
133
140
|
if (typeof item !== "string" && typeof item !== "number" && typeof item !== "bigint") throw new Error(`Cannot serialize style property "${name}" to HTML.`);
|
|
134
141
|
if (serialized !== "") serialized += ";";
|
|
@@ -137,20 +144,17 @@ function serializeStyle(value) {
|
|
|
137
144
|
return serialized;
|
|
138
145
|
}
|
|
139
146
|
function reservedProp(name) {
|
|
140
|
-
return name === "children" || name === "key" || name === "mix" || name === "bind" || name === "suppressHydrationWarning" || name === "unsafeHTML" ||
|
|
141
|
-
}
|
|
142
|
-
function valueProp(name) {
|
|
143
|
-
return name === "value" || name === "defaultValue";
|
|
147
|
+
return name === "children" || name === "key" || name === "mix" || name === "bind" || name === "suppressHydrationWarning" || name === "unsafeHTML" || eventPropPattern.test(name);
|
|
144
148
|
}
|
|
145
149
|
function styleName(name) {
|
|
146
150
|
if (name.startsWith("--")) return name;
|
|
147
|
-
return name.replace(
|
|
151
|
+
return name.replace(styleNamePattern, hyphenateStyleLetter);
|
|
148
152
|
}
|
|
149
153
|
function validateTagName(name) {
|
|
150
|
-
if (
|
|
154
|
+
if (!tagNamePattern.test(name)) throw new Error(`Invalid HTML tag name "${name}".`);
|
|
151
155
|
}
|
|
152
156
|
function validateAttributeName(name) {
|
|
153
|
-
if (
|
|
157
|
+
if (attributeNamePattern.test(name)) throw new Error(`Invalid HTML attribute name "${name}".`);
|
|
154
158
|
}
|
|
155
159
|
//#endregion
|
|
156
160
|
//#region src/preload-header.ts
|
|
@@ -158,23 +162,30 @@ const DEFAULT_LENGTH = 2e3;
|
|
|
158
162
|
const HEX_ESCAPE = /^[0-9A-Fa-f]{2}$/;
|
|
159
163
|
const PARAMETER_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
160
164
|
const URI_REFERENCE_PUNCTUATION = "-._~:/?#[]@!$&'()*+,;=";
|
|
161
|
-
function createPreloadHeaderEntries(resources
|
|
165
|
+
function createPreloadHeaderEntries(resources) {
|
|
166
|
+
const entries = [];
|
|
167
|
+
for (const resource of resources) {
|
|
168
|
+
if (!isServerPreloadHeaderResource(resource)) continue;
|
|
169
|
+
const value = preloadHeaderValue(resource);
|
|
170
|
+
if (value !== null) entries.push({
|
|
171
|
+
resource,
|
|
172
|
+
value
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return entries;
|
|
176
|
+
}
|
|
177
|
+
function snapshotPreloadHeaderResources(resources, isEarlyImage) {
|
|
162
178
|
const preconnects = [];
|
|
163
179
|
const criticalPreloads = [];
|
|
164
180
|
const stylesheets = [];
|
|
165
181
|
const remaining = [];
|
|
166
182
|
for (const resource of resources) {
|
|
167
183
|
if (!isServerPreloadHeaderResource(resource)) continue;
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
};
|
|
174
|
-
if (resource.kind === "preconnect") preconnects.push(entry);
|
|
175
|
-
else if (resource.kind === "font" || resource.kind === "preload" && (resource.as === "font" || resource.as === "image" && (resource.fetchpriority === "high" || isEarlyImage?.(resource) === true))) criticalPreloads.push(entry);
|
|
176
|
-
else if (resource.kind === "stylesheet") stylesheets.push(entry);
|
|
177
|
-
else remaining.push(entry);
|
|
184
|
+
const snapshot = { ...resource };
|
|
185
|
+
if (resource.kind === "preconnect") preconnects.push(snapshot);
|
|
186
|
+
else if (resource.kind === "font" || resource.kind === "preload" && (resource.as === "font" || resource.as === "image" && (resource.fetchpriority === "high" || isEarlyImage?.(resource) === true))) criticalPreloads.push(snapshot);
|
|
187
|
+
else if (resource.kind === "stylesheet") stylesheets.push(snapshot);
|
|
188
|
+
else remaining.push(snapshot);
|
|
178
189
|
}
|
|
179
190
|
return [
|
|
180
191
|
...preconnects,
|
|
@@ -308,18 +319,17 @@ var AssetResourceRegistry = class {
|
|
|
308
319
|
}
|
|
309
320
|
register(resource) {
|
|
310
321
|
if (isMetadataResource(resource)) return;
|
|
311
|
-
this.canonical(resource);
|
|
322
|
+
this.canonical(assetResourceKey(resource), resource);
|
|
312
323
|
}
|
|
313
324
|
registerAutomaticImage(resource) {
|
|
314
|
-
const
|
|
325
|
+
const key = assetResourceKey(resource);
|
|
326
|
+
const current = this.canonical(key, resource);
|
|
315
327
|
if (this.earlyImageKeys.size < 10 || current.kind === "preload" && current.as === "image" && current.fetchpriority === "high") this.earlyImageKeys.add(key);
|
|
316
328
|
}
|
|
317
|
-
isEarlyImage(resource) {
|
|
318
|
-
return this.earlyImageKeys.has(assetResourceKey(resource));
|
|
319
|
-
}
|
|
320
329
|
activateMetadata(owner, resources) {
|
|
321
|
-
|
|
322
|
-
if (metadata
|
|
330
|
+
let metadata = null;
|
|
331
|
+
for (const resource of resources) if (isMetadataResource(resource)) (metadata ??= []).push(resource);
|
|
332
|
+
if (metadata === null) {
|
|
323
333
|
this.metadataByOwner.delete(owner);
|
|
324
334
|
return;
|
|
325
335
|
}
|
|
@@ -330,13 +340,33 @@ var AssetResourceRegistry = class {
|
|
|
330
340
|
}
|
|
331
341
|
write(resource, sink) {
|
|
332
342
|
if (isMetadataResource(resource)) return null;
|
|
333
|
-
const
|
|
343
|
+
const key = assetResourceKey(resource);
|
|
344
|
+
const current = this.canonical(key, resource);
|
|
334
345
|
const id = this.revealBlockerId(key, current);
|
|
335
346
|
if (this.emittedResources.has(key)) return id;
|
|
336
347
|
this.emittedResources.add(key);
|
|
337
348
|
writeAssetTag(sink, current, id);
|
|
338
349
|
return id;
|
|
339
350
|
}
|
|
351
|
+
writeDocumentHead(resources, metadata, sink) {
|
|
352
|
+
const preconnects = [];
|
|
353
|
+
const criticalPreloads = [];
|
|
354
|
+
const stylesheets = [];
|
|
355
|
+
const afterMetadata = [];
|
|
356
|
+
for (const resource of resources) {
|
|
357
|
+
if (isMetadataResource(resource)) continue;
|
|
358
|
+
if (resource.kind === "preconnect") preconnects.push(resource);
|
|
359
|
+
else if (resource.kind === "font" || resource.kind === "preload" && (resource.as === "font" || resource.as === "image" && (resource.fetchpriority === "high" || this.isEarlyImage(resource)))) criticalPreloads.push(resource);
|
|
360
|
+
else if (resource.kind === "stylesheet") stylesheets.push(resource);
|
|
361
|
+
else afterMetadata.push(resource);
|
|
362
|
+
}
|
|
363
|
+
sink.write(metadata.preamble);
|
|
364
|
+
for (const resource of preconnects) this.write(resource, sink);
|
|
365
|
+
for (const resource of criticalPreloads) this.write(resource, sink);
|
|
366
|
+
for (const resource of stylesheets) this.write(resource, sink);
|
|
367
|
+
sink.write(metadata.metadata);
|
|
368
|
+
for (const resource of afterMetadata) this.write(resource, sink);
|
|
369
|
+
}
|
|
340
370
|
headHtml(nonce, streamMetadata = false) {
|
|
341
371
|
const { preamble, metadata } = this.headMetadataHtml(nonce, streamMetadata);
|
|
342
372
|
return preamble + metadata;
|
|
@@ -357,11 +387,7 @@ var AssetResourceRegistry = class {
|
|
|
357
387
|
}, resource, null);
|
|
358
388
|
}
|
|
359
389
|
return {
|
|
360
|
-
preamble:
|
|
361
|
-
...buckets.charset,
|
|
362
|
-
...buckets.parser,
|
|
363
|
-
...buckets.viewport
|
|
364
|
-
].join(""),
|
|
390
|
+
preamble: buckets.charset.join("") + buckets.parser.join("") + buckets.viewport.join(""),
|
|
365
391
|
metadata: buckets.metadata.join("")
|
|
366
392
|
};
|
|
367
393
|
}
|
|
@@ -379,37 +405,30 @@ var AssetResourceRegistry = class {
|
|
|
379
405
|
]);
|
|
380
406
|
return snapshot;
|
|
381
407
|
}
|
|
382
|
-
|
|
383
|
-
return
|
|
408
|
+
preloadHeaderResources() {
|
|
409
|
+
return snapshotPreloadHeaderResources(this.deliveryResources.values(), (resource) => this.isEarlyImage(resource));
|
|
410
|
+
}
|
|
411
|
+
isEarlyImage(resource) {
|
|
412
|
+
return this.earlyImageKeys.has(assetResourceKey(resource));
|
|
384
413
|
}
|
|
385
414
|
visibleMetadata() {
|
|
386
415
|
const visible = /* @__PURE__ */ new Map();
|
|
387
416
|
for (const metadata of this.metadataByOwner.values()) for (const resource of metadata) visible.set(assetResourceKey(resource), resource);
|
|
388
417
|
return visible;
|
|
389
418
|
}
|
|
390
|
-
canonical(resource) {
|
|
391
|
-
const key = assetResourceKey(resource);
|
|
419
|
+
canonical(key, resource) {
|
|
392
420
|
const current = this.deliveryResources.get(key);
|
|
393
421
|
if (current !== void 0) {
|
|
394
422
|
if (assetSignature(current) !== assetSignature(resource)) {
|
|
395
423
|
const promoted = promoteCompatibleImagePreload(current, resource);
|
|
396
424
|
if (promoted === null) throw new AssetResourceConflictError(key, current, resource);
|
|
397
425
|
this.deliveryResources.set(key, promoted);
|
|
398
|
-
return
|
|
399
|
-
key,
|
|
400
|
-
resource: promoted
|
|
401
|
-
};
|
|
426
|
+
return promoted;
|
|
402
427
|
}
|
|
403
|
-
return
|
|
404
|
-
key,
|
|
405
|
-
resource: current
|
|
406
|
-
};
|
|
428
|
+
return current;
|
|
407
429
|
}
|
|
408
430
|
this.deliveryResources.set(key, resource);
|
|
409
|
-
return
|
|
410
|
-
key,
|
|
411
|
-
resource
|
|
412
|
-
};
|
|
431
|
+
return resource;
|
|
413
432
|
}
|
|
414
433
|
revealBlockerId(key, resource) {
|
|
415
434
|
if (resource.kind !== "stylesheet") return null;
|
|
@@ -453,13 +472,11 @@ function writeAssetTag(sink, resource, id) {
|
|
|
453
472
|
}, sink);
|
|
454
473
|
return;
|
|
455
474
|
default: {
|
|
456
|
-
const props = {
|
|
457
|
-
[HYDRATION_SKIP_ATTRIBUTE]: true,
|
|
458
|
-
...Object.fromEntries(assetResourceHostAttributes(resource))
|
|
459
|
-
};
|
|
475
|
+
const props = assetResourceHostProps(resource, { [HYDRATION_SKIP_ATTRIBUTE]: true });
|
|
460
476
|
if (resource.kind === "stylesheet" && id !== null) props.id = id;
|
|
477
|
+
if (sink.nonce !== void 0) props.nonce = sink.nonce;
|
|
461
478
|
const tag = resource.kind === "script" ? "script" : "link";
|
|
462
|
-
writeElementStart(tag,
|
|
479
|
+
writeElementStart(tag, props, sink);
|
|
463
480
|
if (tag === "script") writeElementEnd("script", sink);
|
|
464
481
|
}
|
|
465
482
|
}
|
|
@@ -487,12 +504,6 @@ function metadataAttributes(resource) {
|
|
|
487
504
|
["data-fig-resource-key", resource.key]
|
|
488
505
|
].filter((entry) => entry[1] !== void 0);
|
|
489
506
|
}
|
|
490
|
-
function withNonce(sink, props) {
|
|
491
|
-
return sink.nonce === void 0 ? props : {
|
|
492
|
-
...props,
|
|
493
|
-
nonce: sink.nonce
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
507
|
function assetSignature(resource) {
|
|
497
508
|
switch (resource.kind) {
|
|
498
509
|
case "stylesheet": return signature(resource.kind, resource.href, resource.media ?? "", resource.precedence ?? "", resource.crossorigin ?? "", resource.blocking ?? "reveal");
|
|
@@ -531,20 +542,27 @@ function signature(...values) {
|
|
|
531
542
|
}
|
|
532
543
|
//#endregion
|
|
533
544
|
//#region src/protocol.ts
|
|
534
|
-
function
|
|
545
|
+
function buildServerRuntimeCode(runtimeName) {
|
|
535
546
|
return `globalThis[${jsString(runtimeName)}]??={r(a,f){let n=0,d=()=>{--n||f()};for(let i of a){let e=document.getElementById(i);if(e&&e.tagName==='LINK'&&e.rel==='stylesheet'&&!e.sheet){n++;e.addEventListener('load',d,{once:true});e.addEventListener('error',d,{once:true})}}n||f()},q(e,a){if(e&&e.nodeType===1){if(e.hasAttribute&&e.hasAttribute('${VIEW_TRANSITION_NAME_ATTRIBUTE}'))a.push([e,e.getAttribute('${VIEW_TRANSITION_NAME_ATTRIBUTE}'),e.getAttribute('${VIEW_TRANSITION_CLASS_ATTRIBUTE}')]);if(e.querySelectorAll)for(let x of e.querySelectorAll('[${VIEW_TRANSITION_NAME_ATTRIBUTE}]'))a.push([x,x.getAttribute('${VIEW_TRANSITION_NAME_ATTRIBUTE}'),x.getAttribute('${VIEW_TRANSITION_CLASS_ATTRIBUTE}')])}},g(r){let a=[];this.q(r,a);return a},h(b){let a=[],d=0;for(let e=b;e;){if(e.nodeType===8){if(e.data.indexOf('${SUSPENSE_MARKER_PREFIX}')===0)d++;else if(e.data==='${SUSPENSE_END_MARKER}'){if(d===0)break;d--}}else this.q(e,a);e=e.nextSibling}return a},a(l){for(let x of l){let e=x[0],s=e.style;x[3]=s.viewTransitionName;x[4]=s.viewTransitionClass;s.viewTransitionName=x[1];if(x[2])s.viewTransitionClass=x[2]}},u(l){for(let x of l){let e=x[0],s=e.style;s.viewTransitionName=x[3]||'';s.viewTransitionClass=x[4]||'';!(e.getAttribute&&e.getAttribute('style'))&&e.removeAttribute&&e.removeAttribute('style')}},z(l){for(let f of l)f()},j(t,r){let p=t&&(t.ready||t.finished);p&&p.then?p.then(r,()=>{let f=t&&t.finished;f&&f.then?f.then(r,r):r()}):r()},v(b,s,f){let o=this.h(b),n=this.g(s);if(!o.length&&!n.length){f();return}let d=document,w=d.startViewTransition;if(typeof w!='function'){f();return}let p=d.${VIEW_TRANSITION_PENDING_PROPERTY},pw=p&&(p.finished||p.ready);if(pw&&pw.then){let q=0,i,g=()=>{if(q)return;q=1;clearTimeout(i);d.${VIEW_TRANSITION_PENDING_PROPERTY}===p&&(d.${VIEW_TRANSITION_PENDING_PROPERTY}=null);this.v(b,s,f)};i=setTimeout(g,${VIEW_TRANSITION_TIMEOUT_MS});pw.then(g,g);return}this.a(o);let m=0,l=[],r=()=>{this.u(o);this.u(n);this.z(l)};try{let t=w.call(d,()=>{m=1;f(l);this.a(n)});if(t){d.${VIEW_TRANSITION_PENDING_PROPERTY}=t;let c=()=>{d.${VIEW_TRANSITION_PENDING_PROPERTY}===t&&(d.${VIEW_TRANSITION_PENDING_PROPERTY}=null)},cw=t.finished||t.ready;cw&&cw.then?cw.then(c,c):c()}this.j(t,r)}catch(e){r();if(m)throw e;f()}},m(a){let h=document.head,e=new Map;for(let n of h.querySelectorAll('[${STREAMED_METADATA_ATTRIBUTE}]'))e.set(n.getAttribute('${STREAMED_METADATA_ATTRIBUTE}'),n);for(let d of a){let k=d[0],t=d[1],v=d[2],n=e.get(k);if(!n||n.tagName.toLowerCase()!==t){n&&n.remove();n=document.createElement(t);n.setAttribute('${STREAMED_METADATA_ATTRIBUTE}',k);n.setAttribute('${HYDRATION_SKIP_ATTRIBUTE}','');h.appendChild(n)}e.delete(k);if(t==='title')n.textContent=v;else{for(let x of Array.from(n.attributes))if(x.name!=='${STREAMED_METADATA_ATTRIBUTE}'&&x.name!=='${HYDRATION_SKIP_ATTRIBUTE}')n.removeAttribute(x.name);for(let x of v)n.setAttribute(x[0],x[1])}}for(let n of e.values())n.remove()},s(p,s){p=document.getElementById(p);s=document.getElementById(s);if(!p||!s)return;this.v(p,s,()=>{while(s.firstChild)p.parentNode.insertBefore(s.firstChild,p);p.remove();s.remove()})},f(r,i){if(!r)return null;if(r.id===i)return r;for(let e of r.querySelectorAll?r.querySelectorAll('[id]'):[])if(e.id===i)return e;return null},b(t,b){let e=document.getElementById(t),r=e&&(e.content||e);return this.f(r,b)||document.getElementById(b)},c(b,s,m){let x=document.getElementById(b),y=document.getElementById(s);this.v(x,y,r=>this.o(x,y,r,m))},o(b,s,l,m){if(!b||!s)return;let a=b.previousSibling||b,p=a.parentNode,c=s.content||s;if(!p)return;let r=a.nodeType===8&&a.__figRetry;if(!r&&m)this.m(m);while(c.firstChild)p.insertBefore(c.firstChild,b);for(let e=b,d=0;e;){if(e.nodeType===8){if(e.data.indexOf('${SUSPENSE_MARKER_PREFIX}')===0)d++;else if(e.data==='${SUSPENSE_END_MARKER}'){if(d===0)break;d--}}let x=e.nextSibling;e.remove();e=x}s.remove();if(a.nodeType===8){a.data='${SUSPENSE_COMPLETED_MARKER}';if(r){if(l)l.push(r);else r()}}},x(b,d,m){this.y(document.getElementById(b),d,m)},y(b,d,m){if(!b)return;let s=b.previousSibling;if(s&&s.nodeType===8){s.data='${SUSPENSE_CLIENT_MARKER}';if(d)b.dataset.dgst=d;if(m)b.dataset.msg=m;s.__figRetry&&s.__figRetry()}},ac(t,b,s,m){let x=this.b(t,b),y=document.getElementById(s);this.v(x,y,r=>this.o(x,y,r,m))},ax(t,b,d,m){this.y(this.b(t,b),d,m)}}`;
|
|
536
547
|
}
|
|
537
|
-
|
|
548
|
+
const RUNTIME_CODE_PREFIX = "globalThis[";
|
|
549
|
+
const EMPTY_RUNTIME_REFERENCE = `${RUNTIME_CODE_PREFIX}${jsString("")}`;
|
|
550
|
+
const SERVER_RUNTIME_SUFFIX = buildServerRuntimeCode("").slice(EMPTY_RUNTIME_REFERENCE.length);
|
|
551
|
+
function serverRuntimeCodeFor(runtimeName) {
|
|
552
|
+
return `${RUNTIME_CODE_PREFIX}${jsString(runtimeName)}${SERVER_RUNTIME_SUFFIX}`;
|
|
553
|
+
}
|
|
554
|
+
function writeRuntime(request) {
|
|
538
555
|
if (request.runtimeWritten) return;
|
|
539
556
|
request.runtimeWritten = true;
|
|
540
|
-
writeScript$1(request, serverRuntimeCodeFor(request.runtimeName)
|
|
557
|
+
writeScript$1(request, serverRuntimeCodeFor(request.runtimeName));
|
|
541
558
|
}
|
|
542
|
-
function writeScript$1(request, code
|
|
543
|
-
write(`<script ${HYDRATION_SKIP_ATTRIBUTE}=""${nonceAttribute(request.nonce)}>${code}<\/script>`);
|
|
559
|
+
function writeScript$1(request, code) {
|
|
560
|
+
request.write(`<script ${HYDRATION_SKIP_ATTRIBUTE}=""${nonceAttribute(request.nonce)}>${code}<\/script>`);
|
|
544
561
|
}
|
|
545
562
|
function earlyEventCaptureCode() {
|
|
546
|
-
return
|
|
563
|
+
return EARLY_EVENT_CAPTURE_CODE;
|
|
547
564
|
}
|
|
565
|
+
const EARLY_EVENT_CAPTURE_CODE = `(d=>{if(d.${EARLY_EVENT_QUEUE_PROPERTY})return;let q=d.${EARLY_EVENT_QUEUE_PROPERTY}=[],h=d.${EARLY_EVENT_HANDLER_PROPERTY}=e=>{q.push(e)};for(let t of [${REPLAYABLE_EVENT_TYPES.map((type) => `'${type}'`).join(",")}])d.addEventListener(t,h,!0)})(document)`;
|
|
548
566
|
function earlyEventCaptureMarkup(request) {
|
|
549
567
|
return `<script ${HYDRATION_SKIP_ATTRIBUTE}=""${nonceAttribute(request.nonce)}>${earlyEventCaptureCode()}<\/script>`;
|
|
550
568
|
}
|
|
@@ -588,14 +606,13 @@ const textEncoder = new TextEncoder();
|
|
|
588
606
|
function flushCompletedQueues(request) {
|
|
589
607
|
if (request.controller === null || request.status === "closed") return;
|
|
590
608
|
if (request.pendingRootTasks > 0) return;
|
|
591
|
-
if (request.prerender && request.
|
|
609
|
+
if (request.prerender && request.abortableTasks.size > 0) return;
|
|
592
610
|
if (request.flushing) return;
|
|
593
611
|
request.flushing = true;
|
|
594
612
|
try {
|
|
595
613
|
sealHead(request);
|
|
596
|
-
if (request.
|
|
597
|
-
flushSegment(request, request.
|
|
598
|
-
request.completedRootSegment = null;
|
|
614
|
+
if (request.rootSegment.status !== "flushed") {
|
|
615
|
+
flushSegment(request, request.rootSegment);
|
|
599
616
|
flushWriteBuffer(request);
|
|
600
617
|
}
|
|
601
618
|
if (!drainBoundaryQueue(request, request.clientRenderedBoundaries, flushClientRenderedBoundary) && !drainBoundaryQueue(request, request.completedBoundaries, flushCompletedBoundary)) drainBoundaryQueue(request, request.partialBoundaries, flushPartialBoundary);
|
|
@@ -603,20 +620,20 @@ function flushCompletedQueues(request) {
|
|
|
603
620
|
} finally {
|
|
604
621
|
request.flushing = false;
|
|
605
622
|
}
|
|
606
|
-
if (request.
|
|
607
|
-
request.cleanupAbortListener();
|
|
623
|
+
if (request.abortableTasks.size === 0 && request.completedBoundaries.size === 0 && request.clientRenderedBoundaries.size === 0 && request.partialBoundaries.size === 0) {
|
|
608
624
|
request.status = "closed";
|
|
609
|
-
request.
|
|
625
|
+
request.dispose();
|
|
610
626
|
request.controller.close();
|
|
611
627
|
}
|
|
612
628
|
}
|
|
613
629
|
function sealHead(request) {
|
|
614
630
|
if (request.headSnapshot !== null) return;
|
|
615
631
|
activateVisibleMetadata(request, request.rootSegment);
|
|
616
|
-
const metadata = request.assetRegistry.headMetadataHtml(request.nonce, !request.prerender && request.
|
|
632
|
+
const metadata = request.assetRegistry.headMetadataHtml(request.nonce, !request.prerender && request.abortableTasks.size > 0);
|
|
617
633
|
request.headSnapshot = {
|
|
618
634
|
...metadata,
|
|
619
|
-
preloadHeaderEntries:
|
|
635
|
+
preloadHeaderEntries: null,
|
|
636
|
+
preloadHeaderResources: request.assetRegistry.preloadHeaderResources()
|
|
620
637
|
};
|
|
621
638
|
request.headReady.resolve(metadata.preamble + metadata.metadata);
|
|
622
639
|
}
|
|
@@ -636,21 +653,24 @@ function flushSubtree(request, segment) {
|
|
|
636
653
|
}
|
|
637
654
|
if (segment.status === "flushed") return;
|
|
638
655
|
segment.status = "flushed";
|
|
639
|
-
if (request.
|
|
656
|
+
if (request.documentHasHead === null || segment !== request.rootSegment) collectSegmentAssets(request, segment, null);
|
|
640
657
|
let chunkIndex = 0;
|
|
641
658
|
for (const child of segment.children) {
|
|
642
659
|
for (; chunkIndex < child.index; chunkIndex += 1) writeChunk(request, segment.chunks[chunkIndex], segment);
|
|
643
660
|
flushSegment(request, child);
|
|
644
661
|
}
|
|
645
662
|
for (; chunkIndex < segment.chunks.length; chunkIndex += 1) writeChunk(request, segment.chunks[chunkIndex], segment);
|
|
663
|
+
segment.chunks.length = 0;
|
|
646
664
|
}
|
|
647
665
|
function flushSuspenseBoundary(request, segment, boundary) {
|
|
648
666
|
boundary.parentFlushed = true;
|
|
649
667
|
if (boundary.status === "completed") {
|
|
650
668
|
request.write(`<!--${SUSPENSE_COMPLETED_MARKER}-->`);
|
|
651
|
-
|
|
669
|
+
for (const completedSegment of boundary.completedSegments) flushSegment(request, completedSegment);
|
|
670
|
+
boundary.completedSegments.length = 0;
|
|
652
671
|
request.write(`<!--${SUSPENSE_END_MARKER}-->`);
|
|
653
672
|
segment.status = "flushed";
|
|
673
|
+
segment.chunks.length = 0;
|
|
654
674
|
return;
|
|
655
675
|
}
|
|
656
676
|
if (request.prerender && boundary.status === "client-rendered") {
|
|
@@ -661,7 +681,7 @@ function flushSuspenseBoundary(request, segment, boundary) {
|
|
|
661
681
|
return;
|
|
662
682
|
}
|
|
663
683
|
const boundaryIdValue = ensureBoundaryId(request, boundary);
|
|
664
|
-
|
|
684
|
+
collectSegmentAssets(request, boundary.contentSegment, null);
|
|
665
685
|
request.write(`<!--${SUSPENSE_PENDING_PREFIX}${boundaryIdValue}-->`);
|
|
666
686
|
request.write(boundaryPlaceholderMarkup(request, boundaryIdValue));
|
|
667
687
|
flushSubtree(request, segment);
|
|
@@ -669,10 +689,6 @@ function flushSuspenseBoundary(request, segment, boundary) {
|
|
|
669
689
|
if (boundary.status === "client-rendered") request.clientRenderedBoundaries.add(boundary);
|
|
670
690
|
else if (boundary.completedSegments.length > 0) request.partialBoundaries.add(boundary);
|
|
671
691
|
}
|
|
672
|
-
function flushBoundaryContent(request, boundary) {
|
|
673
|
-
for (const segment of boundary.completedSegments) flushSegment(request, segment);
|
|
674
|
-
boundary.completedSegments = [];
|
|
675
|
-
}
|
|
676
692
|
function clientRenderedBoundaryPlaceholderMarkup(request, boundary) {
|
|
677
693
|
const id = escapeAttribute(boundaryId(request, ensureBoundaryId(request, boundary)));
|
|
678
694
|
const digest = boundary.error?.digest;
|
|
@@ -685,11 +701,17 @@ function flushCompletedBoundary(request, boundary) {
|
|
|
685
701
|
}
|
|
686
702
|
function flushPartialBoundary(request, boundary) {
|
|
687
703
|
for (const segment of boundary.completedSegments) flushBoundarySegment(request, boundary, segment);
|
|
688
|
-
boundary.completedSegments =
|
|
704
|
+
boundary.completedSegments.length = 0;
|
|
689
705
|
}
|
|
690
706
|
function flushBoundarySegment(request, boundary, segment) {
|
|
691
707
|
ensureBoundaryId(request, boundary);
|
|
692
|
-
|
|
708
|
+
let blockingIds = "";
|
|
709
|
+
if (segment.status !== "flushed") {
|
|
710
|
+
blockingIds = flushSegmentAssets(request, segment);
|
|
711
|
+
request.write(segmentContainerStartMarkup(request, ensureSegmentId(request, segment)));
|
|
712
|
+
flushSegment(request, segment);
|
|
713
|
+
request.write("</div>");
|
|
714
|
+
}
|
|
693
715
|
if (segment !== boundary.contentSegment) writeSegmentRevealScript(request, segment, blockingIds);
|
|
694
716
|
}
|
|
695
717
|
function writeSegmentRevealScript(request, segment, blockingIds) {
|
|
@@ -739,32 +761,26 @@ function deactivateMetadataTree(request, segment) {
|
|
|
739
761
|
boundary.metadataVisible = false;
|
|
740
762
|
deactivateMetadataTree(request, boundary.contentSegment);
|
|
741
763
|
}
|
|
742
|
-
function flushSegmentContainer(request, segment) {
|
|
743
|
-
if (segment.status === "flushed") return [];
|
|
744
|
-
const blockingIds = flushSegmentAssets(request, segment);
|
|
745
|
-
request.write(segmentContainerStartMarkup(request, ensureSegmentId(request, segment)));
|
|
746
|
-
flushSegment(request, segment);
|
|
747
|
-
request.write("</div>");
|
|
748
|
-
return blockingIds;
|
|
749
|
-
}
|
|
750
764
|
function flushSegmentAssets(request, segment) {
|
|
751
765
|
const blockingIds = /* @__PURE__ */ new Set();
|
|
752
766
|
collectSegmentAssets(request, segment, blockingIds);
|
|
753
|
-
|
|
767
|
+
let serialized = "";
|
|
768
|
+
for (const id of blockingIds) {
|
|
769
|
+
if (serialized !== "") serialized += ",";
|
|
770
|
+
serialized += jsString(id);
|
|
771
|
+
}
|
|
772
|
+
return serialized;
|
|
754
773
|
}
|
|
755
774
|
function collectSegmentAssets(request, segment, blockingIds) {
|
|
756
|
-
if (segment.status !== "pending" && segment.status !== "rendering")
|
|
757
|
-
for (const child of segment.children) collectSegmentAssets(request, child, blockingIds);
|
|
758
|
-
}
|
|
759
|
-
function flushAssetList(request, resources, blockingIds) {
|
|
760
|
-
for (const resource of resources) {
|
|
775
|
+
if (segment.status !== "pending" && segment.status !== "rendering") for (const resource of segment.assetResources) {
|
|
761
776
|
const id = request.assetRegistry.write(resource, request);
|
|
762
|
-
if (id !== null) blockingIds
|
|
777
|
+
if (id !== null) blockingIds?.add(id);
|
|
763
778
|
}
|
|
779
|
+
for (const child of segment.children) collectSegmentAssets(request, child, blockingIds);
|
|
764
780
|
}
|
|
765
781
|
function withAssetGate(blockingIds, call) {
|
|
766
|
-
if (blockingIds
|
|
767
|
-
return `${RUNTIME_REF}.r([${blockingIds
|
|
782
|
+
if (blockingIds === "") return call;
|
|
783
|
+
return `${RUNTIME_REF}.r([${blockingIds}],()=>{${call}})`;
|
|
768
784
|
}
|
|
769
785
|
function flushClientRenderedBoundary(request, boundary) {
|
|
770
786
|
if (boundary.id === null) return;
|
|
@@ -784,11 +800,8 @@ function drainBoundaryQueue(request, queue, flush) {
|
|
|
784
800
|
flushWriteBuffer(request);
|
|
785
801
|
}
|
|
786
802
|
}
|
|
787
|
-
function writeRuntime(request) {
|
|
788
|
-
writeRuntime$1(request, (chunk) => request.write(chunk));
|
|
789
|
-
}
|
|
790
803
|
function writeScript(request, code) {
|
|
791
|
-
writeScript$1(request, `(__figSSR=>{${code}})(globalThis[${jsString(request.runtimeName)}])
|
|
804
|
+
writeScript$1(request, `(__figSSR=>{${code}})(globalThis[${jsString(request.runtimeName)}])`);
|
|
792
805
|
}
|
|
793
806
|
function writeChunk(request, chunk, segment) {
|
|
794
807
|
if (chunk === leadingNewlineStartMarker) {
|
|
@@ -807,34 +820,14 @@ function writeChunk(request, chunk, segment) {
|
|
|
807
820
|
request.write(chunk);
|
|
808
821
|
return;
|
|
809
822
|
}
|
|
810
|
-
if (request.
|
|
823
|
+
if (request.documentHasHead === null) return;
|
|
811
824
|
const metadata = request.headSnapshot ?? request.assetRegistry.headMetadataHtml(request.nonce);
|
|
812
|
-
|
|
813
|
-
const blockingIds = /* @__PURE__ */ new Set();
|
|
814
|
-
request.write(metadata.preamble);
|
|
815
|
-
flushAssetList(request, beforeMetadata, blockingIds);
|
|
816
|
-
request.write(metadata.metadata);
|
|
817
|
-
flushAssetList(request, afterMetadata, blockingIds);
|
|
818
|
-
}
|
|
819
|
-
function partitionHeadAssets(request, resources) {
|
|
820
|
-
const preconnects = [];
|
|
821
|
-
const criticalPreloads = [];
|
|
822
|
-
const stylesheets = [];
|
|
823
|
-
const afterMetadata = [];
|
|
824
|
-
for (const resource of resources) if (resource.kind === "preconnect") preconnects.push(resource);
|
|
825
|
-
else if (resource.kind === "font" || resource.kind === "preload" && (resource.as === "font" || resource.as === "image" && (resource.fetchpriority === "high" || request.assetRegistry.isEarlyImage(resource)))) criticalPreloads.push(resource);
|
|
826
|
-
else if (resource.kind === "stylesheet") stylesheets.push(resource);
|
|
827
|
-
else afterMetadata.push(resource);
|
|
828
|
-
return [[
|
|
829
|
-
...preconnects,
|
|
830
|
-
...criticalPreloads,
|
|
831
|
-
...stylesheets
|
|
832
|
-
], afterMetadata];
|
|
825
|
+
request.assetRegistry.writeDocumentHead(segment.assetResources, metadata, request);
|
|
833
826
|
}
|
|
834
827
|
function flushWriteBuffer(request) {
|
|
835
|
-
if (request.writeBuffer
|
|
836
|
-
request.controller.enqueue(textEncoder.encode(request.writeBuffer
|
|
837
|
-
request.writeBuffer =
|
|
828
|
+
if (request.writeBuffer === "" || request.controller === null) return;
|
|
829
|
+
request.controller.enqueue(textEncoder.encode(request.writeBuffer));
|
|
830
|
+
request.writeBuffer = "";
|
|
838
831
|
}
|
|
839
832
|
function ensureSegmentId(request, segment) {
|
|
840
833
|
segment.id ??= request.nextSegmentId++;
|
|
@@ -849,31 +842,32 @@ function ensureBoundaryId(request, boundary) {
|
|
|
849
842
|
const errorStacks = /* @__PURE__ */ new WeakMap();
|
|
850
843
|
const TEXT_SEPARATOR = `<!--${TEXT_SEPARATOR_DATA}-->`;
|
|
851
844
|
let nextRuntimeId = 0;
|
|
852
|
-
function createServerRenderRequest(node, options
|
|
845
|
+
function createServerRenderRequest(node, options, mode) {
|
|
853
846
|
throwIfAborted(options.signal);
|
|
847
|
+
const identifierPrefix = options.identifierPrefix ?? "";
|
|
854
848
|
const shellReady = deferred();
|
|
855
849
|
const headReady = deferred();
|
|
856
850
|
const allReady = deferred();
|
|
857
|
-
shellReady.promise.catch(
|
|
858
|
-
headReady.promise.catch(
|
|
859
|
-
allReady.promise.catch(
|
|
860
|
-
const rootSegment = createSegment(0
|
|
851
|
+
shellReady.promise.catch(noop);
|
|
852
|
+
headReady.promise.catch(noop);
|
|
853
|
+
allReady.promise.catch(noop);
|
|
854
|
+
const rootSegment = createSegment(0);
|
|
861
855
|
const dataStoreHost = {
|
|
862
|
-
getLane:
|
|
856
|
+
getLane: noLane,
|
|
863
857
|
partition: options.dataPartition,
|
|
864
|
-
schedule:
|
|
858
|
+
schedule: noop
|
|
865
859
|
};
|
|
866
860
|
const dataStore = options.dataStore === void 0 ? createRendererDataStore(dataStoreHost) : attachDataStore(options.dataStore, dataStoreHost, options.initialData);
|
|
867
861
|
const request = {
|
|
868
862
|
abortableTasks: /* @__PURE__ */ new Set(),
|
|
869
863
|
allReady,
|
|
870
|
-
cleanupAbortListener:
|
|
864
|
+
cleanupAbortListener: null,
|
|
871
865
|
completedBoundaries: /* @__PURE__ */ new Set(),
|
|
872
|
-
completedRootSegment: null,
|
|
873
866
|
controller: null,
|
|
874
867
|
dataStore,
|
|
875
|
-
|
|
876
|
-
|
|
868
|
+
dispose: disposeRequest,
|
|
869
|
+
abortReason: null,
|
|
870
|
+
identifierPrefix,
|
|
877
871
|
leadingNewlineStack: [],
|
|
878
872
|
nextBoundaryId: 0,
|
|
879
873
|
nextSegmentId: 0,
|
|
@@ -882,10 +876,9 @@ function createServerRenderRequest(node, options = {}, mode = {}) {
|
|
|
882
876
|
nonce: options.nonce,
|
|
883
877
|
onError: options.onError,
|
|
884
878
|
pendingRootTasks: 0,
|
|
885
|
-
pendingTasks: 0,
|
|
886
879
|
pingedTasks: [],
|
|
887
880
|
rootSegment,
|
|
888
|
-
runtimeName: createRuntimeName(
|
|
881
|
+
runtimeName: createRuntimeName(identifierPrefix),
|
|
889
882
|
runtimeWritten: false,
|
|
890
883
|
headReady,
|
|
891
884
|
headSnapshot: null,
|
|
@@ -894,37 +887,37 @@ function createServerRenderRequest(node, options = {}, mode = {}) {
|
|
|
894
887
|
clientRenderedBoundaries: /* @__PURE__ */ new Set(),
|
|
895
888
|
clientReferenceFallback: options.clientReferenceFallback,
|
|
896
889
|
partialBoundaries: /* @__PURE__ */ new Set(),
|
|
897
|
-
prerender: mode
|
|
890
|
+
prerender: mode?.prerender === true,
|
|
898
891
|
componentAssets: options.assets,
|
|
899
|
-
|
|
900
|
-
assetRegistry: new AssetResourceRegistry(
|
|
892
|
+
documentHasHead: mode?.document === true ? false : null,
|
|
893
|
+
assetRegistry: new AssetResourceRegistry(identifierPrefix),
|
|
901
894
|
resolveAssetKey: options.resolveAssetKey,
|
|
902
|
-
workScheduled: false,
|
|
903
895
|
flushing: false,
|
|
904
|
-
writeBuffer:
|
|
905
|
-
write
|
|
906
|
-
if (chunk !== "" && this.leadingNewlineStack.length > 0) this.leadingNewlineStack[this.leadingNewlineStack.length - 1] = true;
|
|
907
|
-
this.writeBuffer.push(chunk);
|
|
908
|
-
}
|
|
896
|
+
writeBuffer: "",
|
|
897
|
+
write: writeRequestChunk
|
|
909
898
|
};
|
|
910
899
|
if (options.dataStore === void 0 && options.initialData !== void 0) request.dataStore.hydrate(options.initialData);
|
|
911
900
|
rootSegment.parentFlushed = true;
|
|
912
|
-
|
|
913
|
-
abortSet: request.abortableTasks,
|
|
901
|
+
pingTask(createTask(node, {
|
|
914
902
|
boundary: null,
|
|
915
903
|
contextValues: /* @__PURE__ */ new Map(),
|
|
904
|
+
dispatcher: null,
|
|
905
|
+
fallbackTasks: null,
|
|
916
906
|
hiddenActivityId: null,
|
|
917
907
|
hostAncestors: [],
|
|
918
908
|
hostNamespace: "html",
|
|
919
909
|
imagePreloadsSuppressed: false,
|
|
920
|
-
idPath:
|
|
910
|
+
idPath: [],
|
|
911
|
+
idPathString: null,
|
|
912
|
+
localIdCounter: 0,
|
|
921
913
|
pendingLeadingNewline: false,
|
|
914
|
+
request,
|
|
922
915
|
selectProps: null,
|
|
916
|
+
segment: rootSegment,
|
|
923
917
|
stack: null,
|
|
924
918
|
treeParent: options.renderTree?.tree ?? null,
|
|
925
919
|
viewTransition: null
|
|
926
|
-
});
|
|
927
|
-
request.pingedTasks.push(rootTask);
|
|
920
|
+
}));
|
|
928
921
|
const stream = new ReadableStream({
|
|
929
922
|
start(streamController) {
|
|
930
923
|
request.controller = streamController;
|
|
@@ -935,7 +928,7 @@ function createServerRenderRequest(node, options = {}, mode = {}) {
|
|
|
935
928
|
},
|
|
936
929
|
cancel(reason) {
|
|
937
930
|
request.controller = null;
|
|
938
|
-
request.writeBuffer =
|
|
931
|
+
request.writeBuffer = "";
|
|
939
932
|
abort(request, reason);
|
|
940
933
|
request.status = "closed";
|
|
941
934
|
}
|
|
@@ -946,21 +939,28 @@ function createServerRenderRequest(node, options = {}, mode = {}) {
|
|
|
946
939
|
signal.addEventListener("abort", abortListener, { once: true });
|
|
947
940
|
request.cleanupAbortListener = () => {
|
|
948
941
|
signal.removeEventListener("abort", abortListener);
|
|
949
|
-
request.cleanupAbortListener =
|
|
942
|
+
request.cleanupAbortListener = null;
|
|
950
943
|
};
|
|
951
944
|
}
|
|
952
|
-
request.workScheduled = true;
|
|
953
|
-
queueMicrotask(() => {
|
|
954
|
-
request.workScheduled = false;
|
|
955
|
-
performWork(request);
|
|
956
|
-
});
|
|
957
945
|
return {
|
|
958
946
|
abort: (reason) => abort(request, reason),
|
|
959
947
|
allReady: allReady.promise,
|
|
960
948
|
contentType: "text/html; charset=utf-8",
|
|
961
949
|
data: request.dataStore,
|
|
962
950
|
getData: () => request.dataStore.snapshot(),
|
|
963
|
-
getPreloadHeader: (headerOptions) =>
|
|
951
|
+
getPreloadHeader: (headerOptions) => {
|
|
952
|
+
const snapshot = request.headSnapshot;
|
|
953
|
+
if (snapshot === null) return void 0;
|
|
954
|
+
let entries = snapshot.preloadHeaderEntries;
|
|
955
|
+
if (entries === null) {
|
|
956
|
+
const resources = snapshot.preloadHeaderResources;
|
|
957
|
+
if (resources === null) throw new Error("Missing preload-header resource snapshot.");
|
|
958
|
+
entries = createPreloadHeaderEntries(resources);
|
|
959
|
+
snapshot.preloadHeaderEntries = entries;
|
|
960
|
+
snapshot.preloadHeaderResources = null;
|
|
961
|
+
}
|
|
962
|
+
return formatPreloadHeader(entries, headerOptions);
|
|
963
|
+
},
|
|
964
964
|
getHead: () => {
|
|
965
965
|
const snapshot = request.headSnapshot;
|
|
966
966
|
return snapshot === null ? request.assetRegistry.headHtml(request.nonce) : snapshot.preamble + snapshot.metadata;
|
|
@@ -970,105 +970,91 @@ function createServerRenderRequest(node, options = {}, mode = {}) {
|
|
|
970
970
|
stream
|
|
971
971
|
};
|
|
972
972
|
}
|
|
973
|
-
function createTask(
|
|
974
|
-
request
|
|
975
|
-
if (
|
|
976
|
-
else
|
|
973
|
+
function createTask(node, frame, childIndexBase = 0) {
|
|
974
|
+
const { request } = frame;
|
|
975
|
+
if (frame.boundary === null) request.pendingRootTasks += 1;
|
|
976
|
+
else frame.boundary.pendingTasks += 1;
|
|
977
977
|
const task = {
|
|
978
|
-
...scope,
|
|
979
978
|
childIndexBase,
|
|
980
|
-
|
|
981
|
-
|
|
979
|
+
frame,
|
|
980
|
+
node
|
|
982
981
|
};
|
|
983
982
|
request.abortableTasks.add(task);
|
|
984
|
-
|
|
983
|
+
frame.fallbackTasks?.add(task);
|
|
985
984
|
return task;
|
|
986
985
|
}
|
|
987
|
-
function
|
|
986
|
+
function forkFrame(frame, segment, boundary = frame.boundary, fallbackTasks = frame.fallbackTasks) {
|
|
988
987
|
return {
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
988
|
+
boundary,
|
|
989
|
+
contextValues: cloneContextValues(frame.contextValues),
|
|
990
|
+
dispatcher: null,
|
|
991
|
+
fallbackTasks,
|
|
992
|
+
hiddenActivityId: frame.hiddenActivityId,
|
|
993
|
+
hostAncestors: frame.hostAncestors,
|
|
994
|
+
hostNamespace: frame.hostNamespace,
|
|
995
|
+
imagePreloadsSuppressed: frame.imagePreloadsSuppressed,
|
|
996
|
+
idPath: [...frame.idPath],
|
|
997
|
+
idPathString: null,
|
|
998
|
+
localIdCounter: 0,
|
|
999
|
+
pendingLeadingNewline: frame.pendingLeadingNewline,
|
|
1000
|
+
request: frame.request,
|
|
1001
|
+
selectProps: frame.selectProps,
|
|
1002
|
+
segment,
|
|
1003
|
+
stack: frame.stack,
|
|
1004
|
+
treeParent: frame.treeParent,
|
|
1005
|
+
viewTransition: frame.viewTransition === null ? null : { ...frame.viewTransition }
|
|
1002
1006
|
};
|
|
1003
1007
|
}
|
|
1004
|
-
function createSegment(index, boundary
|
|
1005
|
-
lastPushedText: false,
|
|
1006
|
-
textEmbedded: false
|
|
1007
|
-
}) {
|
|
1008
|
+
function createSegment(index, boundary = null) {
|
|
1008
1009
|
return {
|
|
1009
1010
|
boundary,
|
|
1010
1011
|
children: [],
|
|
1011
1012
|
chunks: [],
|
|
1012
1013
|
id: null,
|
|
1013
1014
|
index,
|
|
1014
|
-
lastPushedText:
|
|
1015
|
+
lastPushedText: false,
|
|
1015
1016
|
parentFlushed: false,
|
|
1016
1017
|
assetResources: [],
|
|
1017
1018
|
status: "pending",
|
|
1018
|
-
textEmbedded:
|
|
1019
|
-
write
|
|
1020
|
-
this.lastPushedText = false;
|
|
1021
|
-
this.chunks.push(chunk);
|
|
1022
|
-
}
|
|
1019
|
+
textEmbedded: false,
|
|
1020
|
+
write: writeSegmentChunk
|
|
1023
1021
|
};
|
|
1024
1022
|
}
|
|
1025
|
-
function
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
status: "pending",
|
|
1037
|
-
metadataVisible: false
|
|
1038
|
-
};
|
|
1023
|
+
function writeRequestChunk(chunk) {
|
|
1024
|
+
if (chunk !== "" && this.leadingNewlineStack.length > 0) this.leadingNewlineStack[this.leadingNewlineStack.length - 1] = true;
|
|
1025
|
+
this.writeBuffer += chunk;
|
|
1026
|
+
}
|
|
1027
|
+
function disposeRequest() {
|
|
1028
|
+
this.cleanupAbortListener?.();
|
|
1029
|
+
this.dataStore.dispose();
|
|
1030
|
+
}
|
|
1031
|
+
function writeSegmentChunk(chunk) {
|
|
1032
|
+
this.lastPushedText = false;
|
|
1033
|
+
this.chunks.push(chunk);
|
|
1039
1034
|
}
|
|
1040
1035
|
function performWork(request) {
|
|
1041
1036
|
if (request.status === "closed") return;
|
|
1042
1037
|
const tasks = request.pingedTasks;
|
|
1043
1038
|
request.pingedTasks = [];
|
|
1044
|
-
for (const task of tasks) retryTask(
|
|
1039
|
+
for (const task of tasks) retryTask(task);
|
|
1045
1040
|
flushCompletedQueues(request);
|
|
1046
1041
|
}
|
|
1047
|
-
function retryTask(
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1042
|
+
function retryTask(task) {
|
|
1043
|
+
const { frame } = task;
|
|
1044
|
+
if (frame.segment.status !== "pending") return;
|
|
1045
|
+
frame.segment.status = "rendering";
|
|
1051
1046
|
try {
|
|
1052
1047
|
renderChildren(task.node, frame, task.childIndexBase);
|
|
1053
|
-
completeSegmentText(
|
|
1054
|
-
|
|
1055
|
-
detachTask(
|
|
1056
|
-
|
|
1048
|
+
completeSegmentText(frame.segment);
|
|
1049
|
+
frame.segment.status = "completed";
|
|
1050
|
+
detachTask(task);
|
|
1051
|
+
settleTask(task, "completed");
|
|
1057
1052
|
} catch (error) {
|
|
1058
|
-
detachTask(
|
|
1059
|
-
|
|
1060
|
-
|
|
1053
|
+
detachTask(task);
|
|
1054
|
+
frame.segment.status = "completed";
|
|
1055
|
+
settleTask(task, "errored", error);
|
|
1061
1056
|
}
|
|
1062
1057
|
}
|
|
1063
|
-
function createRenderFrame(request, segment, scope) {
|
|
1064
|
-
return {
|
|
1065
|
-
...scope,
|
|
1066
|
-
dispatcher: null,
|
|
1067
|
-
localIdCounter: 0,
|
|
1068
|
-
request,
|
|
1069
|
-
segment
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
1058
|
function createServerDispatcher(frame) {
|
|
1073
1059
|
return createStaticDispatcher({
|
|
1074
1060
|
contextValues: frame.contextValues,
|
|
@@ -1086,7 +1072,8 @@ function createServerDispatcher(frame) {
|
|
|
1086
1072
|
frame.request.dataStore.preloadData(resource, ...args);
|
|
1087
1073
|
},
|
|
1088
1074
|
useId() {
|
|
1089
|
-
|
|
1075
|
+
frame.idPathString ??= formatIdPath(frame.idPath);
|
|
1076
|
+
const id = `${frame.request.identifierPrefix}fig-${frame.idPathString}-${frame.localIdCounter.toString(32)}`;
|
|
1090
1077
|
frame.localIdCounter += 1;
|
|
1091
1078
|
return id;
|
|
1092
1079
|
},
|
|
@@ -1094,14 +1081,9 @@ function createServerDispatcher(frame) {
|
|
|
1094
1081
|
});
|
|
1095
1082
|
}
|
|
1096
1083
|
function renderNode(node, frame) {
|
|
1097
|
-
if (Array.isArray(node)) {
|
|
1098
|
-
renderChildren(node, frame);
|
|
1099
|
-
return;
|
|
1100
|
-
}
|
|
1101
|
-
if (node === null || node === void 0 || typeof node === "boolean") return;
|
|
1102
1084
|
if (typeof node === "string" || typeof node === "number") {
|
|
1103
1085
|
const text = String(node);
|
|
1104
|
-
if (frame.request.
|
|
1086
|
+
if (frame.request.documentHasHead === false) {
|
|
1105
1087
|
if (text.trim() !== "") throw invalidDocumentShellError();
|
|
1106
1088
|
}
|
|
1107
1089
|
if (frame.hostNamespace === "html") validateTextNesting(text, frame.hostAncestors);
|
|
@@ -1114,7 +1096,7 @@ function renderNode(node, frame) {
|
|
|
1114
1096
|
props: { nodeValue: text }
|
|
1115
1097
|
});
|
|
1116
1098
|
if (frame.segment.lastPushedText) frame.segment.write(TEXT_SEPARATOR);
|
|
1117
|
-
if (consumePendingLeadingNewline(frame))
|
|
1099
|
+
if (consumePendingLeadingNewline(frame)) frame.segment.write({ value: escapeText(text) });
|
|
1118
1100
|
else writeText(text, frame.segment);
|
|
1119
1101
|
frame.segment.lastPushedText = true;
|
|
1120
1102
|
}
|
|
@@ -1133,31 +1115,38 @@ function renderNode(node, frame) {
|
|
|
1133
1115
|
}
|
|
1134
1116
|
function renderChildren(node, frame, indexBase = 0) {
|
|
1135
1117
|
if (Array.isArray(node)) {
|
|
1136
|
-
|
|
1118
|
+
const children = collectChildren(node);
|
|
1119
|
+
for (let index = 0; index < children.length; index += 1) renderChildAtIndex(children[index], frame, indexBase + index);
|
|
1137
1120
|
return;
|
|
1138
1121
|
}
|
|
1139
1122
|
if (node === null || node === void 0 || typeof node === "boolean" || node === "") return;
|
|
1140
1123
|
renderChildAtIndex(node, frame, indexBase);
|
|
1141
1124
|
}
|
|
1142
|
-
function renderChildSequence(children, frame, indexBase = 0) {
|
|
1143
|
-
for (let index = 0; index < children.length; index += 1) renderChildAtIndex(children[index], frame, indexBase + index);
|
|
1144
|
-
}
|
|
1145
1125
|
function renderChildAtIndex(child, frame, index) {
|
|
1146
|
-
const
|
|
1147
|
-
|
|
1148
|
-
frame.
|
|
1126
|
+
const previousIdPathString = frame.idPathString;
|
|
1127
|
+
frame.idPath.push(index);
|
|
1128
|
+
frame.idPathString = null;
|
|
1149
1129
|
try {
|
|
1150
1130
|
renderNode(child, frame);
|
|
1151
1131
|
} catch (error) {
|
|
1152
|
-
frame.idPath
|
|
1132
|
+
frame.idPath.pop();
|
|
1133
|
+
frame.idPathString = previousIdPathString;
|
|
1153
1134
|
if (isThenable(error)) {
|
|
1154
1135
|
spawnSuspendedTask(frame, child, error, index);
|
|
1155
1136
|
return;
|
|
1156
1137
|
}
|
|
1157
1138
|
throw error;
|
|
1158
|
-
} finally {
|
|
1159
|
-
frame.idPath = previousIdPath;
|
|
1160
1139
|
}
|
|
1140
|
+
frame.idPath.pop();
|
|
1141
|
+
frame.idPathString = previousIdPathString;
|
|
1142
|
+
}
|
|
1143
|
+
function formatIdPath(path) {
|
|
1144
|
+
let value = "";
|
|
1145
|
+
for (let index = 0; index < path.length; index += 1) {
|
|
1146
|
+
if (index > 0) value += "-";
|
|
1147
|
+
value += path[index].toString(32);
|
|
1148
|
+
}
|
|
1149
|
+
return value;
|
|
1161
1150
|
}
|
|
1162
1151
|
function completeSegmentText(segment) {
|
|
1163
1152
|
if (segment.textEmbedded && segment.lastPushedText) segment.write(TEXT_SEPARATOR);
|
|
@@ -1296,16 +1285,18 @@ function renderAssets(props, frame) {
|
|
|
1296
1285
|
}
|
|
1297
1286
|
function renderAssetValue(value, frame) {
|
|
1298
1287
|
if (value === void 0 || value === null || value === false) return;
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
frame.
|
|
1288
|
+
if (Array.isArray(value)) for (const resource of value) renderAssetResource(resource, frame);
|
|
1289
|
+
else renderAssetResource(value, frame);
|
|
1290
|
+
}
|
|
1291
|
+
function renderAssetResource(resource, frame) {
|
|
1292
|
+
if (!isFigAssetResource(resource)) throw new Error("The assets prop must contain Fig asset resources.");
|
|
1293
|
+
try {
|
|
1294
|
+
frame.request.assetRegistry.register(resource);
|
|
1295
|
+
} catch (error) {
|
|
1296
|
+
recordErrorStack(error, frame.stack);
|
|
1297
|
+
throw error;
|
|
1308
1298
|
}
|
|
1299
|
+
frame.segment.assetResources.push(resource);
|
|
1309
1300
|
}
|
|
1310
1301
|
function renderAutomaticImagePreload(resource, frame) {
|
|
1311
1302
|
try {
|
|
@@ -1318,20 +1309,27 @@ function renderAutomaticImagePreload(resource, frame) {
|
|
|
1318
1309
|
}
|
|
1319
1310
|
function renderSuspense(props, frame) {
|
|
1320
1311
|
consumePendingLeadingNewline(frame);
|
|
1321
|
-
const
|
|
1322
|
-
const
|
|
1323
|
-
|
|
1324
|
-
|
|
1312
|
+
const contentSegment = createSegment(0);
|
|
1313
|
+
const boundary = {
|
|
1314
|
+
activityId: frame.hiddenActivityId,
|
|
1315
|
+
completedSegments: [],
|
|
1316
|
+
contentSegment,
|
|
1317
|
+
error: null,
|
|
1318
|
+
fallbackSegment: null,
|
|
1319
|
+
fallbackTasks: /* @__PURE__ */ new Set(),
|
|
1320
|
+
id: null,
|
|
1321
|
+
metadataVisible: false,
|
|
1322
|
+
parentFlushed: false,
|
|
1323
|
+
pendingTasks: 0,
|
|
1324
|
+
status: "pending"
|
|
1325
|
+
};
|
|
1325
1326
|
const parentSegment = frame.segment;
|
|
1326
1327
|
const boundarySegment = createSegment(parentSegment.chunks.length, boundary);
|
|
1327
1328
|
boundary.fallbackSegment = boundarySegment;
|
|
1328
1329
|
parentSegment.children.push(boundarySegment);
|
|
1329
1330
|
parentSegment.lastPushedText = false;
|
|
1330
1331
|
contentSegment.parentFlushed = true;
|
|
1331
|
-
const contentFrame =
|
|
1332
|
-
...forkScope(frame),
|
|
1333
|
-
boundary
|
|
1334
|
-
});
|
|
1332
|
+
const contentFrame = forkFrame(frame, contentSegment, boundary);
|
|
1335
1333
|
try {
|
|
1336
1334
|
renderChildren(props.children, contentFrame);
|
|
1337
1335
|
contentSegment.status = "completed";
|
|
@@ -1341,46 +1339,36 @@ function renderSuspense(props, frame) {
|
|
|
1341
1339
|
contentSegment.status = "completed";
|
|
1342
1340
|
markBoundaryClientRendered(frame.request, boundary, error, frame.stack);
|
|
1343
1341
|
}
|
|
1344
|
-
|
|
1345
|
-
if (frame.viewTransition !== null && branch.viewTransition !== null) frame.viewTransition.index = Math.max(frame.viewTransition.index, branch.viewTransition.index);
|
|
1346
|
-
};
|
|
1347
|
-
advanceSurfaceWatermark(contentFrame);
|
|
1342
|
+
advanceViewTransitionWatermark(frame, contentFrame);
|
|
1348
1343
|
if (boundary.status === "completed") return;
|
|
1349
|
-
const fallbackFrame =
|
|
1350
|
-
...forkScope(frame),
|
|
1351
|
-
abortSet: fallbackAbortableTasks
|
|
1352
|
-
});
|
|
1344
|
+
const fallbackFrame = forkFrame(frame, boundarySegment, frame.boundary, boundary.fallbackTasks);
|
|
1353
1345
|
try {
|
|
1354
1346
|
renderChildren(props.fallback, fallbackFrame);
|
|
1355
1347
|
boundarySegment.status = "completed";
|
|
1356
1348
|
} catch (error) {
|
|
1357
|
-
if (boundary.pendingTasks > 0) for (const task of
|
|
1349
|
+
if (boundary.pendingTasks > 0) for (const task of boundary.fallbackTasks) abortTask(task);
|
|
1358
1350
|
throw error;
|
|
1359
1351
|
} finally {
|
|
1360
|
-
|
|
1352
|
+
advanceViewTransitionWatermark(frame, fallbackFrame);
|
|
1361
1353
|
}
|
|
1362
1354
|
}
|
|
1355
|
+
function advanceViewTransitionWatermark(parent, branch) {
|
|
1356
|
+
if (parent.viewTransition !== null && branch.viewTransition !== null) parent.viewTransition.index = Math.max(parent.viewTransition.index, branch.viewTransition.index);
|
|
1357
|
+
}
|
|
1363
1358
|
function renderViewTransition(props, frame) {
|
|
1364
1359
|
const previousViewTransition = frame.viewTransition;
|
|
1365
|
-
|
|
1360
|
+
const className = props.default;
|
|
1361
|
+
frame.viewTransition = {
|
|
1362
|
+
className: className === void 0 || className === "auto" || className === "none" ? null : className,
|
|
1363
|
+
index: 0,
|
|
1364
|
+
name: props.name === void 0 || props.name === "auto" ? `fig-vt-${frame.request.nextViewTransitionId++}` : props.name
|
|
1365
|
+
};
|
|
1366
1366
|
try {
|
|
1367
1367
|
renderChildren(props.children, frame);
|
|
1368
1368
|
} finally {
|
|
1369
1369
|
frame.viewTransition = previousViewTransition;
|
|
1370
1370
|
}
|
|
1371
1371
|
}
|
|
1372
|
-
function createServerViewTransition(props, request) {
|
|
1373
|
-
return {
|
|
1374
|
-
className: serverViewTransitionClass(props),
|
|
1375
|
-
index: 0,
|
|
1376
|
-
name: props.name === void 0 || props.name === "auto" ? `fig-vt-${request.nextViewTransitionId++}` : props.name
|
|
1377
|
-
};
|
|
1378
|
-
}
|
|
1379
|
-
function serverViewTransitionClass(props) {
|
|
1380
|
-
const className = props.default;
|
|
1381
|
-
if (className === void 0 || className === "auto" || className === "none") return null;
|
|
1382
|
-
return className;
|
|
1383
|
-
}
|
|
1384
1372
|
function renderActivity(props, frame) {
|
|
1385
1373
|
if (props.mode !== "hidden") {
|
|
1386
1374
|
renderChildren(props.children, frame);
|
|
@@ -1398,15 +1386,17 @@ function renderActivity(props, frame) {
|
|
|
1398
1386
|
frame.segment.write("</template>");
|
|
1399
1387
|
}
|
|
1400
1388
|
function renderHostElement(type, props, frame) {
|
|
1401
|
-
const
|
|
1402
|
-
|
|
1389
|
+
const normalizedType = type.toLowerCase();
|
|
1390
|
+
const namespace = normalizedType === "svg" ? "svg" : normalizedType === "math" ? "mathml" : frame.hostNamespace;
|
|
1391
|
+
if (namespace === "html" && renderHostAsset(normalizedType, props, frame)) return;
|
|
1403
1392
|
if (namespace === "html") validateInstanceNesting(type, frame.hostAncestors);
|
|
1404
|
-
const
|
|
1405
|
-
|
|
1393
|
+
const isDocument = frame.request.documentHasHead !== null;
|
|
1394
|
+
const isDocumentHead = isDocument && type === "head";
|
|
1395
|
+
if (frame.request.documentHasHead === false) {
|
|
1406
1396
|
if (type !== "html" && type !== "head") throw invalidDocumentShellError();
|
|
1407
1397
|
}
|
|
1408
|
-
if (
|
|
1409
|
-
if (
|
|
1398
|
+
if (isDocument && type === "html") frame.segment.write("<!doctype html>");
|
|
1399
|
+
if (isDocumentHead) frame.request.documentHasHead = true;
|
|
1410
1400
|
const isVoid = namespace === "html" && isVoidElement(type);
|
|
1411
1401
|
const unsafeHTML = unsafeHTMLContent(props);
|
|
1412
1402
|
if (isVoid && hasRenderableChild(props.children)) throw new Error(`Void element <${type}> cannot have children.`);
|
|
@@ -1418,21 +1408,18 @@ function renderHostElement(type, props, frame) {
|
|
|
1418
1408
|
}
|
|
1419
1409
|
consumePendingLeadingNewline(frame);
|
|
1420
1410
|
const viewTransition = frame.viewTransition;
|
|
1421
|
-
writeElementStart(type, viewTransition === null ? props : viewTransitionHostProps(props, viewTransition), frame.segment, frame.selectProps
|
|
1422
|
-
if (
|
|
1411
|
+
writeElementStart(type, viewTransition === null ? props : viewTransitionHostProps(props, viewTransition), frame.segment, frame.selectProps);
|
|
1412
|
+
if (isDocumentHead) frame.segment.write(earlyEventCaptureMarkup(frame.request));
|
|
1423
1413
|
if (isVoid) return;
|
|
1424
1414
|
const previousPendingLeadingNewline = frame.pendingLeadingNewline;
|
|
1425
|
-
const tracksLeadingNewline =
|
|
1415
|
+
const tracksLeadingNewline = type === "pre" || type === "textarea";
|
|
1426
1416
|
frame.pendingLeadingNewline = tracksLeadingNewline;
|
|
1427
|
-
if (unsafeHTML !== null) {
|
|
1428
|
-
frame.segment.write(consumePendingLeadingNewline(frame) ? preserveParserStrippedLeadingNewline(unsafeHTML) : unsafeHTML);
|
|
1429
|
-
frame.pendingLeadingNewline = previousPendingLeadingNewline;
|
|
1430
|
-
writeElementEnd(type, frame.segment);
|
|
1431
|
-
return;
|
|
1432
|
-
}
|
|
1433
1417
|
const formText = namespace === "html" ? formTextContent(type, props) : null;
|
|
1434
|
-
|
|
1435
|
-
|
|
1418
|
+
const staticContent = unsafeHTML ?? formText;
|
|
1419
|
+
if (staticContent !== null) {
|
|
1420
|
+
const content = consumePendingLeadingNewline(frame) && staticContent.startsWith("\n") ? `\n${staticContent}` : staticContent;
|
|
1421
|
+
if (unsafeHTML === null) writeText(content, frame.segment);
|
|
1422
|
+
else frame.segment.write(content);
|
|
1436
1423
|
frame.pendingLeadingNewline = previousPendingLeadingNewline;
|
|
1437
1424
|
writeElementEnd(type, frame.segment);
|
|
1438
1425
|
return;
|
|
@@ -1445,7 +1432,7 @@ function renderHostElement(type, props, frame) {
|
|
|
1445
1432
|
const previousViewTransition = frame.viewTransition;
|
|
1446
1433
|
if (viewTransition !== null) frame.viewTransition = null;
|
|
1447
1434
|
frame.hostAncestors = [type, ...previousHostAncestors];
|
|
1448
|
-
frame.hostNamespace =
|
|
1435
|
+
frame.hostNamespace = namespace === "svg" && normalizedType === "foreignobject" ? "html" : namespace;
|
|
1449
1436
|
frame.imagePreloadsSuppressed = previousImagePreloadsSuppressed || namespace === "html" && suppressesImagePreloads(type);
|
|
1450
1437
|
if (tracksLeadingNewline) frame.segment.chunks.push(leadingNewlineStartMarker);
|
|
1451
1438
|
try {
|
|
@@ -1459,21 +1446,11 @@ function renderHostElement(type, props, frame) {
|
|
|
1459
1446
|
frame.pendingLeadingNewline = previousPendingLeadingNewline;
|
|
1460
1447
|
}
|
|
1461
1448
|
if (tracksLeadingNewline) frame.segment.chunks.push(leadingNewlineEndMarker);
|
|
1462
|
-
if (
|
|
1449
|
+
if (isDocumentHead) frame.segment.write(documentHeadMarker);
|
|
1463
1450
|
writeElementEnd(type, frame.segment);
|
|
1464
1451
|
}
|
|
1465
|
-
function
|
|
1466
|
-
|
|
1467
|
-
if (normalizedType === "svg") return "svg";
|
|
1468
|
-
if (normalizedType === "math") return "mathml";
|
|
1469
|
-
return parent;
|
|
1470
|
-
}
|
|
1471
|
-
function childHostNamespace(type, namespace) {
|
|
1472
|
-
return namespace === "svg" && type.toLowerCase() === "foreignobject" ? "html" : namespace;
|
|
1473
|
-
}
|
|
1474
|
-
function renderHostAsset(type, props, frame) {
|
|
1475
|
-
if (type.length < 4 || type.length > 6) return false;
|
|
1476
|
-
const normalizedType = type.toLowerCase();
|
|
1452
|
+
function renderHostAsset(normalizedType, props, frame) {
|
|
1453
|
+
if (normalizedType.length < 4 || normalizedType.length > 6) return false;
|
|
1477
1454
|
switch (normalizedType) {
|
|
1478
1455
|
case "link":
|
|
1479
1456
|
case "meta":
|
|
@@ -1497,144 +1474,106 @@ function viewTransitionHostProps(props, viewTransition) {
|
|
|
1497
1474
|
return nextProps;
|
|
1498
1475
|
}
|
|
1499
1476
|
function spawnSuspendedTask(frame, node, thenable, childIndexBase) {
|
|
1500
|
-
const
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
textEmbedded: true
|
|
1504
|
-
});
|
|
1477
|
+
const segment = createSegment(frame.segment.chunks.length);
|
|
1478
|
+
segment.lastPushedText = frame.segment.lastPushedText;
|
|
1479
|
+
segment.textEmbedded = true;
|
|
1505
1480
|
frame.segment.lastPushedText = false;
|
|
1506
1481
|
frame.segment.children.push(segment);
|
|
1507
|
-
const task = createTask(
|
|
1508
|
-
|
|
1482
|
+
const task = createTask(node, forkFrame(frame, segment), childIndexBase);
|
|
1483
|
+
const ping = () => pingTask(task);
|
|
1484
|
+
thenable.then(ping, ping);
|
|
1509
1485
|
}
|
|
1510
|
-
function pingTask(
|
|
1486
|
+
function pingTask(task) {
|
|
1487
|
+
const { request } = task.frame;
|
|
1511
1488
|
if (request.status === "closed" || request.status === "aborting") return;
|
|
1489
|
+
const shouldSchedule = request.pingedTasks.length === 0;
|
|
1512
1490
|
request.pingedTasks.push(task);
|
|
1513
|
-
if (request
|
|
1514
|
-
request.workScheduled = true;
|
|
1515
|
-
queueMicrotask(() => {
|
|
1516
|
-
request.workScheduled = false;
|
|
1517
|
-
performWork(request);
|
|
1518
|
-
});
|
|
1491
|
+
if (shouldSchedule) queueMicrotask(() => performWork(request));
|
|
1519
1492
|
}
|
|
1520
|
-
function
|
|
1521
|
-
request
|
|
1522
|
-
const boundary = task.boundary;
|
|
1493
|
+
function settleTask(task, outcome, error) {
|
|
1494
|
+
const { boundary, request, segment, stack } = task.frame;
|
|
1523
1495
|
if (boundary === null) {
|
|
1524
1496
|
request.pendingRootTasks -= 1;
|
|
1525
|
-
if (
|
|
1497
|
+
if (outcome === "errored") {
|
|
1498
|
+
fatalError(request, error);
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1526
1501
|
if (request.pendingRootTasks === 0) finishRootShell(request);
|
|
1527
1502
|
} else {
|
|
1528
1503
|
boundary.pendingTasks -= 1;
|
|
1529
|
-
if (
|
|
1530
|
-
if (
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
request.pendingTasks -= 1;
|
|
1536
|
-
const boundary = task.boundary;
|
|
1537
|
-
if (boundary === null) {
|
|
1538
|
-
request.pendingRootTasks -= 1;
|
|
1539
|
-
fatalError(request, error);
|
|
1540
|
-
return;
|
|
1504
|
+
if (outcome === "errored") markBoundaryClientRendered(request, boundary, error, stack);
|
|
1505
|
+
else if (outcome === "completed" && segment.parentFlushed) boundary.completedSegments.push(segment);
|
|
1506
|
+
if (outcome !== "errored") {
|
|
1507
|
+
const boundaryCompleted = completeBoundaryIfReady(request, boundary);
|
|
1508
|
+
if (outcome === "completed" && !boundaryCompleted && boundary.parentFlushed) request.partialBoundaries.add(boundary);
|
|
1509
|
+
}
|
|
1541
1510
|
}
|
|
1542
|
-
|
|
1543
|
-
markBoundaryClientRendered(request, boundary, error, task.stack);
|
|
1544
|
-
if (request.pendingTasks === 0) request.allReady.resolve(void 0);
|
|
1511
|
+
if (request.abortableTasks.size === 0) request.allReady.resolve(void 0);
|
|
1545
1512
|
}
|
|
1546
|
-
function detachTask(
|
|
1547
|
-
task.
|
|
1548
|
-
request.abortableTasks.delete(task);
|
|
1513
|
+
function detachTask(task) {
|
|
1514
|
+
task.frame.fallbackTasks?.delete(task);
|
|
1515
|
+
return task.frame.request.abortableTasks.delete(task);
|
|
1549
1516
|
}
|
|
1550
|
-
function abortTask(
|
|
1551
|
-
if (!
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
const boundary = task.boundary;
|
|
1556
|
-
if (boundary === null) {
|
|
1557
|
-
request.pendingRootTasks -= 1;
|
|
1558
|
-
if (request.pendingRootTasks === 0) finishRootShell(request);
|
|
1559
|
-
} else {
|
|
1560
|
-
boundary.pendingTasks -= 1;
|
|
1561
|
-
completeBoundaryIfReady(request, boundary);
|
|
1562
|
-
}
|
|
1563
|
-
if (request.pendingTasks === 0) request.allReady.resolve(void 0);
|
|
1517
|
+
function abortTask(task) {
|
|
1518
|
+
if (!detachTask(task)) return;
|
|
1519
|
+
const { frame } = task;
|
|
1520
|
+
frame.segment.status = "completed";
|
|
1521
|
+
settleTask(task, "aborted");
|
|
1564
1522
|
}
|
|
1565
1523
|
function completeBoundaryIfReady(request, boundary) {
|
|
1566
1524
|
if (boundary.pendingTasks !== 0 || boundary.status !== "pending") return false;
|
|
1567
1525
|
boundary.status = "completed";
|
|
1568
|
-
|
|
1526
|
+
for (const fallbackTask of boundary.fallbackTasks) abortTask(fallbackTask);
|
|
1569
1527
|
if (boundary.parentFlushed) request.completedBoundaries.add(boundary);
|
|
1570
1528
|
return true;
|
|
1571
1529
|
}
|
|
1572
|
-
function abortFallbackTasks(request, boundary) {
|
|
1573
|
-
for (const fallbackTask of Array.from(boundary.fallbackAbortableTasks)) abortTask(request, fallbackTask);
|
|
1574
|
-
}
|
|
1575
1530
|
function markBoundaryClientRendered(request, boundary, error, stack, payload) {
|
|
1576
1531
|
if (boundary.status !== "client-rendered") {
|
|
1577
1532
|
boundary.status = "client-rendered";
|
|
1578
|
-
boundary.error = payload ??
|
|
1533
|
+
boundary.error = payload ?? serverErrorPayload(error, stackForError(error, stack), request.onError);
|
|
1579
1534
|
}
|
|
1580
|
-
boundary.completedSegments =
|
|
1535
|
+
boundary.completedSegments.length = 0;
|
|
1581
1536
|
request.completedBoundaries.delete(boundary);
|
|
1582
1537
|
request.partialBoundaries.delete(boundary);
|
|
1583
|
-
for (const task of
|
|
1584
|
-
for (const task of
|
|
1538
|
+
for (const task of request.abortableTasks) if (task.frame.boundary === boundary) abortTask(task);
|
|
1539
|
+
for (const task of boundary.fallbackTasks) abortTask(task);
|
|
1585
1540
|
if (boundary.parentFlushed) request.clientRenderedBoundaries.add(boundary);
|
|
1586
1541
|
}
|
|
1587
1542
|
function abort(request, reason) {
|
|
1588
1543
|
if (request.status === "closed") return;
|
|
1589
|
-
request.cleanupAbortListener();
|
|
1590
1544
|
request.status = "aborting";
|
|
1591
|
-
request.dataStore.dispose();
|
|
1592
1545
|
const error = abortError(reason);
|
|
1593
|
-
request.
|
|
1546
|
+
request.abortReason = error;
|
|
1594
1547
|
if (request.pendingRootTasks > 0) {
|
|
1595
1548
|
fatalError(request, error);
|
|
1596
1549
|
return;
|
|
1597
1550
|
}
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1551
|
+
request.dispose();
|
|
1552
|
+
for (const task of request.abortableTasks) {
|
|
1553
|
+
const { boundary, stack } = task.frame;
|
|
1554
|
+
if (boundary !== null) markBoundaryClientRendered(request, boundary, error, stack, {});
|
|
1601
1555
|
}
|
|
1602
1556
|
request.abortableTasks.clear();
|
|
1603
|
-
request.pendingTasks = 0;
|
|
1604
1557
|
request.allReady.resolve(void 0);
|
|
1605
1558
|
flushCompletedQueues(request);
|
|
1606
1559
|
}
|
|
1607
1560
|
function fatalError(request, error) {
|
|
1608
1561
|
if (request.status === "closed") return;
|
|
1609
|
-
request.cleanupAbortListener();
|
|
1610
1562
|
request.status = "closed";
|
|
1611
|
-
request.
|
|
1612
|
-
request.fatalError = error;
|
|
1563
|
+
request.dispose();
|
|
1613
1564
|
request.headReady.reject(error);
|
|
1614
1565
|
request.shellReady.reject(error);
|
|
1615
1566
|
request.allReady.reject(error);
|
|
1616
1567
|
request.controller?.error(error);
|
|
1617
1568
|
}
|
|
1618
1569
|
function finishRootShell(request) {
|
|
1619
|
-
if (request.
|
|
1570
|
+
if (request.documentHasHead === false) {
|
|
1620
1571
|
fatalError(request, invalidDocumentShellError());
|
|
1621
1572
|
return;
|
|
1622
1573
|
}
|
|
1623
1574
|
if (!request.prerender) sealHead(request);
|
|
1624
1575
|
request.shellReady.resolve(void 0);
|
|
1625
1576
|
}
|
|
1626
|
-
function enqueueUnique(queue, item) {
|
|
1627
|
-
if (!queue.includes(item)) queue.push(item);
|
|
1628
|
-
}
|
|
1629
|
-
function reportBoundaryError(request, error, stack) {
|
|
1630
|
-
const info = { componentStack: componentStack(stackForError(error, stack)) };
|
|
1631
|
-
if (request.onError === void 0) return { message: errorMessage(error) };
|
|
1632
|
-
try {
|
|
1633
|
-
return request.onError(error, info) ?? {};
|
|
1634
|
-
} catch {
|
|
1635
|
-
return {};
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
1577
|
function recordErrorStack(error, stack) {
|
|
1639
1578
|
if (stack === null) return;
|
|
1640
1579
|
if (typeof error !== "object" && typeof error !== "function") return;
|
|
@@ -1648,29 +1587,14 @@ function stackForError(error, fallback) {
|
|
|
1648
1587
|
function createRuntimeName(identifierPrefix) {
|
|
1649
1588
|
const id = nextRuntimeId.toString(36);
|
|
1650
1589
|
nextRuntimeId += 1;
|
|
1651
|
-
const prefix = identifierPrefix
|
|
1590
|
+
const prefix = identifierPrefix.replace(/[^A-Za-z0-9_$]/g, "_");
|
|
1652
1591
|
return prefix === "" ? `__figSSR_${id}` : `__figSSR_${prefix}_${id}`;
|
|
1653
1592
|
}
|
|
1654
|
-
function writeDocumentHeadMarker(segment) {
|
|
1655
|
-
segment.lastPushedText = false;
|
|
1656
|
-
segment.chunks.push(documentHeadMarker);
|
|
1657
|
-
}
|
|
1658
1593
|
function consumePendingLeadingNewline(frame) {
|
|
1659
1594
|
const pending = frame.pendingLeadingNewline;
|
|
1660
1595
|
frame.pendingLeadingNewline = false;
|
|
1661
1596
|
return pending;
|
|
1662
1597
|
}
|
|
1663
|
-
function leadingNewlineStrippedHost(type) {
|
|
1664
|
-
return type === "pre" || type === "textarea";
|
|
1665
|
-
}
|
|
1666
|
-
function writeLeadingNewlineText(text, segment) {
|
|
1667
|
-
writeText(text, { write(value) {
|
|
1668
|
-
segment.write({ value });
|
|
1669
|
-
} });
|
|
1670
|
-
}
|
|
1671
|
-
function preserveParserStrippedLeadingNewline(text) {
|
|
1672
|
-
return text.startsWith("\n") ? `\n${text}` : text;
|
|
1673
|
-
}
|
|
1674
1598
|
function invalidDocumentShellError() {
|
|
1675
1599
|
return /* @__PURE__ */ new Error("renderToDocumentStream requires the root to render an <html> document with a <head>.");
|
|
1676
1600
|
}
|
|
@@ -1678,7 +1602,7 @@ function throwIfAborted(signal) {
|
|
|
1678
1602
|
if (signal?.aborted === true) throw abortReason(signal.reason);
|
|
1679
1603
|
}
|
|
1680
1604
|
function throwIfAborting(request) {
|
|
1681
|
-
if (request.status === "aborting") throw abortReason(request.
|
|
1605
|
+
if (request.status === "aborting") throw abortReason(request.abortReason);
|
|
1682
1606
|
}
|
|
1683
1607
|
function abortError(reason) {
|
|
1684
1608
|
if (reason instanceof Error) return reason;
|
|
@@ -1709,17 +1633,8 @@ function renderToStream(node, options = {}) {
|
|
|
1709
1633
|
return createServerRenderRequest(node, options);
|
|
1710
1634
|
}
|
|
1711
1635
|
function renderToDocumentStream(node, options = {}) {
|
|
1712
|
-
const
|
|
1713
|
-
return
|
|
1714
|
-
abort: (reason) => request.abort(reason),
|
|
1715
|
-
allReady: request.allReady,
|
|
1716
|
-
contentType: request.contentType,
|
|
1717
|
-
data: request.data,
|
|
1718
|
-
getData: () => request.getData(),
|
|
1719
|
-
getPreloadHeader: (headerOptions) => request.getPreloadHeader(headerOptions),
|
|
1720
|
-
shellReady: request.shellReady,
|
|
1721
|
-
stream: request.stream
|
|
1722
|
-
};
|
|
1636
|
+
const { getHead: _getHead, headReady: _headReady, ...result } = createServerRenderRequest(node, options, { document: true });
|
|
1637
|
+
return result;
|
|
1723
1638
|
}
|
|
1724
1639
|
/**
|
|
1725
1640
|
* The streamed output, buffered: awaits `allReady` and concatenates exactly
|
|
@@ -1745,8 +1660,8 @@ async function renderToDocumentHtml(node, options = {}) {
|
|
|
1745
1660
|
* Suspense content is emitted in logical position without streaming scripts.
|
|
1746
1661
|
*/
|
|
1747
1662
|
async function prerender(node, options = {}) {
|
|
1748
|
-
const
|
|
1749
|
-
const result = createServerRenderRequest(node,
|
|
1663
|
+
const document = options.document === true;
|
|
1664
|
+
const result = createServerRenderRequest(node, options, {
|
|
1750
1665
|
document,
|
|
1751
1666
|
prerender: true
|
|
1752
1667
|
});
|