@absolutejs/absolute 0.19.0-beta.365 → 0.19.0-beta.367
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/angular/browser.js +8 -12
- package/dist/angular/browser.js.map +4 -4
- package/dist/angular/index.js +4420 -4465
- package/dist/angular/index.js.map +8 -8
- package/dist/build.js +576 -24
- package/dist/build.js.map +10 -4
- package/dist/client/index.js +44 -45
- package/dist/client/index.js.map +4 -4
- package/dist/index.js +9572 -9596
- package/dist/index.js.map +13 -12
- package/dist/react/components/browser/index.js +18 -6
- package/dist/react/components/index.js +35 -16
- package/dist/react/components/index.js.map +6 -5
- package/dist/react/index.js +1762 -1794
- package/dist/react/index.js.map +12 -12
- package/dist/react/server.js +571 -3
- package/dist/react/server.js.map +11 -4
- package/dist/src/core/pageHandlers.d.ts +1 -1
- package/dist/src/react/index.d.ts +1 -1
- package/dist/src/react/streamingSlotCollection.d.ts +9 -0
- package/dist/svelte/index.js +1881 -1926
- package/dist/svelte/index.js.map +8 -8
- package/dist/vue/components/index.js +8 -12
- package/dist/vue/components/index.js.map +5 -5
- package/dist/vue/index.js +1929 -1976
- package/dist/vue/index.js.map +8 -8
- package/package.json +1 -1
package/dist/build.js
CHANGED
|
@@ -170019,10 +170019,10 @@ var routePropsCache, cacheRouteData = (pagePath, data) => {
|
|
|
170019
170019
|
result = injectBeforeClose(result, `<script type="module" src="${indexPath}"></script>`);
|
|
170020
170020
|
}
|
|
170021
170021
|
return result;
|
|
170022
|
-
}, renderAngularApp = async (deps, PageComponent, providers,
|
|
170022
|
+
}, renderAngularApp = async (deps, PageComponent, providers, document2) => {
|
|
170023
170023
|
const bootstrap = (context) => deps.bootstrapApplication(PageComponent, { providers }, context);
|
|
170024
170024
|
return withSuppressedAngularDevLogs(() => deps.renderApplication(bootstrap, {
|
|
170025
|
-
document,
|
|
170025
|
+
document: document2,
|
|
170026
170026
|
platformProviders: [],
|
|
170027
170027
|
url: "/"
|
|
170028
170028
|
}));
|
|
@@ -170187,9 +170187,9 @@ var angularIslandSelector = "abs-angular-island", getAngularIslandSelector = (_i
|
|
|
170187
170187
|
{ provide: deps.APP_BASE_HREF, useValue: "/" },
|
|
170188
170188
|
{ provide: propsToken, useValue: props }
|
|
170189
170189
|
];
|
|
170190
|
-
const
|
|
170190
|
+
const document2 = `<!DOCTYPE html><html><body><${selector}></${selector}></body></html>`;
|
|
170191
170191
|
const html = await withSuppressedAngularDevLogs(() => deps.renderApplication((context) => deps.bootstrapApplication(WrapperComponent, { providers }, context), {
|
|
170192
|
-
document,
|
|
170192
|
+
document: document2,
|
|
170193
170193
|
platformProviders: [],
|
|
170194
170194
|
url: "/"
|
|
170195
170195
|
}));
|
|
@@ -172556,7 +172556,7 @@ ${registrations}
|
|
|
172556
172556
|
({ tsLibDir } = cached);
|
|
172557
172557
|
cached.lastUsed = Date.now();
|
|
172558
172558
|
} else {
|
|
172559
|
-
const tsPath = __require.resolve("typescript");
|
|
172559
|
+
const tsPath = __require.resolve("/home/alexkahn/abs/absolutejs/node_modules/typescript/lib/typescript.js");
|
|
172560
172560
|
const tsRootDir = dirname8(tsPath);
|
|
172561
172561
|
tsLibDir = tsRootDir.endsWith("lib") ? tsRootDir : resolve15(tsRootDir, "lib");
|
|
172562
172562
|
const config = readConfiguration("./tsconfig.json");
|
|
@@ -176076,6 +176076,568 @@ var init_pageHandler = __esm(() => {
|
|
|
176076
176076
|
setSsrContextGetter(() => angularSsrContext.getStore());
|
|
176077
176077
|
});
|
|
176078
176078
|
|
|
176079
|
+
// src/client/streamSwap.ts
|
|
176080
|
+
var streamSwapRuntime = () => {
|
|
176081
|
+
if (window.__ABS_SLOT_RUNTIME__ === true)
|
|
176082
|
+
return;
|
|
176083
|
+
window.__ABS_SLOT_RUNTIME__ = true;
|
|
176084
|
+
window.__ABS_SLOT_PENDING__ = window.__ABS_SLOT_PENDING__ ?? {};
|
|
176085
|
+
const pending = window.__ABS_SLOT_PENDING__;
|
|
176086
|
+
const apply = (id, html) => {
|
|
176087
|
+
const node = document.getElementById(`slot-${id}`);
|
|
176088
|
+
if (!node) {
|
|
176089
|
+
pending[id] = html;
|
|
176090
|
+
return;
|
|
176091
|
+
}
|
|
176092
|
+
node.innerHTML = html;
|
|
176093
|
+
delete pending[id];
|
|
176094
|
+
};
|
|
176095
|
+
const flush = () => {
|
|
176096
|
+
for (const id in pending) {
|
|
176097
|
+
if (!Object.prototype.hasOwnProperty.call(pending, id))
|
|
176098
|
+
continue;
|
|
176099
|
+
apply(id, pending[id] ?? "");
|
|
176100
|
+
}
|
|
176101
|
+
};
|
|
176102
|
+
window.__ABS_SLOT_ENQUEUE__ = (id, html) => {
|
|
176103
|
+
apply(id, html);
|
|
176104
|
+
};
|
|
176105
|
+
if (typeof MutationObserver === "function") {
|
|
176106
|
+
const observer = new MutationObserver(flush);
|
|
176107
|
+
const root = document.documentElement ?? document.body ?? document;
|
|
176108
|
+
observer.observe(root, { childList: true, subtree: true });
|
|
176109
|
+
}
|
|
176110
|
+
if (document.readyState === "loading") {
|
|
176111
|
+
document.addEventListener("DOMContentLoaded", flush, { once: true });
|
|
176112
|
+
}
|
|
176113
|
+
flush();
|
|
176114
|
+
}, stripFunctionWrapper = (value) => {
|
|
176115
|
+
const start = value.indexOf("{");
|
|
176116
|
+
const end = value.lastIndexOf("}");
|
|
176117
|
+
if (start < 0 || end <= start)
|
|
176118
|
+
return "";
|
|
176119
|
+
return value.slice(start + 1, end);
|
|
176120
|
+
}, getStreamSwapRuntimeScript = () => `(function(){${stripFunctionWrapper(streamSwapRuntime.toString())}})();`;
|
|
176121
|
+
|
|
176122
|
+
// src/utils/escapeScriptContent.ts
|
|
176123
|
+
var ESCAPE_LOOKUP, ESCAPE_REGEX, escapeScriptContent = (content) => content.replace(ESCAPE_REGEX, (char) => {
|
|
176124
|
+
const escaped = ESCAPE_LOOKUP[char];
|
|
176125
|
+
return escaped !== undefined ? escaped : char;
|
|
176126
|
+
});
|
|
176127
|
+
var init_escapeScriptContent = __esm(() => {
|
|
176128
|
+
ESCAPE_LOOKUP = {
|
|
176129
|
+
"\u2028": "\\u2028",
|
|
176130
|
+
"\u2029": "\\u2029",
|
|
176131
|
+
"&": "\\u0026",
|
|
176132
|
+
"<": "\\u003C",
|
|
176133
|
+
">": "\\u003E"
|
|
176134
|
+
};
|
|
176135
|
+
ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
|
176136
|
+
});
|
|
176137
|
+
|
|
176138
|
+
// src/utils/streamingSlots.ts
|
|
176139
|
+
var SLOT_ID_PREFIX = "abs-slot-", SLOT_PLACEHOLDER_PREFIX = "slot-", CLOSING_HEAD_TAG2 = "</head>", CLOSING_HEAD_TAG_LENGTH, CLOSING_PAGE_TAG_REGEX, STREAMING_RUNTIME_GLOBAL = "__ABS_SLOT_ENQUEUE__", STREAMING_PENDING_GLOBAL = "__ABS_SLOT_PENDING__", STREAM_TAIL_LOOKBEHIND = 128, STREAMING_SLOT_TIMEOUT_MS = 5000, STREAMING_SLOT_MAX_PER_RESPONSE = 128, STREAMING_SLOT_MAX_HTML_BYTES = 64000, createSlotPlaceholderId = (id) => `${SLOT_PLACEHOLDER_PREFIX}${id}`, createSlotPatchStatement = (id, html) => `(window.${STREAMING_RUNTIME_GLOBAL}||function(i,h){window.${STREAMING_PENDING_GLOBAL}=window.${STREAMING_PENDING_GLOBAL}||{};window.${STREAMING_PENDING_GLOBAL}[i]=h;})(${JSON.stringify(id)},${JSON.stringify(html)});`, createNonceAttr = (nonce) => nonce ? ` nonce="${nonce}"` : "", createStreamingSlotId = () => `${SLOT_ID_PREFIX}${Math.random().toString(36).slice(2, 10)}`, getStreamingSlotsRuntimeScript = () => getStreamSwapRuntimeScript(), renderStreamingSlotsRuntimeTag = (nonce) => `<script${createNonceAttr(nonce)}>${escapeScriptContent(getStreamingSlotsRuntimeScript())}</script>`, renderStreamingSlotPlaceholder = (id, fallbackHtml = "") => `<div id="${createSlotPlaceholderId(id)}" data-absolute-slot="true">${fallbackHtml}</div>`, renderStreamingSlotPatchTag = (id, html, nonce) => `<script${createNonceAttr(nonce)}>${escapeScriptContent(createSlotPatchStatement(id, html))}</script>`, injectHtmlIntoHead = (html, injection) => {
|
|
176140
|
+
const closingHeadIndex = html.indexOf(CLOSING_HEAD_TAG2);
|
|
176141
|
+
if (closingHeadIndex >= 0) {
|
|
176142
|
+
return `${html.slice(0, closingHeadIndex)}${injection}${html.slice(closingHeadIndex)}`;
|
|
176143
|
+
}
|
|
176144
|
+
return `${html}${injection}`;
|
|
176145
|
+
}, toUint8 = (value, encoder) => encoder.encode(value), currentStreamingSlotPolicy, clonePolicy = (policy) => ({
|
|
176146
|
+
...policy
|
|
176147
|
+
}), normalizeSlotBytes = (value, fallback) => {
|
|
176148
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
|
|
176149
|
+
return Math.floor(value);
|
|
176150
|
+
}
|
|
176151
|
+
return fallback;
|
|
176152
|
+
}, normalizeSlotText = (value, fallback) => typeof value === "string" ? value : fallback, normalizeSlotError = (value, fallback) => typeof value === "string" ? value : fallback, hasPolicyValue = (policy, key) => Object.prototype.hasOwnProperty.call(policy, key), applyStreamingSlotPolicyOverrides = (base, overridePolicy = {}) => ({
|
|
176153
|
+
timeoutMs: hasPolicyValue(overridePolicy, "timeoutMs") ? normalizeSlotBytes(overridePolicy.timeoutMs, base.timeoutMs) : base.timeoutMs,
|
|
176154
|
+
fallbackHtml: hasPolicyValue(overridePolicy, "fallbackHtml") ? normalizeSlotText(overridePolicy.fallbackHtml, "") : base.fallbackHtml,
|
|
176155
|
+
errorHtml: hasPolicyValue(overridePolicy, "errorHtml") ? normalizeSlotError(overridePolicy.errorHtml) : base.errorHtml,
|
|
176156
|
+
maxSlotsPerResponse: hasPolicyValue(overridePolicy, "maxSlotsPerResponse") ? normalizeSlotBytes(overridePolicy.maxSlotsPerResponse, base.maxSlotsPerResponse) : base.maxSlotsPerResponse,
|
|
176157
|
+
maxSlotHtmlSizeBytes: hasPolicyValue(overridePolicy, "maxSlotHtmlSizeBytes") ? normalizeSlotBytes(overridePolicy.maxSlotHtmlSizeBytes, base.maxSlotHtmlSizeBytes) : base.maxSlotHtmlSizeBytes,
|
|
176158
|
+
onError: hasPolicyValue(overridePolicy, "onError") ? overridePolicy.onError : base.onError,
|
|
176159
|
+
onSlotMetric: hasPolicyValue(overridePolicy, "onSlotMetric") ? overridePolicy.onSlotMetric : base.onSlotMetric
|
|
176160
|
+
}), createCombinedSlotErrorHandler = (policyOnError, enhancerOnError) => {
|
|
176161
|
+
if (!policyOnError && !enhancerOnError)
|
|
176162
|
+
return;
|
|
176163
|
+
return (error, slot) => {
|
|
176164
|
+
policyOnError?.(error, slot);
|
|
176165
|
+
enhancerOnError?.(error, slot);
|
|
176166
|
+
};
|
|
176167
|
+
}, createCombinedSlotMetricHandler = (policyOnSlotMetric, callOnSlotMetric) => {
|
|
176168
|
+
if (!policyOnSlotMetric && !callOnSlotMetric)
|
|
176169
|
+
return;
|
|
176170
|
+
return (metric) => {
|
|
176171
|
+
policyOnSlotMetric?.(metric);
|
|
176172
|
+
callOnSlotMetric?.(metric);
|
|
176173
|
+
};
|
|
176174
|
+
}, resolveStreamingSlotPolicy = (overridePolicy = {}) => {
|
|
176175
|
+
const base = getStreamingSlotPolicy();
|
|
176176
|
+
return applyStreamingSlotPolicyOverrides(base, overridePolicy);
|
|
176177
|
+
}, getStreamingSlotPolicy = () => clonePolicy(currentStreamingSlotPolicy), setStreamingSlotPolicy = (policy = {}) => {
|
|
176178
|
+
const base = getStreamingSlotPolicy();
|
|
176179
|
+
currentStreamingSlotPolicy = applyStreamingSlotPolicyOverrides(base, policy);
|
|
176180
|
+
}, withStreamingSlotPolicy = async (policy, callback) => {
|
|
176181
|
+
const previous = getStreamingSlotPolicy();
|
|
176182
|
+
setStreamingSlotPolicy(policy);
|
|
176183
|
+
try {
|
|
176184
|
+
return await callback();
|
|
176185
|
+
} finally {
|
|
176186
|
+
currentStreamingSlotPolicy = previous;
|
|
176187
|
+
}
|
|
176188
|
+
}, emitSlotMetric = (metric, onSlotMetric) => {
|
|
176189
|
+
onSlotMetric?.(metric);
|
|
176190
|
+
}, createTimeoutError = (slot, timeoutMs) => {
|
|
176191
|
+
const error = new Error(`Streaming slot "${slot.id}" timed out after ${timeoutMs}ms`);
|
|
176192
|
+
error.__absTimeout = true;
|
|
176193
|
+
return error;
|
|
176194
|
+
}, toStreamingSlot = (slot, policy) => ({
|
|
176195
|
+
errorHtml: slot.errorHtml === undefined ? policy.errorHtml : slot.errorHtml,
|
|
176196
|
+
fallbackHtml: normalizeSlotText(slot.fallbackHtml, policy.fallbackHtml),
|
|
176197
|
+
id: slot.id ?? createStreamingSlotId(),
|
|
176198
|
+
timeoutMs: normalizeSlotBytes(slot.timeoutMs, policy.timeoutMs),
|
|
176199
|
+
resolve: slot.resolve
|
|
176200
|
+
}), prepareSlots = ({
|
|
176201
|
+
policy,
|
|
176202
|
+
slots,
|
|
176203
|
+
onError,
|
|
176204
|
+
onSlotMetric
|
|
176205
|
+
}) => {
|
|
176206
|
+
const preparedSlots = slots.map((slot) => toStreamingSlot(slot, policy));
|
|
176207
|
+
const maxSlotsPerResponse = policy.maxSlotsPerResponse;
|
|
176208
|
+
if (maxSlotsPerResponse === 0) {
|
|
176209
|
+
const error = new Error("Streaming slot limit is set to 0");
|
|
176210
|
+
for (const slot of preparedSlots) {
|
|
176211
|
+
onError?.(error, slot);
|
|
176212
|
+
emitSlotMetric({
|
|
176213
|
+
type: "dropped",
|
|
176214
|
+
slotId: slot.id,
|
|
176215
|
+
reason: "maxSlotsPerResponse is 0"
|
|
176216
|
+
}, onSlotMetric);
|
|
176217
|
+
}
|
|
176218
|
+
return [];
|
|
176219
|
+
}
|
|
176220
|
+
if (preparedSlots.length <= maxSlotsPerResponse) {
|
|
176221
|
+
preparedSlots.forEach((slot) => emitSlotMetric({
|
|
176222
|
+
type: "prepared",
|
|
176223
|
+
slotId: slot.id
|
|
176224
|
+
}, onSlotMetric));
|
|
176225
|
+
return preparedSlots;
|
|
176226
|
+
}
|
|
176227
|
+
const keptSlots = preparedSlots.slice(0, maxSlotsPerResponse);
|
|
176228
|
+
const droppedSlots = preparedSlots.slice(maxSlotsPerResponse);
|
|
176229
|
+
droppedSlots.forEach((slot) => {
|
|
176230
|
+
onError?.(new Error(`Streaming slot "${slot.id}" dropped because ${maxSlotsPerResponse} slots is the configured maximum`), slot);
|
|
176231
|
+
emitSlotMetric({
|
|
176232
|
+
type: "dropped",
|
|
176233
|
+
slotId: slot.id,
|
|
176234
|
+
reason: `maxSlotsPerResponse is ${maxSlotsPerResponse}`
|
|
176235
|
+
}, onSlotMetric);
|
|
176236
|
+
});
|
|
176237
|
+
keptSlots.forEach((slot) => emitSlotMetric({
|
|
176238
|
+
type: "prepared",
|
|
176239
|
+
slotId: slot.id
|
|
176240
|
+
}, onSlotMetric));
|
|
176241
|
+
return keptSlots;
|
|
176242
|
+
}, htmlByteLength = (value, encoder) => encoder.encode(value).length, resolveSlot = async (slot, onError, policy, onSlotMetric) => {
|
|
176243
|
+
const safePolicy = policy ?? getStreamingSlotPolicy();
|
|
176244
|
+
const encoder = new TextEncoder;
|
|
176245
|
+
const start = Date.now();
|
|
176246
|
+
try {
|
|
176247
|
+
const maybeAsyncValue = Promise.resolve(slot.resolve());
|
|
176248
|
+
const resolved = typeof slot.timeoutMs === "number" && slot.timeoutMs > 0 ? await Promise.race([
|
|
176249
|
+
maybeAsyncValue,
|
|
176250
|
+
new Promise((_, reject) => setTimeout(() => {
|
|
176251
|
+
reject(createTimeoutError(slot, slot.timeoutMs ?? 0));
|
|
176252
|
+
}, slot.timeoutMs))
|
|
176253
|
+
]) : await maybeAsyncValue;
|
|
176254
|
+
const html = typeof resolved === "string" ? resolved : `${resolved}`;
|
|
176255
|
+
if (safePolicy.maxSlotHtmlSizeBytes > 0 && htmlByteLength(html, encoder) > safePolicy.maxSlotHtmlSizeBytes) {
|
|
176256
|
+
const bytes2 = htmlByteLength(html, encoder);
|
|
176257
|
+
const error = new Error(`Streaming slot "${slot.id}" exceeded max payload size of ${safePolicy.maxSlotHtmlSizeBytes} bytes`);
|
|
176258
|
+
const durationMs2 = Date.now() - start;
|
|
176259
|
+
onError?.(error, slot);
|
|
176260
|
+
emitSlotMetric({
|
|
176261
|
+
type: "size_exceeded",
|
|
176262
|
+
slotId: slot.id,
|
|
176263
|
+
durationMs: durationMs2,
|
|
176264
|
+
bytes: bytes2,
|
|
176265
|
+
error
|
|
176266
|
+
}, onSlotMetric);
|
|
176267
|
+
const fallbackHtml = typeof slot.errorHtml === "string" ? slot.errorHtml : null;
|
|
176268
|
+
return {
|
|
176269
|
+
html: fallbackHtml,
|
|
176270
|
+
id: slot.id,
|
|
176271
|
+
durationMs: durationMs2,
|
|
176272
|
+
bytes: fallbackHtml === null ? 0 : htmlByteLength(fallbackHtml, encoder)
|
|
176273
|
+
};
|
|
176274
|
+
}
|
|
176275
|
+
const durationMs = Date.now() - start;
|
|
176276
|
+
const bytes = htmlByteLength(html, encoder);
|
|
176277
|
+
emitSlotMetric({
|
|
176278
|
+
type: "resolved",
|
|
176279
|
+
slotId: slot.id,
|
|
176280
|
+
durationMs,
|
|
176281
|
+
bytes
|
|
176282
|
+
}, onSlotMetric);
|
|
176283
|
+
return {
|
|
176284
|
+
html,
|
|
176285
|
+
id: slot.id,
|
|
176286
|
+
durationMs,
|
|
176287
|
+
bytes
|
|
176288
|
+
};
|
|
176289
|
+
} catch (error) {
|
|
176290
|
+
const durationMs = Date.now() - start;
|
|
176291
|
+
onError?.(error, slot);
|
|
176292
|
+
emitSlotMetric({
|
|
176293
|
+
type: error?.__absTimeout === true ? "timeout" : "error",
|
|
176294
|
+
slotId: slot.id,
|
|
176295
|
+
durationMs,
|
|
176296
|
+
error
|
|
176297
|
+
}, onSlotMetric);
|
|
176298
|
+
if (typeof slot.errorHtml === "string") {
|
|
176299
|
+
const html = slot.errorHtml;
|
|
176300
|
+
return {
|
|
176301
|
+
html,
|
|
176302
|
+
id: slot.id,
|
|
176303
|
+
durationMs,
|
|
176304
|
+
bytes: htmlByteLength(html, encoder)
|
|
176305
|
+
};
|
|
176306
|
+
}
|
|
176307
|
+
return {
|
|
176308
|
+
html: null,
|
|
176309
|
+
id: slot.id,
|
|
176310
|
+
durationMs,
|
|
176311
|
+
bytes: 0
|
|
176312
|
+
};
|
|
176313
|
+
}
|
|
176314
|
+
}, nextResolvedSlot = async (pending) => {
|
|
176315
|
+
const wrapped = pending.map((promise) => promise.then((result) => ({
|
|
176316
|
+
original: promise,
|
|
176317
|
+
result
|
|
176318
|
+
})));
|
|
176319
|
+
return Promise.race(wrapped);
|
|
176320
|
+
}, streamChunkToString2 = (value, decoder) => typeof value === "string" ? value : decoder.decode(value, { stream: true }), streamOutOfOrderSlots = ({
|
|
176321
|
+
footerHtml = "",
|
|
176322
|
+
headerHtml = "",
|
|
176323
|
+
nonce,
|
|
176324
|
+
policy,
|
|
176325
|
+
onSlotMetric,
|
|
176326
|
+
onError,
|
|
176327
|
+
slots
|
|
176328
|
+
}) => {
|
|
176329
|
+
const resolvedPolicy = resolveStreamingSlotPolicy(policy);
|
|
176330
|
+
const combinedOnError = createCombinedSlotErrorHandler(resolvedPolicy.onError, onError);
|
|
176331
|
+
const combinedOnSlotMetric = createCombinedSlotMetricHandler(resolvedPolicy.onSlotMetric, onSlotMetric);
|
|
176332
|
+
const effectivePolicy = {
|
|
176333
|
+
...resolvedPolicy,
|
|
176334
|
+
onSlotMetric: combinedOnSlotMetric
|
|
176335
|
+
};
|
|
176336
|
+
const preparedSlots = prepareSlots({
|
|
176337
|
+
policy: effectivePolicy,
|
|
176338
|
+
slots,
|
|
176339
|
+
onError: combinedOnError,
|
|
176340
|
+
onSlotMetric: combinedOnSlotMetric
|
|
176341
|
+
});
|
|
176342
|
+
const encoder = new TextEncoder;
|
|
176343
|
+
return new ReadableStream({
|
|
176344
|
+
async start(controller) {
|
|
176345
|
+
try {
|
|
176346
|
+
let header = headerHtml;
|
|
176347
|
+
if (preparedSlots.length > 0 && !header.includes(STREAMING_RUNTIME_GLOBAL)) {
|
|
176348
|
+
header = injectHtmlIntoHead(header, renderStreamingSlotsRuntimeTag(nonce));
|
|
176349
|
+
}
|
|
176350
|
+
controller.enqueue(toUint8(header, encoder));
|
|
176351
|
+
const pending = preparedSlots.map((slot) => {
|
|
176352
|
+
const fallback = renderStreamingSlotPlaceholder(slot.id, slot.fallbackHtml ?? "");
|
|
176353
|
+
controller.enqueue(toUint8(fallback, encoder));
|
|
176354
|
+
return resolveSlot(slot, combinedOnError, effectivePolicy, combinedOnSlotMetric);
|
|
176355
|
+
});
|
|
176356
|
+
while (pending.length > 0) {
|
|
176357
|
+
const { original, result } = await nextResolvedSlot(pending);
|
|
176358
|
+
const index = pending.indexOf(original);
|
|
176359
|
+
if (index >= 0)
|
|
176360
|
+
pending.splice(index, 1);
|
|
176361
|
+
if (result.html === null)
|
|
176362
|
+
continue;
|
|
176363
|
+
emitSlotMetric({
|
|
176364
|
+
type: "patched",
|
|
176365
|
+
slotId: result.id,
|
|
176366
|
+
durationMs: result.durationMs,
|
|
176367
|
+
bytes: result.bytes
|
|
176368
|
+
}, combinedOnSlotMetric);
|
|
176369
|
+
controller.enqueue(toUint8(renderStreamingSlotPatchTag(result.id, result.html, nonce), encoder));
|
|
176370
|
+
}
|
|
176371
|
+
if (footerHtml.length > 0) {
|
|
176372
|
+
controller.enqueue(toUint8(footerHtml, encoder));
|
|
176373
|
+
}
|
|
176374
|
+
controller.close();
|
|
176375
|
+
} catch (error) {
|
|
176376
|
+
controller.error(error);
|
|
176377
|
+
}
|
|
176378
|
+
}
|
|
176379
|
+
});
|
|
176380
|
+
}, injectStreamingRuntimeIntoStream = (stream, nonce) => {
|
|
176381
|
+
const runtimeTag = renderStreamingSlotsRuntimeTag(nonce);
|
|
176382
|
+
const encoder = new TextEncoder;
|
|
176383
|
+
const decoder = new TextDecoder;
|
|
176384
|
+
const lookbehind = CLOSING_HEAD_TAG_LENGTH - 1;
|
|
176385
|
+
return new ReadableStream({
|
|
176386
|
+
async start(controller) {
|
|
176387
|
+
const reader = stream.getReader();
|
|
176388
|
+
let injected = false;
|
|
176389
|
+
let pending = "";
|
|
176390
|
+
try {
|
|
176391
|
+
for (;; ) {
|
|
176392
|
+
const { done, value } = await reader.read();
|
|
176393
|
+
if (done)
|
|
176394
|
+
break;
|
|
176395
|
+
if (!value)
|
|
176396
|
+
continue;
|
|
176397
|
+
pending += streamChunkToString2(value, decoder);
|
|
176398
|
+
if (injected) {
|
|
176399
|
+
controller.enqueue(encoder.encode(pending));
|
|
176400
|
+
pending = "";
|
|
176401
|
+
continue;
|
|
176402
|
+
}
|
|
176403
|
+
const headIndex = pending.indexOf(CLOSING_HEAD_TAG2);
|
|
176404
|
+
if (headIndex >= 0) {
|
|
176405
|
+
const withRuntime = `${pending.slice(0, headIndex)}${runtimeTag}${pending.slice(headIndex)}`;
|
|
176406
|
+
controller.enqueue(encoder.encode(withRuntime));
|
|
176407
|
+
pending = "";
|
|
176408
|
+
injected = true;
|
|
176409
|
+
continue;
|
|
176410
|
+
}
|
|
176411
|
+
if (pending.length > lookbehind) {
|
|
176412
|
+
const safeText = pending.slice(0, pending.length - lookbehind);
|
|
176413
|
+
controller.enqueue(encoder.encode(safeText));
|
|
176414
|
+
pending = pending.slice(-lookbehind);
|
|
176415
|
+
}
|
|
176416
|
+
}
|
|
176417
|
+
pending += decoder.decode();
|
|
176418
|
+
if (!injected) {
|
|
176419
|
+
pending = injectHtmlIntoHead(pending, runtimeTag);
|
|
176420
|
+
}
|
|
176421
|
+
if (pending.length > 0) {
|
|
176422
|
+
controller.enqueue(encoder.encode(pending));
|
|
176423
|
+
}
|
|
176424
|
+
controller.close();
|
|
176425
|
+
} catch (error) {
|
|
176426
|
+
controller.error(error);
|
|
176427
|
+
}
|
|
176428
|
+
}
|
|
176429
|
+
});
|
|
176430
|
+
}, appendStreamingSlotPatchesToStream = (stream, slots = [], {
|
|
176431
|
+
injectRuntime = true,
|
|
176432
|
+
nonce,
|
|
176433
|
+
onError,
|
|
176434
|
+
onSlotMetric,
|
|
176435
|
+
policy
|
|
176436
|
+
} = {}) => {
|
|
176437
|
+
const resolvedPolicy = resolveStreamingSlotPolicy(policy);
|
|
176438
|
+
const combinedOnError = createCombinedSlotErrorHandler(resolvedPolicy.onError, onError);
|
|
176439
|
+
const combinedOnSlotMetric = createCombinedSlotMetricHandler(resolvedPolicy.onSlotMetric, onSlotMetric);
|
|
176440
|
+
const effectivePolicy = {
|
|
176441
|
+
...resolvedPolicy,
|
|
176442
|
+
onSlotMetric: combinedOnSlotMetric
|
|
176443
|
+
};
|
|
176444
|
+
const preparedSlots = prepareSlots({
|
|
176445
|
+
policy: effectivePolicy,
|
|
176446
|
+
slots,
|
|
176447
|
+
onError: combinedOnError,
|
|
176448
|
+
onSlotMetric: combinedOnSlotMetric
|
|
176449
|
+
});
|
|
176450
|
+
if (preparedSlots.length === 0)
|
|
176451
|
+
return stream;
|
|
176452
|
+
const source = injectRuntime ? injectStreamingRuntimeIntoStream(stream, nonce) : stream;
|
|
176453
|
+
const encoder = new TextEncoder;
|
|
176454
|
+
const decoder = new TextDecoder;
|
|
176455
|
+
const reader = source.getReader();
|
|
176456
|
+
const pending = preparedSlots.map((slot) => resolveSlot(slot, combinedOnError, effectivePolicy, combinedOnSlotMetric));
|
|
176457
|
+
return new ReadableStream({
|
|
176458
|
+
async start(controller) {
|
|
176459
|
+
let baseDone = false;
|
|
176460
|
+
let baseRead = reader.read();
|
|
176461
|
+
let tail = "";
|
|
176462
|
+
let footer = "";
|
|
176463
|
+
try {
|
|
176464
|
+
while (!baseDone || pending.length > 0) {
|
|
176465
|
+
const racers = [];
|
|
176466
|
+
if (!baseDone) {
|
|
176467
|
+
racers.push(baseRead.then(({ done, value }) => ({
|
|
176468
|
+
done,
|
|
176469
|
+
kind: "base",
|
|
176470
|
+
value
|
|
176471
|
+
})));
|
|
176472
|
+
}
|
|
176473
|
+
if (pending.length > 0) {
|
|
176474
|
+
racers.push(nextResolvedSlot(pending).then((resolved) => ({
|
|
176475
|
+
kind: "slot",
|
|
176476
|
+
...resolved
|
|
176477
|
+
})));
|
|
176478
|
+
}
|
|
176479
|
+
if (racers.length === 0)
|
|
176480
|
+
break;
|
|
176481
|
+
const winner = await Promise.race(racers);
|
|
176482
|
+
if (winner.kind === "base") {
|
|
176483
|
+
if (winner.done) {
|
|
176484
|
+
baseDone = true;
|
|
176485
|
+
tail += decoder.decode();
|
|
176486
|
+
const footerStart = tail.search(CLOSING_PAGE_TAG_REGEX);
|
|
176487
|
+
if (footerStart >= 0) {
|
|
176488
|
+
const content = tail.slice(0, footerStart);
|
|
176489
|
+
footer = tail.slice(footerStart);
|
|
176490
|
+
if (content.length > 0) {
|
|
176491
|
+
controller.enqueue(encoder.encode(content));
|
|
176492
|
+
}
|
|
176493
|
+
} else if (tail.length > 0) {
|
|
176494
|
+
controller.enqueue(encoder.encode(tail));
|
|
176495
|
+
}
|
|
176496
|
+
tail = "";
|
|
176497
|
+
} else if (winner.value) {
|
|
176498
|
+
tail += streamChunkToString2(winner.value, decoder);
|
|
176499
|
+
if (tail.length > STREAM_TAIL_LOOKBEHIND) {
|
|
176500
|
+
const content = tail.slice(0, tail.length - STREAM_TAIL_LOOKBEHIND);
|
|
176501
|
+
controller.enqueue(encoder.encode(content));
|
|
176502
|
+
tail = tail.slice(-STREAM_TAIL_LOOKBEHIND);
|
|
176503
|
+
}
|
|
176504
|
+
baseRead = reader.read();
|
|
176505
|
+
}
|
|
176506
|
+
continue;
|
|
176507
|
+
}
|
|
176508
|
+
const index = pending.indexOf(winner.original);
|
|
176509
|
+
if (index >= 0)
|
|
176510
|
+
pending.splice(index, 1);
|
|
176511
|
+
if (winner.result.html === null)
|
|
176512
|
+
continue;
|
|
176513
|
+
emitSlotMetric({
|
|
176514
|
+
type: "patched",
|
|
176515
|
+
slotId: winner.result.id,
|
|
176516
|
+
durationMs: winner.result.durationMs,
|
|
176517
|
+
bytes: winner.result.bytes
|
|
176518
|
+
}, combinedOnSlotMetric);
|
|
176519
|
+
controller.enqueue(encoder.encode(renderStreamingSlotPatchTag(winner.result.id, winner.result.html, nonce)));
|
|
176520
|
+
}
|
|
176521
|
+
if (footer.length > 0)
|
|
176522
|
+
controller.enqueue(encoder.encode(footer));
|
|
176523
|
+
controller.close();
|
|
176524
|
+
} catch (error) {
|
|
176525
|
+
controller.error(error);
|
|
176526
|
+
}
|
|
176527
|
+
}
|
|
176528
|
+
});
|
|
176529
|
+
};
|
|
176530
|
+
var init_streamingSlots = __esm(() => {
|
|
176531
|
+
init_escapeScriptContent();
|
|
176532
|
+
CLOSING_HEAD_TAG_LENGTH = CLOSING_HEAD_TAG2.length;
|
|
176533
|
+
CLOSING_PAGE_TAG_REGEX = /<\/body>\s*<\/html>\s*$/i;
|
|
176534
|
+
currentStreamingSlotPolicy = {
|
|
176535
|
+
timeoutMs: STREAMING_SLOT_TIMEOUT_MS,
|
|
176536
|
+
fallbackHtml: "",
|
|
176537
|
+
errorHtml: undefined,
|
|
176538
|
+
maxSlotsPerResponse: STREAMING_SLOT_MAX_PER_RESPONSE,
|
|
176539
|
+
maxSlotHtmlSizeBytes: STREAMING_SLOT_MAX_HTML_BYTES
|
|
176540
|
+
};
|
|
176541
|
+
});
|
|
176542
|
+
|
|
176543
|
+
// src/core/streamingSlotRegistrar.ts
|
|
176544
|
+
var registrar = null, setStreamingSlotRegistrar = (nextRegistrar) => {
|
|
176545
|
+
registrar = nextRegistrar;
|
|
176546
|
+
}, registerStreamingSlot = (slot) => {
|
|
176547
|
+
registrar?.(slot);
|
|
176548
|
+
};
|
|
176549
|
+
|
|
176550
|
+
// src/core/streamingSlotRegistry.ts
|
|
176551
|
+
var asyncLocalStorage, isServerRuntime = () => typeof process !== "undefined" && typeof process.versions?.node === "string", ensureAsyncLocalStorage = async () => {
|
|
176552
|
+
if (typeof asyncLocalStorage !== "undefined")
|
|
176553
|
+
return asyncLocalStorage;
|
|
176554
|
+
if (!isServerRuntime()) {
|
|
176555
|
+
asyncLocalStorage = null;
|
|
176556
|
+
return asyncLocalStorage;
|
|
176557
|
+
}
|
|
176558
|
+
const mod = await import("async_hooks");
|
|
176559
|
+
asyncLocalStorage = new mod.AsyncLocalStorage;
|
|
176560
|
+
return asyncLocalStorage;
|
|
176561
|
+
}, registerStreamingSlot2 = (slot) => {
|
|
176562
|
+
if (!asyncLocalStorage)
|
|
176563
|
+
return;
|
|
176564
|
+
const store = asyncLocalStorage.getStore();
|
|
176565
|
+
if (!store)
|
|
176566
|
+
return;
|
|
176567
|
+
store.set(slot.id, slot);
|
|
176568
|
+
}, runWithStreamingSlotRegistry = async (task) => {
|
|
176569
|
+
const storage = await ensureAsyncLocalStorage();
|
|
176570
|
+
if (!storage) {
|
|
176571
|
+
return {
|
|
176572
|
+
result: await task(),
|
|
176573
|
+
slots: []
|
|
176574
|
+
};
|
|
176575
|
+
}
|
|
176576
|
+
return storage.run(new Map, async () => {
|
|
176577
|
+
const result = await task();
|
|
176578
|
+
const store = storage.getStore();
|
|
176579
|
+
return {
|
|
176580
|
+
result,
|
|
176581
|
+
slots: store ? [...store.values()] : []
|
|
176582
|
+
};
|
|
176583
|
+
});
|
|
176584
|
+
};
|
|
176585
|
+
var init_streamingSlotRegistry = __esm(() => {
|
|
176586
|
+
setStreamingSlotRegistrar(registerStreamingSlot2);
|
|
176587
|
+
});
|
|
176588
|
+
|
|
176589
|
+
// src/core/responseEnhancers.ts
|
|
176590
|
+
var toResponse = async (responseLike) => await responseLike, cloneHeaders = (response) => {
|
|
176591
|
+
const headers = new Headers(response.headers);
|
|
176592
|
+
return headers;
|
|
176593
|
+
}, enhanceHtmlResponseWithStreamingSlots = (response, { nonce, onError, streamingSlots = [], policy } = {}) => {
|
|
176594
|
+
if (!response.body || streamingSlots.length === 0) {
|
|
176595
|
+
return response;
|
|
176596
|
+
}
|
|
176597
|
+
const body = appendStreamingSlotPatchesToStream(response.body, streamingSlots, {
|
|
176598
|
+
nonce,
|
|
176599
|
+
onError,
|
|
176600
|
+
policy
|
|
176601
|
+
});
|
|
176602
|
+
return new Response(body, {
|
|
176603
|
+
headers: cloneHeaders(response),
|
|
176604
|
+
status: response.status,
|
|
176605
|
+
statusText: response.statusText
|
|
176606
|
+
});
|
|
176607
|
+
}, withStreamingSlots = async (responseLike, options = {}) => enhanceHtmlResponseWithStreamingSlots(await toResponse(responseLike), options), mergeStreamingSlots = (registered, explicit) => {
|
|
176608
|
+
const merged = new Map;
|
|
176609
|
+
for (const slot of registered)
|
|
176610
|
+
merged.set(slot.id, slot);
|
|
176611
|
+
for (const slot of explicit)
|
|
176612
|
+
merged.set(slot.id, slot);
|
|
176613
|
+
return [...merged.values()];
|
|
176614
|
+
}, withRegisteredStreamingSlots = async (renderResponse, options = {}) => {
|
|
176615
|
+
const { result, slots } = await runWithStreamingSlotRegistry(renderResponse);
|
|
176616
|
+
const explicit = options.streamingSlots ?? [];
|
|
176617
|
+
return withStreamingSlots(result, {
|
|
176618
|
+
...options,
|
|
176619
|
+
streamingSlots: mergeStreamingSlots(slots, explicit)
|
|
176620
|
+
});
|
|
176621
|
+
};
|
|
176622
|
+
var init_responseEnhancers = __esm(() => {
|
|
176623
|
+
init_streamingSlots();
|
|
176624
|
+
init_streamingSlotRegistry();
|
|
176625
|
+
});
|
|
176626
|
+
|
|
176627
|
+
// src/react/streamingSlotCollection.tsx
|
|
176628
|
+
import { createContext, useContext } from "react";
|
|
176629
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
176630
|
+
var StreamingSlotCollectorContext, StreamingSlotCollectorProvider = ({
|
|
176631
|
+
children,
|
|
176632
|
+
collector
|
|
176633
|
+
}) => /* @__PURE__ */ jsxDEV(StreamingSlotCollectorContext.Provider, {
|
|
176634
|
+
value: collector,
|
|
176635
|
+
children
|
|
176636
|
+
}, undefined, false, undefined, this), useStreamingSlotCollector = () => useContext(StreamingSlotCollectorContext);
|
|
176637
|
+
var init_streamingSlotCollection = __esm(() => {
|
|
176638
|
+
StreamingSlotCollectorContext = createContext(null);
|
|
176639
|
+
});
|
|
176640
|
+
|
|
176079
176641
|
// src/react/pageHandler.ts
|
|
176080
176642
|
var ssrDirty2 = false, buildDirtyResponse = (index, maybeProps) => {
|
|
176081
176643
|
const propsScript = maybeProps ? `window.__INITIAL_PROPS__=${JSON.stringify(maybeProps)};` : "";
|
|
@@ -176094,7 +176656,9 @@ var ssrDirty2 = false, buildDirtyResponse = (index, maybeProps) => {
|
|
|
176094
176656
|
try {
|
|
176095
176657
|
const { createElement: createElement2 } = await import("react");
|
|
176096
176658
|
const { renderToReadableStream } = await import("react-dom/server");
|
|
176097
|
-
const
|
|
176659
|
+
const slotCollector = new Map;
|
|
176660
|
+
const pageElement = maybeProps !== undefined ? createElement2(PageComponent, maybeProps) : createElement2(PageComponent);
|
|
176661
|
+
const element = createElement2(StreamingSlotCollectorProvider, { collector: slotCollector }, pageElement);
|
|
176098
176662
|
const propsScript = maybeProps ? `window.__INITIAL_PROPS__=${JSON.stringify(maybeProps)};` : "";
|
|
176099
176663
|
const refreshSetup = "window.__REFRESH_BUFFER__=[];window.$RefreshReg$=function(t,i){window.__REFRESH_BUFFER__.push([t,i])};window.$RefreshSig$=function(){return function(t){return t}};";
|
|
176100
176664
|
const stream = await renderToReadableStream(element, {
|
|
@@ -176108,8 +176672,10 @@ var ssrDirty2 = false, buildDirtyResponse = (index, maybeProps) => {
|
|
|
176108
176672
|
await stream.allReady;
|
|
176109
176673
|
}
|
|
176110
176674
|
const htmlStream = injectIslandPageContextStream(stream);
|
|
176111
|
-
return new Response(htmlStream, {
|
|
176675
|
+
return withStreamingSlots(new Response(htmlStream, {
|
|
176112
176676
|
headers: { "Content-Type": "text/html" }
|
|
176677
|
+
}), {
|
|
176678
|
+
streamingSlots: [...slotCollector.values()]
|
|
176113
176679
|
});
|
|
176114
176680
|
} catch (error) {
|
|
176115
176681
|
console.error("[SSR] React render error:", error);
|
|
@@ -176126,23 +176692,9 @@ var ssrDirty2 = false, buildDirtyResponse = (index, maybeProps) => {
|
|
|
176126
176692
|
ssrDirty2 = true;
|
|
176127
176693
|
};
|
|
176128
176694
|
var init_pageHandler2 = __esm(() => {
|
|
176695
|
+
init_responseEnhancers();
|
|
176129
176696
|
init_resolveConvention();
|
|
176130
|
-
|
|
176131
|
-
|
|
176132
|
-
// src/utils/escapeScriptContent.ts
|
|
176133
|
-
var ESCAPE_LOOKUP, ESCAPE_REGEX, escapeScriptContent = (content) => content.replace(ESCAPE_REGEX, (char) => {
|
|
176134
|
-
const escaped = ESCAPE_LOOKUP[char];
|
|
176135
|
-
return escaped !== undefined ? escaped : char;
|
|
176136
|
-
});
|
|
176137
|
-
var init_escapeScriptContent = __esm(() => {
|
|
176138
|
-
ESCAPE_LOOKUP = {
|
|
176139
|
-
"\u2028": "\\u2028",
|
|
176140
|
-
"\u2029": "\\u2029",
|
|
176141
|
-
"&": "\\u0026",
|
|
176142
|
-
"<": "\\u003C",
|
|
176143
|
-
">": "\\u003E"
|
|
176144
|
-
};
|
|
176145
|
-
ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
|
176697
|
+
init_streamingSlotCollection();
|
|
176146
176698
|
});
|
|
176147
176699
|
|
|
176148
176700
|
// src/svelte/renderToReadableStream.ts
|
|
@@ -179151,5 +179703,5 @@ export {
|
|
|
179151
179703
|
build
|
|
179152
179704
|
};
|
|
179153
179705
|
|
|
179154
|
-
//# debugId=
|
|
179706
|
+
//# debugId=DF9EA1EB950C542E64756E2164756E21
|
|
179155
179707
|
//# sourceMappingURL=build.js.map
|