@solidjs/web 2.0.0-rc.20 → 2.0.0-rc.21
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/server.dev.js +163 -63
- package/dist/server.js +163 -63
- package/dist/server.observe.js +163 -63
- package/dist/web.dev.js +17 -24
- package/dist/web.js +17 -24
- package/dist/web.observe.js +17 -24
- package/frames/dist/server.dev.js +2 -6
- package/frames/dist/server.js +2 -6
- package/frames/dist/server.observe.js +2 -6
- package/package.json +2 -2
- package/serialization/dist/serialization.js +51 -11
- package/serialization/types/index.d.ts +35 -0
- package/serialization/types/serializer.d.ts +35 -0
- package/server-functions/dist/rich-args.js +27 -9
- package/server-functions/dist/server.dev.js +122 -36
- package/server-functions/dist/server.js +122 -36
- package/server-functions/dist/server.observe.js +122 -36
- package/types/frames/serializer.d.ts +35 -0
- package/types/serializer.d.ts +35 -0
- package/types/server-functions/client.d.ts +0 -1
- package/types/server-functions/server.d.ts +0 -1
- package/types/server-functions/uploads.d.ts +3 -0
- package/types/server-mock.d.ts +35 -8
- package/types/server.d.ts +45 -15
package/dist/server.dev.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createRenderEffect, getOwner, createMemo, OBSERVE, DEV, createRoot, $PR
|
|
|
2
2
|
export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, dynamicComponent, getOwner, merge as mergeProps, untrack } from 'solid-js';
|
|
3
3
|
import { sharedConfig, ssrSanitizeError, beginEdgesRender, reportServerError, viewOf, sourceOwners, ssrHandleError, inServerComponentScope, creationStamp, dynamicCore, getProjectionTrace, shareAsyncIterable } from 'solid-js/internal';
|
|
4
4
|
export { ssrScope as scope } from 'solid-js/internal';
|
|
5
|
-
import { createStream, Feature,
|
|
5
|
+
import { createStream, Feature, crossSerializeStream, isStream, getCrossReferenceHeader } from 'seroval';
|
|
6
6
|
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
7
7
|
|
|
8
8
|
const DOMWithState = {
|
|
@@ -563,7 +563,6 @@ function createKeyedSerializer(serialize, onError, onDone) {
|
|
|
563
563
|
pendingWrites++;
|
|
564
564
|
let settled = false;
|
|
565
565
|
let failed = false;
|
|
566
|
-
let started = false;
|
|
567
566
|
let cancel = null;
|
|
568
567
|
const settle = () => {
|
|
569
568
|
if (settled) return;
|
|
@@ -584,10 +583,7 @@ function createKeyedSerializer(serialize, onError, onDone) {
|
|
|
584
583
|
}
|
|
585
584
|
}),
|
|
586
585
|
onDone: settle
|
|
587
|
-
},
|
|
588
|
-
if (initial) started = true;
|
|
589
|
-
return !closed;
|
|
590
|
-
});
|
|
586
|
+
}, () => !closed);
|
|
591
587
|
} catch (err) {
|
|
592
588
|
settle();
|
|
593
589
|
throw err;
|
|
@@ -634,22 +630,66 @@ function createHydrationSerializer({
|
|
|
634
630
|
onDone,
|
|
635
631
|
scopeId,
|
|
636
632
|
onError,
|
|
637
|
-
plugins
|
|
633
|
+
plugins,
|
|
634
|
+
late
|
|
638
635
|
}) {
|
|
639
636
|
const resolvedPlugins = resolveSerializerPlugins(plugins);
|
|
640
637
|
const disabledFeatures = defaultDisabledFeatures() | serializeOnlyDisabledFeatures();
|
|
641
638
|
const refs = new Map();
|
|
642
|
-
|
|
639
|
+
const serialize = (key, value, callbacks, live) => crossSerializeStream(value, {
|
|
643
640
|
scopeId,
|
|
644
641
|
refs,
|
|
645
642
|
plugins: resolvedPlugins,
|
|
646
643
|
disabledFeatures,
|
|
647
644
|
onSerialize(data, initial) {
|
|
648
|
-
if (!live(
|
|
645
|
+
if (!live()) return;
|
|
649
646
|
onData(initial ? HYDRATION_GLOBAL + '["' + serializeKey(key) + '"]=' + data : data);
|
|
650
647
|
},
|
|
651
648
|
...callbacks
|
|
652
|
-
})
|
|
649
|
+
});
|
|
650
|
+
return createKeyedSerializer(late ? late(serialize, refs, onData, scopeId) : serialize, onError, onDone);
|
|
651
|
+
}
|
|
652
|
+
function rejectUnserializedKey(serialize, refs, onData, scopeId) {
|
|
653
|
+
let taken = 0;
|
|
654
|
+
let fresh = [];
|
|
655
|
+
const set = refs.set;
|
|
656
|
+
refs.set = (value, id) => {
|
|
657
|
+
taken++;
|
|
658
|
+
fresh.push(value);
|
|
659
|
+
return set.call(refs, value, id);
|
|
660
|
+
};
|
|
661
|
+
Object.defineProperty(refs, "size", {
|
|
662
|
+
get: () => taken
|
|
663
|
+
});
|
|
664
|
+
return (key, value, callbacks, live) => {
|
|
665
|
+
const sent = [];
|
|
666
|
+
const failed = () => {
|
|
667
|
+
for (const ref of fresh) refs.delete(ref);
|
|
668
|
+
fresh = [];
|
|
669
|
+
const ids = new Set();
|
|
670
|
+
for (const ref of sent) {
|
|
671
|
+
const id = refs.get(ref);
|
|
672
|
+
if (ref instanceof Promise) ids.add(id + 1);else if (isStream(ref) || Object.getPrototypeOf(ref) === Object.prototype && !Object.keys(ref).length) ids.add(id);
|
|
673
|
+
}
|
|
674
|
+
if (!ids.size) return;
|
|
675
|
+
const body = "for(const i of[" + [...ids] + "]){const v=$R[i];v&&(v.f?v.f(e):v.throw&&v.throw(e))}";
|
|
676
|
+
const message = JSON.stringify("Serialization failed: the hydration value for key " + JSON.stringify(key) + " could not be serialized on the server").replace(/[<\u2028\u2029]/g, c => KEY_ESCAPES[c]);
|
|
677
|
+
onData("($R=>{const e=new Error(" + message + ");" + body + "})(" + (scopeId == null ? "$R" : '$R["' + serializeKey(scopeId) + '"]') + ")");
|
|
678
|
+
};
|
|
679
|
+
return serialize(key, value, {
|
|
680
|
+
...callbacks,
|
|
681
|
+
onError: callbacks.onError && (err => {
|
|
682
|
+
if (live()) failed();
|
|
683
|
+
callbacks.onError(err);
|
|
684
|
+
})
|
|
685
|
+
},
|
|
686
|
+
() => {
|
|
687
|
+
if (!live()) return false;
|
|
688
|
+
sent.push(...fresh);
|
|
689
|
+
fresh = [];
|
|
690
|
+
return true;
|
|
691
|
+
});
|
|
692
|
+
};
|
|
653
693
|
}
|
|
654
694
|
function getLocalHeaderScript(id) {
|
|
655
695
|
return getCrossReferenceHeader(id) + ";";
|
|
@@ -1055,7 +1095,7 @@ function resolveAssets(moduleUrl, manifest) {
|
|
|
1055
1095
|
if (!manifest) return null;
|
|
1056
1096
|
const base = manifest._base;
|
|
1057
1097
|
const entry = manifest[moduleUrl];
|
|
1058
|
-
if (!entry) return null;
|
|
1098
|
+
if (!entry || typeof entry !== "object") return null;
|
|
1059
1099
|
const css = [];
|
|
1060
1100
|
const js = [];
|
|
1061
1101
|
let preloads;
|
|
@@ -1064,7 +1104,7 @@ function resolveAssets(moduleUrl, manifest) {
|
|
|
1064
1104
|
if (visited.has(key)) return;
|
|
1065
1105
|
visited.add(key);
|
|
1066
1106
|
const e = manifest[key];
|
|
1067
|
-
if (!e) return;
|
|
1107
|
+
if (!e || typeof e !== "object") return;
|
|
1068
1108
|
js.push(joinAssetPath(base, e.file));
|
|
1069
1109
|
if (e.css) for (let i = 0; i < e.css.length; i++) css.push(joinAssetPath(base, e.css[i]));
|
|
1070
1110
|
if (e.preloads) {
|
|
@@ -1103,18 +1143,19 @@ function registerEntryAssets(manifest) {
|
|
|
1103
1143
|
const ctx = sharedConfig.context;
|
|
1104
1144
|
if (!ctx?.registerAsset) return;
|
|
1105
1145
|
for (const key in manifest) {
|
|
1106
|
-
|
|
1146
|
+
const entry = manifest[key];
|
|
1147
|
+
if (entry && entry.isEntry) {
|
|
1107
1148
|
const assets = resolveAssets(key, manifest);
|
|
1108
1149
|
if (assets) {
|
|
1109
1150
|
if (assets.preloads) for (let i = 0; i < assets.preloads.length; i++) ctx.registerAsset("preload", assets.preloads[i]);
|
|
1110
1151
|
for (let i = 0; i < assets.css.length; i++) ctx.registerAsset("style", assets.css[i]);
|
|
1111
|
-
for (let i = 1; i < assets.js.length; i++) ctx.registerAsset("module", assets.js[i]);
|
|
1152
|
+
for (let i = 1; i < assets.js.length; i++) ctx.registerAsset("module", assets.js[i], true);
|
|
1112
1153
|
}
|
|
1113
1154
|
return;
|
|
1114
1155
|
}
|
|
1115
1156
|
}
|
|
1116
1157
|
}
|
|
1117
|
-
function createAssetTracking() {
|
|
1158
|
+
function createAssetTracking(lowPriorityPreloads) {
|
|
1118
1159
|
const boundaryModules = new Map();
|
|
1119
1160
|
const boundaryStyles = new Map();
|
|
1120
1161
|
const emittedAssets = new Set();
|
|
@@ -1126,6 +1167,7 @@ function createAssetTracking() {
|
|
|
1126
1167
|
emittedAssets,
|
|
1127
1168
|
inlineStyles,
|
|
1128
1169
|
preloadLinks: null,
|
|
1170
|
+
lowModules: lowPriorityPreloads !== false ? new Set() : null,
|
|
1129
1171
|
registerInlineStyle(desc) {
|
|
1130
1172
|
let entry = inlineStyles.get(desc.id);
|
|
1131
1173
|
if (!entry) {
|
|
@@ -1503,7 +1545,7 @@ function emitHeadResource(registry, context, tracking, emitResource, nonce, desc
|
|
|
1503
1545
|
if (plain && props.href != null) {
|
|
1504
1546
|
const isCss = isCssUrl(props.href);
|
|
1505
1547
|
if (rel === "stylesheet" ? isCss : !isCss) {
|
|
1506
|
-
context.registerAsset(rel === "stylesheet" ? "style" : "module", props.href);
|
|
1548
|
+
context.registerAsset(rel === "stylesheet" ? "style" : "module", props.href, true);
|
|
1507
1549
|
return;
|
|
1508
1550
|
}
|
|
1509
1551
|
}
|
|
@@ -1752,6 +1794,10 @@ function nonceDestination(tag, props) {
|
|
|
1752
1794
|
return "script";
|
|
1753
1795
|
}
|
|
1754
1796
|
}
|
|
1797
|
+
function modulePreloadLink(url, scriptAttr, lowModules) {
|
|
1798
|
+
const priority = lowModules && !lowModules.has(url) ? ' fetchpriority="low"' : "";
|
|
1799
|
+
return `<link rel="modulepreload" href="${url}"${priority}${scriptAttr}>`;
|
|
1800
|
+
}
|
|
1755
1801
|
function nonceAttr(nonce, destination) {
|
|
1756
1802
|
if (!nonce || !destination) return "";
|
|
1757
1803
|
return destination === "script" ? nonce.scriptAttr : nonce.styleAttr;
|
|
@@ -1867,7 +1913,7 @@ function renderToString(code, options = {}) {
|
|
|
1867
1913
|
},
|
|
1868
1914
|
onError: serializerErrorHook(options.onError)
|
|
1869
1915
|
});
|
|
1870
|
-
const tracking = createAssetTracking();
|
|
1916
|
+
const tracking = createAssetTracking(options.lowPriorityPreloads);
|
|
1871
1917
|
const headRegistry = createHeadRegistry();
|
|
1872
1918
|
let closed = false;
|
|
1873
1919
|
sharedConfig.context = {
|
|
@@ -1887,7 +1933,7 @@ function renderToString(code, options = {}) {
|
|
|
1887
1933
|
}
|
|
1888
1934
|
serializer.write(id, p);
|
|
1889
1935
|
},
|
|
1890
|
-
registerAsset(type, value) {
|
|
1936
|
+
registerAsset(type, value, defaultPriority) {
|
|
1891
1937
|
if (type === "preload") {
|
|
1892
1938
|
registerPreloadLink(tracking, headRegistry, value, nonce);
|
|
1893
1939
|
return;
|
|
@@ -1904,6 +1950,7 @@ function renderToString(code, options = {}) {
|
|
|
1904
1950
|
}
|
|
1905
1951
|
styles.add(value);
|
|
1906
1952
|
}
|
|
1953
|
+
if (defaultPriority && tracking.lowModules) tracking.lowModules.add(value);
|
|
1907
1954
|
tracking.emittedAssets.add(value);
|
|
1908
1955
|
}
|
|
1909
1956
|
};
|
|
@@ -1930,7 +1977,7 @@ function renderToString(code, options = {}) {
|
|
|
1930
1977
|
closed = true;
|
|
1931
1978
|
serializer.close();
|
|
1932
1979
|
const head = renderShellHead(headRegistry, nonce, null, noScripts, traceMetaMarkup(context.trace));
|
|
1933
|
-
const document = withShellEnd(assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead), context, renderId, nonce, noScripts);
|
|
1980
|
+
const document = withShellEnd(assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead, tracking.lowModules), context, renderId, nonce, noScripts);
|
|
1934
1981
|
if (render) render.shell();
|
|
1935
1982
|
if (requestEvent && requestEvent.response) {
|
|
1936
1983
|
commitResponseStub(requestEvent.response, {
|
|
@@ -1979,9 +2026,7 @@ function renderToStream(code, options = {}) {
|
|
|
1979
2026
|
let rootOwner;
|
|
1980
2027
|
let serializer;
|
|
1981
2028
|
let disconnected = false;
|
|
1982
|
-
let failed = false;
|
|
1983
2029
|
let onFailed;
|
|
1984
|
-
let onDisconnectedBeforeShell;
|
|
1985
2030
|
const defuse = p => {
|
|
1986
2031
|
if (p && typeof p.then === "function") p.then(undefined, () => {});
|
|
1987
2032
|
};
|
|
@@ -1993,11 +2038,11 @@ function renderToStream(code, options = {}) {
|
|
|
1993
2038
|
close() {}
|
|
1994
2039
|
};
|
|
1995
2040
|
const onFailure = complete => {
|
|
1996
|
-
if (
|
|
2041
|
+
if (dead) return complete(undefined, disconnected || undefined);
|
|
1997
2042
|
const prev = onFailed;
|
|
1998
|
-
onFailed = prev ? sink => {
|
|
1999
|
-
prev(sink);
|
|
2000
|
-
complete(sink);
|
|
2043
|
+
onFailed = prev ? (sink, gone) => {
|
|
2044
|
+
prev(sink, gone);
|
|
2045
|
+
complete(sink, gone);
|
|
2001
2046
|
} : complete;
|
|
2002
2047
|
};
|
|
2003
2048
|
const abandon = (disconnect, quiet) => {
|
|
@@ -2015,7 +2060,7 @@ function renderToStream(code, options = {}) {
|
|
|
2015
2060
|
}, null);
|
|
2016
2061
|
dead = true;
|
|
2017
2062
|
completed = true;
|
|
2018
|
-
if (disconnect) disconnected =
|
|
2063
|
+
if (disconnect) disconnected = disconnect;
|
|
2019
2064
|
if (render) settleRender(render, rootOwner, disconnect ? "abandoned" : "error");
|
|
2020
2065
|
const sink = writable;
|
|
2021
2066
|
buffer = {
|
|
@@ -2044,10 +2089,7 @@ function renderToStream(code, options = {}) {
|
|
|
2044
2089
|
for (const p of stubBatch.values()) defuse(p);
|
|
2045
2090
|
stubBatch = null;
|
|
2046
2091
|
}
|
|
2047
|
-
|
|
2048
|
-
failed = true;
|
|
2049
|
-
onFailed && onFailed(sink);
|
|
2050
|
-
} else if (!sink && onDisconnectedBeforeShell) onDisconnectedBeforeShell();
|
|
2092
|
+
onFailed && onFailed(sink, disconnect);
|
|
2051
2093
|
};
|
|
2052
2094
|
const failRender = err => {
|
|
2053
2095
|
reportFailure(err, "failed");
|
|
@@ -2116,21 +2158,31 @@ function renderToStream(code, options = {}) {
|
|
|
2116
2158
|
let stableOrder = false;
|
|
2117
2159
|
let parkedWrites = null;
|
|
2118
2160
|
const byKey = (a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
|
|
2161
|
+
let writing = 0;
|
|
2162
|
+
let stranded = false;
|
|
2163
|
+
const handOver = (id, value) => {
|
|
2164
|
+
writing++;
|
|
2165
|
+
try {
|
|
2166
|
+
serializer.write(id, value);
|
|
2167
|
+
} finally {
|
|
2168
|
+
writing--;
|
|
2169
|
+
}
|
|
2170
|
+
};
|
|
2119
2171
|
const write = (id, value) => {
|
|
2120
|
-
if (stableOrder && !dead) (parkedWrites ||= []).push([id, value]);else
|
|
2172
|
+
if (stableOrder && !dead) (parkedWrites ||= []).push([id, value]);else handOver(id, value);
|
|
2121
2173
|
};
|
|
2122
2174
|
const flushParkedWrites = () => {
|
|
2123
2175
|
if (!parkedWrites) return;
|
|
2124
2176
|
const writes = parkedWrites.sort(byKey);
|
|
2125
2177
|
parkedWrites = null;
|
|
2126
|
-
for (let i = 0; i < writes.length; i++)
|
|
2178
|
+
for (let i = 0; i < writes.length; i++) handOver(writes[i][0], writes[i][1]);
|
|
2127
2179
|
};
|
|
2128
2180
|
const flushStubBatch = () => {
|
|
2129
2181
|
if (!stubBatch) return;
|
|
2130
2182
|
const entries = [...stubBatch];
|
|
2131
2183
|
stubBatch = null;
|
|
2132
2184
|
if (stableOrder) entries.sort(byKey);
|
|
2133
|
-
for (let i = 0; i < entries.length; i++)
|
|
2185
|
+
for (let i = 0; i < entries.length; i++) handOver(entries[i][0], entries[i][1]);
|
|
2134
2186
|
};
|
|
2135
2187
|
let headerEmitted = false;
|
|
2136
2188
|
const pushTask = task => {
|
|
@@ -2148,6 +2200,7 @@ function renderToStream(code, options = {}) {
|
|
|
2148
2200
|
const onDone = () => {
|
|
2149
2201
|
if (dead) return;
|
|
2150
2202
|
writeTasks();
|
|
2203
|
+
if (stranded) return abandon();
|
|
2151
2204
|
lastBlockingSize = blockingPromises.size;
|
|
2152
2205
|
doShell();
|
|
2153
2206
|
onCompleteAll && onCompleteAll({
|
|
@@ -2191,7 +2244,7 @@ function renderToStream(code, options = {}) {
|
|
|
2191
2244
|
},
|
|
2192
2245
|
asset(type, value) {
|
|
2193
2246
|
if (type === "module") {
|
|
2194
|
-
buffer.write(
|
|
2247
|
+
buffer.write(modulePreloadLink(value, nonceAttr(nonce, "script"), tracking.lowModules));
|
|
2195
2248
|
} else if (type === "preload") {
|
|
2196
2249
|
buffer.write(`<link${value.attrHtml}>`);
|
|
2197
2250
|
} else if (type === "inline-style") {
|
|
@@ -2201,7 +2254,7 @@ function renderToStream(code, options = {}) {
|
|
|
2201
2254
|
}
|
|
2202
2255
|
},
|
|
2203
2256
|
shell(shellHtml, meta) {
|
|
2204
|
-
buffer.write(withShellEnd(assembleDocument(shellHtml, meta.preloads, meta.preloadLinks, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead), context, renderId, nonce, noScripts));
|
|
2257
|
+
buffer.write(withShellEnd(assembleDocument(shellHtml, meta.preloads, meta.preloadLinks, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead, tracking.lowModules), context, renderId, nonce, noScripts));
|
|
2205
2258
|
},
|
|
2206
2259
|
...options.sink
|
|
2207
2260
|
};
|
|
@@ -2210,7 +2263,11 @@ function renderToStream(code, options = {}) {
|
|
|
2210
2263
|
plugins: options.plugins,
|
|
2211
2264
|
onData: payload => sink.data(payload),
|
|
2212
2265
|
onDone,
|
|
2213
|
-
onError: err =>
|
|
2266
|
+
onError: err => {
|
|
2267
|
+
reportFailure(err, "serialize");
|
|
2268
|
+
if (!writing && !options.serializer && !firstFlushed) stranded = true;
|
|
2269
|
+
},
|
|
2270
|
+
late: rejectUnserializedKey
|
|
2214
2271
|
});
|
|
2215
2272
|
let rootAssetsSerialized = false;
|
|
2216
2273
|
const serializeRootAssets = () => {
|
|
@@ -2378,7 +2435,7 @@ function renderToStream(code, options = {}) {
|
|
|
2378
2435
|
tmp += payload;
|
|
2379
2436
|
}
|
|
2380
2437
|
};
|
|
2381
|
-
const tracking = createAssetTracking();
|
|
2438
|
+
const tracking = createAssetTracking(options.lowPriorityPreloads);
|
|
2382
2439
|
const headRegistry = createHeadRegistry();
|
|
2383
2440
|
let headScriptFlushed = false;
|
|
2384
2441
|
const emitHeadOps = (key, ops) => {
|
|
@@ -2403,7 +2460,7 @@ function renderToStream(code, options = {}) {
|
|
|
2403
2460
|
}
|
|
2404
2461
|
}, nonce, tags);
|
|
2405
2462
|
},
|
|
2406
|
-
registerAsset(type, value) {
|
|
2463
|
+
registerAsset(type, value, defaultPriority) {
|
|
2407
2464
|
if (type === "preload") {
|
|
2408
2465
|
const entry = registerPreloadLink(tracking, headRegistry, value, nonce);
|
|
2409
2466
|
if (entry && firstFlushed) sink.asset("preload", entry);
|
|
@@ -2425,6 +2482,7 @@ function renderToStream(code, options = {}) {
|
|
|
2425
2482
|
}
|
|
2426
2483
|
styles.add(value);
|
|
2427
2484
|
}
|
|
2485
|
+
if (defaultPriority && tracking.lowModules) tracking.lowModules.add(value);
|
|
2428
2486
|
if (!tracking.emittedAssets.has(value)) {
|
|
2429
2487
|
tracking.emittedAssets.add(value);
|
|
2430
2488
|
if (firstFlushed) sink.asset(type, value);
|
|
@@ -2576,7 +2634,12 @@ function renderToStream(code, options = {}) {
|
|
|
2576
2634
|
registerEntryAssets(manifest);
|
|
2577
2635
|
context.writer = createHydrationWriter(context, () => !completed);
|
|
2578
2636
|
const signal = options.signal;
|
|
2579
|
-
|
|
2637
|
+
let cancelled = false;
|
|
2638
|
+
const onAbort = signal ? () => {
|
|
2639
|
+
if (dead) return;
|
|
2640
|
+
cancelled = true;
|
|
2641
|
+
abandon("signal", !!(signal.reason && signal.reason.quiet === true));
|
|
2642
|
+
} : undefined;
|
|
2580
2643
|
const endEdges = context.edges ? beginEdgesRender() : undefined;
|
|
2581
2644
|
let html;
|
|
2582
2645
|
try {
|
|
@@ -2738,9 +2801,12 @@ function renderToStream(code, options = {}) {
|
|
|
2738
2801
|
const pipeToImpl = w => {
|
|
2739
2802
|
let resolve;
|
|
2740
2803
|
const p = new Promise(r => resolve = r);
|
|
2741
|
-
|
|
2804
|
+
let closeOnAbort = () => w.close().catch(() => {});
|
|
2805
|
+
onFailure((sink, gone) => {
|
|
2742
2806
|
try {
|
|
2743
|
-
if (
|
|
2807
|
+
if (!gone) {
|
|
2808
|
+
if (sink) sink.end();else w.close().catch(() => {});
|
|
2809
|
+
} else if (gone === "signal") closeOnAbort();
|
|
2744
2810
|
} catch (_) {}
|
|
2745
2811
|
resolve();
|
|
2746
2812
|
});
|
|
@@ -2755,6 +2821,7 @@ function renderToStream(code, options = {}) {
|
|
|
2755
2821
|
return;
|
|
2756
2822
|
}
|
|
2757
2823
|
if (!shellCompleted) return flush();
|
|
2824
|
+
if (stranded) return abandon();
|
|
2758
2825
|
const encoder = new TextEncoder();
|
|
2759
2826
|
const writer = w.getWriter();
|
|
2760
2827
|
let pendingWrites = Promise.resolve();
|
|
@@ -2766,6 +2833,10 @@ function renderToStream(code, options = {}) {
|
|
|
2766
2833
|
}
|
|
2767
2834
|
};
|
|
2768
2835
|
writer.closed && writer.closed.catch(failed);
|
|
2836
|
+
closeOnAbort = () => {
|
|
2837
|
+
ended = true;
|
|
2838
|
+
pendingWrites.then(() => writer.close()).catch(() => {});
|
|
2839
|
+
};
|
|
2769
2840
|
buffer = writable = coalesceWrites(payload => {
|
|
2770
2841
|
pendingWrites = pendingWrites.then(() => writer.write(encoder.encode(payload))).catch(failed);
|
|
2771
2842
|
}, () => {
|
|
@@ -2797,7 +2868,7 @@ function renderToStream(code, options = {}) {
|
|
|
2797
2868
|
event: requestEvent
|
|
2798
2869
|
});
|
|
2799
2870
|
};
|
|
2800
|
-
const p = new Promise(resolve => {
|
|
2871
|
+
const p = new Promise((resolve, reject) => {
|
|
2801
2872
|
function complete() {
|
|
2802
2873
|
freezeHead();
|
|
2803
2874
|
dispose();
|
|
@@ -2810,11 +2881,12 @@ function renderToStream(code, options = {}) {
|
|
|
2810
2881
|
complete();
|
|
2811
2882
|
};
|
|
2812
2883
|
} else onCompleteAll = complete;
|
|
2813
|
-
onFailure(() => resolve(tmp));
|
|
2884
|
+
onFailure(() => cancelled ? reject(signal.reason) : resolve(tmp));
|
|
2814
2885
|
function flush() {
|
|
2815
2886
|
allSettled(blockingPromises).then(awaited => {
|
|
2816
2887
|
scheduleFlush(() => {
|
|
2817
2888
|
if (dead) return;
|
|
2889
|
+
sharedConfig.context = context;
|
|
2818
2890
|
try {
|
|
2819
2891
|
if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
|
|
2820
2892
|
} catch (err) {
|
|
@@ -2832,15 +2904,12 @@ function renderToStream(code, options = {}) {
|
|
|
2832
2904
|
pipe(w) {
|
|
2833
2905
|
claimConsumer("pipe");
|
|
2834
2906
|
const abandoned = w[SHELL_ABANDONED];
|
|
2835
|
-
onFailure(sink => {
|
|
2907
|
+
onFailure((sink, gone) => {
|
|
2836
2908
|
try {
|
|
2837
|
-
sink ? sink.end() : abandoned ? abandoned() : w.end();
|
|
2909
|
+
if (!gone) sink ? sink.end() : abandoned ? abandoned() : w.end();else if (!sink && abandoned) abandoned();else if (gone === "signal") w.end();
|
|
2838
2910
|
} catch (_) {}
|
|
2839
2911
|
});
|
|
2840
|
-
if (abandoned)
|
|
2841
|
-
w[ABANDON_RENDER] = abandon;
|
|
2842
|
-
if (disconnected) abandoned();else onDisconnectedBeforeShell = abandoned;
|
|
2843
|
-
}
|
|
2912
|
+
if (abandoned) w[ABANDON_RENDER] = abandon;
|
|
2844
2913
|
function flush() {
|
|
2845
2914
|
allSettled(blockingPromises).then(awaited => {
|
|
2846
2915
|
scheduleFlush(() => {
|
|
@@ -2852,6 +2921,7 @@ function renderToStream(code, options = {}) {
|
|
|
2852
2921
|
return;
|
|
2853
2922
|
}
|
|
2854
2923
|
if (!shellCompleted) return flush();
|
|
2924
|
+
if (stranded) return abandon();
|
|
2855
2925
|
const sink = guardSink(w);
|
|
2856
2926
|
buffer = writable = coalesceWrites(sink.write, sink.end);
|
|
2857
2927
|
buffer.write(tmp);
|
|
@@ -3930,6 +4000,22 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
|
|
|
3930
4000
|
};
|
|
3931
4001
|
if (childOwner !== null) children = info.raw ? childOwner.children : escape(childOwner.children);
|
|
3932
4002
|
if (typeof children === "function") children = children();
|
|
4003
|
+
let thunk = null;
|
|
4004
|
+
if (typeof children === "function" && (ctx === undefined || !ctx.liveHoles)) {
|
|
4005
|
+
thunk = children;
|
|
4006
|
+
ssrTextTail = false;
|
|
4007
|
+
try {
|
|
4008
|
+
children = thunk();
|
|
4009
|
+
} catch (err) {
|
|
4010
|
+
const res = {
|
|
4011
|
+
t: [""],
|
|
4012
|
+
h: [],
|
|
4013
|
+
p: []
|
|
4014
|
+
};
|
|
4015
|
+
pushSSRAsyncHole(res, err, thunk);
|
|
4016
|
+
return ssr([result + ">", info.close], res);
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
3933
4019
|
const ct = typeof children;
|
|
3934
4020
|
if (ct === "string" || ct === "number") return {
|
|
3935
4021
|
t: result + ">" + children + info.close
|
|
@@ -3940,7 +4026,18 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
|
|
|
3940
4026
|
if (ct === "object" && !children.h && typeof children.t === "string") return {
|
|
3941
4027
|
t: result + ">" + children.t + info.close
|
|
3942
4028
|
};
|
|
3943
|
-
return ssr([result + ">", info.close], resolveSSRNode(children, undefined, true));
|
|
4029
|
+
if (thunk === null) return ssr([result + ">", info.close], resolveSSRNode(children, undefined, true));
|
|
4030
|
+
const res = {
|
|
4031
|
+
t: [""],
|
|
4032
|
+
h: [],
|
|
4033
|
+
p: []
|
|
4034
|
+
};
|
|
4035
|
+
try {
|
|
4036
|
+
resolveSSRNode(children, res, false, true);
|
|
4037
|
+
} catch (err) {
|
|
4038
|
+
pushSSRAsyncHole(res, err, thunk);
|
|
4039
|
+
}
|
|
4040
|
+
return ssr([result + ">", info.close], res);
|
|
3944
4041
|
}
|
|
3945
4042
|
function collectSpreadSources(props, viewKeys, owners) {
|
|
3946
4043
|
for (let i = 0; i < props.length; i++) {
|
|
@@ -4236,7 +4333,7 @@ function withShellEnd(html, context, renderId, nonce, noScripts) {
|
|
|
4236
4333
|
const at = html.indexOf("</body>", html.length - 512);
|
|
4237
4334
|
return at < 0 ? html + marker : html.slice(0, at) + marker + html.slice(at);
|
|
4238
4335
|
}
|
|
4239
|
-
function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead) {
|
|
4336
|
+
function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead, lowModules) {
|
|
4240
4337
|
const scriptTag = scripts ? `<script${nonceAttr(nonce, "script")}>${scripts}</script>` : "";
|
|
4241
4338
|
const title = headTags ? headTags.title : null;
|
|
4242
4339
|
let headTagsHtml = headTags ? headTags.html : "";
|
|
@@ -4260,7 +4357,7 @@ function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scrip
|
|
|
4260
4357
|
if (title != null) {
|
|
4261
4358
|
titleHtml = headTags.noScripts ? `<title data-dh="title">${escape(title)}</title>` : `<script${nonceAttr(nonce, "script")}>(function(x,t){(t=document.querySelector("title"))?(t.hasAttribute("data-dh")||t.setAttribute("data-dhf",t.textContent),t.textContent=x):(document.title=x,t=document.querySelector("title"));t&&t.setAttribute("data-dh","title")})(${JSON.stringify(title).replace(/</g, "\\u003C")})</script>`;
|
|
4262
4359
|
}
|
|
4263
|
-
onHead(headPrelude + headTagsHtml + titleHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce));
|
|
4360
|
+
onHead(headPrelude + headTagsHtml + titleHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce, lowModules));
|
|
4264
4361
|
}
|
|
4265
4362
|
if (!scriptTag) return html;
|
|
4266
4363
|
const xs = html.indexOf("<!--xs-->");
|
|
@@ -4280,19 +4377,19 @@ function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scrip
|
|
|
4280
4377
|
headTagsHtml = `<title data-dh="title">${winner}</title>` + headTagsHtml;
|
|
4281
4378
|
}
|
|
4282
4379
|
}
|
|
4283
|
-
const head = headTagsHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce);
|
|
4380
|
+
const head = headTagsHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce, lowModules);
|
|
4284
4381
|
if (!scriptTag) return html.slice(0, headIdx) + head + html.slice(headIdx);
|
|
4285
4382
|
const xsIdx = html.indexOf("<!--xs-->");
|
|
4286
4383
|
if (xsIdx === -1) return html.slice(0, headIdx) + head + html.slice(headIdx) + scriptTag;
|
|
4287
4384
|
return xsIdx < headIdx ? html.slice(0, xsIdx) + scriptTag + html.slice(xsIdx, headIdx) + head + html.slice(headIdx) : html.slice(0, headIdx) + head + html.slice(headIdx, xsIdx) + scriptTag + html.slice(xsIdx);
|
|
4288
4385
|
}
|
|
4289
|
-
function renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce) {
|
|
4386
|
+
function renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce, lowModules) {
|
|
4290
4387
|
let head = "";
|
|
4291
4388
|
const styleAttr = nonceAttr(nonce, "style");
|
|
4292
4389
|
const scriptAttr = nonceAttr(nonce, "script");
|
|
4293
4390
|
if (emittedAssets && emittedAssets.size) {
|
|
4294
4391
|
for (const url of emittedAssets) {
|
|
4295
|
-
head += isCssUrl(url) ? `<link rel="stylesheet" href="${url}"${styleAttr}>` :
|
|
4392
|
+
head += isCssUrl(url) ? `<link rel="stylesheet" href="${url}"${styleAttr}>` : modulePreloadLink(url, scriptAttr, lowModules);
|
|
4296
4393
|
}
|
|
4297
4394
|
}
|
|
4298
4395
|
if (preloadLinks) {
|
|
@@ -4493,14 +4590,7 @@ function resolveSSRNode(node, result = {
|
|
|
4493
4590
|
try {
|
|
4494
4591
|
resolveSSRNode(node(), result, false, true);
|
|
4495
4592
|
} catch (err) {
|
|
4496
|
-
|
|
4497
|
-
if (wrap) {
|
|
4498
|
-
if (ssrTextTail) result.t[result.t.length - 1] += "<!--!$-->";
|
|
4499
|
-
result.h.push(wrap.fn);
|
|
4500
|
-
result.p.push(wrap.p);
|
|
4501
|
-
result.t.push("");
|
|
4502
|
-
ssrTextTail = true;
|
|
4503
|
-
}
|
|
4593
|
+
pushSSRAsyncHole(result, err, node);
|
|
4504
4594
|
} finally {
|
|
4505
4595
|
if (scope) live.scope = scope;
|
|
4506
4596
|
}
|
|
@@ -4508,6 +4598,16 @@ function resolveSSRNode(node, result = {
|
|
|
4508
4598
|
}
|
|
4509
4599
|
return result;
|
|
4510
4600
|
}
|
|
4601
|
+
function pushSSRAsyncHole(result, err, node) {
|
|
4602
|
+
const wrap = buildAsyncWrap(err, node);
|
|
4603
|
+
if (wrap) {
|
|
4604
|
+
if (ssrTextTail) result.t[result.t.length - 1] += "<!--!$-->";
|
|
4605
|
+
result.h.push(wrap.fn);
|
|
4606
|
+
result.p.push(wrap.p);
|
|
4607
|
+
result.t.push("");
|
|
4608
|
+
ssrTextTail = true;
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4511
4611
|
function resolveSSRSync(node) {
|
|
4512
4612
|
const res = resolveSSRNode(node);
|
|
4513
4613
|
if (!res.h.length) return res.t[0];
|