@solidjs/web 2.0.0-beta.30 → 2.0.0-beta.32
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/README.md +1 -6
- package/dist/dev.cjs +284 -82
- package/dist/dev.js +271 -79
- package/dist/server.cjs +555 -135
- package/dist/server.js +544 -132
- package/dist/web.cjs +281 -79
- package/dist/web.js +268 -76
- package/frames/dist/client.cjs +413 -360
- package/frames/dist/client.dev.cjs +413 -360
- package/frames/dist/client.dev.js +414 -361
- package/frames/dist/client.js +414 -361
- package/frames/dist/server.cjs +604 -199
- package/frames/dist/server.js +605 -201
- package/package.json +56 -6
- package/serialization/dist/serialization.cjs +8 -0
- package/serialization/dist/serialization.js +1 -0
- package/serialization/types/index.d.ts +173 -6
- package/serialization/types-cjs/index.d.cts +173 -6
- package/server-functions/dist/client.cjs +46 -9
- package/server-functions/dist/client.js +47 -11
- package/server-functions/dist/rich-args.cjs +11 -0
- package/server-functions/dist/rich-args.js +9 -0
- package/server-functions/dist/server.cjs +275 -126
- package/server-functions/dist/server.dev.cjs +1053 -0
- package/server-functions/dist/server.dev.js +1021 -0
- package/server-functions/dist/server.js +273 -127
- package/server-functions/package.json +10 -0
- package/server-functions/rich-args/package.json +20 -0
- package/storage/types/index.d.ts +1 -1
- package/storage/types-cjs/index.d.cts +1 -1
- package/types/client.d.ts +134 -11
- package/types/core.d.ts +3 -1
- package/types/frames/client.d.ts +24 -8
- package/types/frames/frame-client.d.ts +49 -7
- package/types/frames/frame-sink.d.ts +32 -6
- package/types/frames/frame-transport.d.ts +88 -62
- package/types/frames/serializer.d.ts +173 -6
- package/types/frames/server.d.ts +22 -0
- package/types/index.d.ts +2 -3
- package/types/jsx.d.ts +3 -3
- package/types/response.d.ts +45 -0
- package/types/serializer.d.ts +173 -6
- package/types/server-functions/client.d.ts +1 -0
- package/types/server-functions/rich-args.d.ts +10 -0
- package/types/server-functions/server.d.ts +98 -0
- package/types/server-functions/shared.d.ts +22 -0
- package/types/server-mock.d.ts +171 -59
- package/types/server.d.ts +196 -42
- package/types-cjs/client.d.cts +134 -11
- package/types-cjs/core.d.cts +3 -1
- package/types-cjs/frames/client.d.cts +24 -8
- package/types-cjs/frames/frame-client.d.cts +49 -7
- package/types-cjs/frames/frame-sink.d.cts +32 -6
- package/types-cjs/frames/frame-transport.d.cts +88 -62
- package/types-cjs/frames/serializer.d.cts +173 -6
- package/types-cjs/frames/server.d.cts +22 -0
- package/types-cjs/index.d.cts +2 -3
- package/types-cjs/jsx.d.cts +3 -3
- package/types-cjs/response.d.cts +45 -0
- package/types-cjs/serializer.d.cts +173 -6
- package/types-cjs/server-functions/client.d.cts +1 -0
- package/types-cjs/server-functions/rich-args.d.cts +10 -0
- package/types-cjs/server-functions/server.d.cts +98 -0
- package/types-cjs/server-functions/shared.d.cts +22 -0
- package/types-cjs/server-mock.d.cts +171 -59
- package/types-cjs/server.d.cts +196 -42
package/dist/server.cjs
CHANGED
|
@@ -101,9 +101,144 @@ function getLocalHeaderScript(id) {
|
|
|
101
101
|
}
|
|
102
102
|
seroval.Feature.RegExp;
|
|
103
103
|
|
|
104
|
+
const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
|
|
105
|
+
class ResponseEnvelope {
|
|
106
|
+
constructor(response, value) {
|
|
107
|
+
this.response = response;
|
|
108
|
+
this.value = value;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
ResponseEnvelope.prototype[ENVELOPE] = true;
|
|
112
|
+
function isResponseEnvelope(value) {
|
|
113
|
+
return !!(value && typeof value === "object" && value[ENVELOPE]);
|
|
114
|
+
}
|
|
115
|
+
const HREF = Symbol.for("solid.Href");
|
|
116
|
+
function isHref(value) {
|
|
117
|
+
return !!(value && (typeof value === "object" || typeof value === "function") && value[HREF]);
|
|
118
|
+
}
|
|
119
|
+
const SAFE_ERROR = Symbol.for("solid.SafeError");
|
|
120
|
+
function markSafeError(error) {
|
|
121
|
+
if (error && (typeof error === "object" || typeof error === "function")) {
|
|
122
|
+
Object.defineProperty(error, SAFE_ERROR, {
|
|
123
|
+
value: true,
|
|
124
|
+
enumerable: false,
|
|
125
|
+
configurable: true
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return error;
|
|
129
|
+
}
|
|
130
|
+
function isSafeError(value) {
|
|
131
|
+
return !!(value && (typeof value === "object" || typeof value === "function") && value[SAFE_ERROR]);
|
|
132
|
+
}
|
|
133
|
+
const REVALIDATE_HEADER = "X-Revalidate";
|
|
134
|
+
function initWithRevalidate(init) {
|
|
135
|
+
const {
|
|
136
|
+
revalidate,
|
|
137
|
+
...responseInit
|
|
138
|
+
} = init;
|
|
139
|
+
let headers;
|
|
140
|
+
if (responseInit.headers && responseInit.headers.getSetCookie) {
|
|
141
|
+
headers = new Headers();
|
|
142
|
+
responseInit.headers.forEach((value, key) => {
|
|
143
|
+
if (key !== "set-cookie") headers.append(key, value);
|
|
144
|
+
});
|
|
145
|
+
for (const cookie of responseInit.headers.getSetCookie()) {
|
|
146
|
+
headers.append("Set-Cookie", cookie);
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
headers = new Headers(responseInit.headers);
|
|
150
|
+
}
|
|
151
|
+
revalidate !== undefined && headers.set(REVALIDATE_HEADER, revalidate.toString());
|
|
152
|
+
return {
|
|
153
|
+
responseInit,
|
|
154
|
+
headers
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function redirect(url, init = 302) {
|
|
158
|
+
if (typeof url !== "string" && !isHref(url)) {
|
|
159
|
+
throw new TypeError("redirect() expects a string URL or an Href-branded value (Symbol.for('solid.Href')).");
|
|
160
|
+
}
|
|
161
|
+
const {
|
|
162
|
+
responseInit,
|
|
163
|
+
headers
|
|
164
|
+
} = initWithRevalidate(typeof init === "number" ? {
|
|
165
|
+
status: init
|
|
166
|
+
} : init);
|
|
167
|
+
if (responseInit.status === undefined) {
|
|
168
|
+
responseInit.status = 302;
|
|
169
|
+
}
|
|
170
|
+
headers.set("Location", String(url));
|
|
171
|
+
return new Response(null, {
|
|
172
|
+
...responseInit,
|
|
173
|
+
headers
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function reload(init = {}) {
|
|
177
|
+
const {
|
|
178
|
+
responseInit,
|
|
179
|
+
headers
|
|
180
|
+
} = initWithRevalidate(init);
|
|
181
|
+
return new Response(null, {
|
|
182
|
+
...responseInit,
|
|
183
|
+
headers
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function respond(value, init = {}) {
|
|
187
|
+
const {
|
|
188
|
+
responseInit,
|
|
189
|
+
headers
|
|
190
|
+
} = initWithRevalidate(init);
|
|
191
|
+
headers.set("Content-Type", "application/json");
|
|
192
|
+
return new ResponseEnvelope(new Response(JSON.stringify(value), {
|
|
193
|
+
...responseInit,
|
|
194
|
+
headers
|
|
195
|
+
}), value);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const ERROR_HEADER = "X-Server-Function-Error";
|
|
199
|
+
const BODY_FORMAT_HEADER = "X-Server-Function-Format";
|
|
200
|
+
const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
|
|
201
|
+
|
|
202
|
+
function parseCookieHeader(header) {
|
|
203
|
+
const cookies = {};
|
|
204
|
+
if (!header) return cookies;
|
|
205
|
+
for (const part of header.split(";")) {
|
|
206
|
+
const eq = part.indexOf("=");
|
|
207
|
+
if (eq < 0) continue;
|
|
208
|
+
const name = decodeSafe(part.slice(0, eq).trim());
|
|
209
|
+
let value = part.slice(eq + 1).trim();
|
|
210
|
+
if (value.length > 1 && value[0] === '"' && value[value.length - 1] === '"') {
|
|
211
|
+
value = value.slice(1, -1);
|
|
212
|
+
}
|
|
213
|
+
cookies[name] = decodeSafe(value);
|
|
214
|
+
}
|
|
215
|
+
return cookies;
|
|
216
|
+
}
|
|
217
|
+
function decodeSafe(text) {
|
|
218
|
+
try {
|
|
219
|
+
return decodeURIComponent(text);
|
|
220
|
+
} catch {
|
|
221
|
+
return text;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function serializeCookie(name, value, options = {}) {
|
|
225
|
+
let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
|
|
226
|
+
cookie += `; Path=${options.path === undefined ? "/" : options.path}`;
|
|
227
|
+
if (options.domain) cookie += `; Domain=${options.domain}`;
|
|
228
|
+
if (options.maxAge !== undefined) cookie += `; Max-Age=${Math.trunc(options.maxAge)}`;
|
|
229
|
+
if (options.expires) cookie += `; Expires=${options.expires.toUTCString()}`;
|
|
230
|
+
if (options.httpOnly) cookie += "; HttpOnly";
|
|
231
|
+
if (options.secure) cookie += "; Secure";
|
|
232
|
+
if (options.sameSite) {
|
|
233
|
+
const sameSite = options.sameSite.toLowerCase();
|
|
234
|
+
cookie += `; SameSite=${sameSite === "none" ? "None" : sameSite === "strict" ? "Strict" : "Lax"}`;
|
|
235
|
+
}
|
|
236
|
+
return cookie;
|
|
237
|
+
}
|
|
238
|
+
|
|
104
239
|
const HEAD_ELIGIBLE_TAGS = new Set(["title", "meta", "link", "style", "script", "base"]);
|
|
105
240
|
const HEAD_ATTR_NAME = /^[a-zA-Z_][a-zA-Z0-9_:.-]*$/;
|
|
106
|
-
const RESOURCE_LINK_RELS = new Set(["preload", "modulepreload", "prefetch", "preconnect", "dns-prefetch", "
|
|
241
|
+
const RESOURCE_LINK_RELS = new Set(["preload", "modulepreload", "prefetch", "preconnect", "dns-prefetch", "stylesheet"]);
|
|
107
242
|
const RESOURCE_QUALIFIERS = ["as", "crossorigin", "type", "media", "imagesrcset", "imagesizes"];
|
|
108
243
|
const STYLESHEET_FETCH_META = new Set(["crossorigin", "integrity", "referrerpolicy", "fetchpriority"]);
|
|
109
244
|
function evalHeadValue(v) {
|
|
@@ -147,12 +282,14 @@ function replaceableIdentity(tag, props, key, unique) {
|
|
|
147
282
|
if (tag === "meta" && props.charset != null) return "charset";
|
|
148
283
|
if (key != null) return tag + ":key:" + key;
|
|
149
284
|
if (tag === "meta") {
|
|
150
|
-
if (props
|
|
151
|
-
if (props.property != null) return "meta:property:" + props.property;
|
|
152
|
-
if (props["http-equiv"] != null) return "meta:http-equiv:" + props["http-equiv"];
|
|
285
|
+
for (const ns of ["name", "property", "http-equiv"]) if (props[ns] != null) return "meta:" + ns + ":" + props[ns] + (props.media != null ? ":media=" + props.media : "");
|
|
153
286
|
return unique;
|
|
154
287
|
}
|
|
155
|
-
if (tag === "link")
|
|
288
|
+
if (tag === "link") {
|
|
289
|
+
const rel = props.rel || "";
|
|
290
|
+
if (rel === "icon" || rel === "apple-touch-icon") return "link:" + rel + (props.sizes != null ? ":sizes=" + props.sizes : "") + (props.type != null ? ":type=" + props.type : "");
|
|
291
|
+
return "link:" + rel + ":" + (props.href || "");
|
|
292
|
+
}
|
|
156
293
|
return unique;
|
|
157
294
|
}
|
|
158
295
|
function resolveHead(groups) {
|
|
@@ -339,11 +476,22 @@ function createHeadRegistry() {
|
|
|
339
476
|
resources: new Set(),
|
|
340
477
|
eagerHtml: "",
|
|
341
478
|
flushed: null,
|
|
342
|
-
shellFlushed: false
|
|
479
|
+
shellFlushed: false,
|
|
480
|
+
parkedResources: []
|
|
343
481
|
};
|
|
344
482
|
}
|
|
345
483
|
function registerHeadTags(registry, context, tracking, emitResource, nonce, tags) {
|
|
346
484
|
const boundary = context._currentBoundaryId || "";
|
|
485
|
+
if (typeof tags === "function") {
|
|
486
|
+
registry.pending.push({
|
|
487
|
+
boundary,
|
|
488
|
+
list: tags,
|
|
489
|
+
resource: (desc, rel) => emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel)
|
|
490
|
+
});
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (!Array.isArray(tags)) tags = [tags];
|
|
494
|
+
const probe = solidJs.sharedConfig.context && solidJs.sharedConfig.context._loadingPhase;
|
|
347
495
|
let replaceable = null;
|
|
348
496
|
for (let i = 0; i < tags.length; i++) {
|
|
349
497
|
const desc = tags[i];
|
|
@@ -352,6 +500,16 @@ function registerHeadTags(registry, context, tracking, emitResource, nonce, tags
|
|
|
352
500
|
continue;
|
|
353
501
|
}
|
|
354
502
|
const cls = classifyHeadTag(desc);
|
|
503
|
+
if (probe && !cls.resource) {
|
|
504
|
+
try {
|
|
505
|
+
evalHeadProps(desc.props || {}, cls.rel !== undefined ? {
|
|
506
|
+
rel: cls.rel
|
|
507
|
+
} : undefined);
|
|
508
|
+
evalHeadValue(desc.key);
|
|
509
|
+
} catch (err) {
|
|
510
|
+
if (solidJs.ssrHandleError(err)) throw err;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
355
513
|
if (cls.resource) {
|
|
356
514
|
emitHeadResource(registry, context, tracking, emitResource, nonce, desc, cls.rel);
|
|
357
515
|
} else {
|
|
@@ -368,6 +526,52 @@ function registerHeadTags(registry, context, tracking, emitResource, nonce, tags
|
|
|
368
526
|
tags: replaceable
|
|
369
527
|
});
|
|
370
528
|
}
|
|
529
|
+
function headShellReady(registry, block) {
|
|
530
|
+
let ready = true;
|
|
531
|
+
const pends = err => {
|
|
532
|
+
const source = solidJs.ssrHandleError(err, true);
|
|
533
|
+
if (!source) return false;
|
|
534
|
+
block(source);
|
|
535
|
+
ready = false;
|
|
536
|
+
return true;
|
|
537
|
+
};
|
|
538
|
+
const parked = registry.parkedResources;
|
|
539
|
+
for (let i = parked.length - 1; i >= 0; i--) {
|
|
540
|
+
const {
|
|
541
|
+
desc,
|
|
542
|
+
rel,
|
|
543
|
+
emit
|
|
544
|
+
} = parked[i];
|
|
545
|
+
try {
|
|
546
|
+
evalHeadProps(desc.props || {}, rel !== undefined ? {
|
|
547
|
+
rel
|
|
548
|
+
} : undefined);
|
|
549
|
+
} catch (err) {
|
|
550
|
+
if (pends(err)) continue;
|
|
551
|
+
console.warn(`useHead: error evaluating resource tag props`, err);
|
|
552
|
+
parked.splice(i, 1);
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
parked.splice(i, 1);
|
|
556
|
+
emit();
|
|
557
|
+
}
|
|
558
|
+
for (let i = 0; i < registry.pending.length; i++) {
|
|
559
|
+
const reg = registry.pending[i];
|
|
560
|
+
if (reg.boundary !== "" || reg.list) continue;
|
|
561
|
+
for (let j = 0; j < reg.tags.length; j++) {
|
|
562
|
+
const desc = reg.tags[j];
|
|
563
|
+
try {
|
|
564
|
+
evalHeadProps(desc.props || {}, desc.rel !== undefined ? {
|
|
565
|
+
rel: desc.rel
|
|
566
|
+
} : undefined);
|
|
567
|
+
evalHeadValue(desc.key);
|
|
568
|
+
} catch (err) {
|
|
569
|
+
pends(err);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return ready;
|
|
574
|
+
}
|
|
371
575
|
function emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel) {
|
|
372
576
|
let props;
|
|
373
577
|
try {
|
|
@@ -375,6 +579,16 @@ function emitHeadResource(registry, context, tracking, emitResource, nonce, desc
|
|
|
375
579
|
rel
|
|
376
580
|
} : undefined);
|
|
377
581
|
} catch (err) {
|
|
582
|
+
const loadingPhase = solidJs.sharedConfig.context && solidJs.sharedConfig.context._loadingPhase;
|
|
583
|
+
if (loadingPhase && solidJs.ssrHandleError(err)) throw err;
|
|
584
|
+
if (!loadingPhase && !context._currentBoundaryId && !registry.shellFlushed && typeof context.block === "function" && solidJs.ssrHandleError(err, true)) {
|
|
585
|
+
registry.parkedResources.push({
|
|
586
|
+
desc,
|
|
587
|
+
rel,
|
|
588
|
+
emit: () => emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel)
|
|
589
|
+
});
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
378
592
|
console.warn(`useHead: error evaluating resource tag props`, err);
|
|
379
593
|
return;
|
|
380
594
|
}
|
|
@@ -431,9 +645,39 @@ function commitHeadBoundary(registry, boundary, isPendingFragment) {
|
|
|
431
645
|
keep.push(reg);
|
|
432
646
|
continue;
|
|
433
647
|
}
|
|
648
|
+
let descs = reg.tags;
|
|
649
|
+
if (reg.list) {
|
|
650
|
+
let resolved;
|
|
651
|
+
try {
|
|
652
|
+
resolved = reg.list();
|
|
653
|
+
} catch (err) {
|
|
654
|
+
console.warn(`useHead: error evaluating head group membership`, err);
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
if (!Array.isArray(resolved)) resolved = [resolved];
|
|
658
|
+
descs = [];
|
|
659
|
+
for (let j = 0; j < resolved.length; j++) {
|
|
660
|
+
const desc = resolved[j];
|
|
661
|
+
if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
|
|
662
|
+
console.warn(`useHead: ignoring non-head tag`, desc);
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
const cls = classifyHeadTag(desc);
|
|
666
|
+
if (cls.resource) {
|
|
667
|
+
reg.resource(desc, cls.rel);
|
|
668
|
+
} else {
|
|
669
|
+
descs.push(cls.rel !== undefined ? {
|
|
670
|
+
tag: desc.tag,
|
|
671
|
+
props: desc.props,
|
|
672
|
+
key: desc.key,
|
|
673
|
+
rel: cls.rel
|
|
674
|
+
} : desc);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
434
678
|
const tags = [];
|
|
435
|
-
for (let j = 0; j <
|
|
436
|
-
const desc =
|
|
679
|
+
for (let j = 0; j < descs.length; j++) {
|
|
680
|
+
const desc = descs[j];
|
|
437
681
|
let props, key;
|
|
438
682
|
try {
|
|
439
683
|
props = evalHeadProps(desc.props || {}, desc.rel !== undefined ? {
|
|
@@ -582,10 +826,10 @@ function useHead(tags) {
|
|
|
582
826
|
console.warn("useHead() called outside of a server render; registration ignored.");
|
|
583
827
|
return;
|
|
584
828
|
}
|
|
585
|
-
ctx.registerHeadTags(
|
|
829
|
+
ctx.registerHeadTags(tags);
|
|
586
830
|
}
|
|
587
831
|
const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
|
|
588
|
-
const REPLACE_SCRIPT = `function $df(e){return _$HY.f?_$HY.f(e):$dfr(e)}function $dfr(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById("pl-"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!=="pl-"+e);)t=o.nextSibling,o.remove(),o=t;t=o.parentNode,o.replaceWith(n.content),n.remove(),_$HY.fe(e,t),_$HY.hp&&_$HY.hp[e]&&($dh(_$HY.hp[e]),delete _$HY.hp[e]),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById("pl-"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue==="pl-"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}`;
|
|
832
|
+
const REPLACE_SCRIPT = `function $df(e){return _$HY.f?_$HY.f(e):$dfr(e)}function $dfr(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById("pl-"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!=="pl-"+e);)t=o.nextSibling,o.remove(),o=t;t=o.parentNode,o.replaceWith(n.content),n.remove(),(_$HY.v=_$HY.v||{})[e]=1,_$HY.fe(e,t),_$HY.hp&&_$HY.hp[e]&&($dh(_$HY.hp[e]),delete _$HY.hp[e]),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById("pl-"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue==="pl-"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}`;
|
|
589
833
|
const HEAD_SCRIPT = `function $dha(o,i,e,n){for(i=0;i<o.length;i++)e=o[i],"t"==e[0]?((n=document.querySelector("title"))||(n=document.createElement("title"),document.head.appendChild(n)),n.textContent=e[1],n.setAttribute("data-dh","title")):"r"==e[0]?$dhr(e[1]):(n=document.createElement(e[2]),Object.keys(e[3]).forEach(function(a){n.setAttribute(a,e[3][a])}),null!=e[4]&&(n.textContent=e[4]),n.setAttribute("data-dh",e[1]),document.head.appendChild(n))}function $dhr(v,l,i){for(l=document.head.querySelectorAll("[data-dh]"),i=0;i<l.length;i++)l[i].getAttribute("data-dh")==v&&l[i].remove()}function $dh(o){_$HY.h?_$HY.h(o):$dha(o)}`;
|
|
590
834
|
function renderToString(code, options = {}) {
|
|
591
835
|
const {
|
|
@@ -611,7 +855,6 @@ function renderToString(code, options = {}) {
|
|
|
611
855
|
const tracking = createAssetTracking();
|
|
612
856
|
const headRegistry = createHeadRegistry();
|
|
613
857
|
solidJs.sharedConfig.context = {
|
|
614
|
-
assets: [],
|
|
615
858
|
nonce,
|
|
616
859
|
escape: escape,
|
|
617
860
|
resolve: resolveSSRNode,
|
|
@@ -653,9 +896,8 @@ function renderToString(code, options = {}) {
|
|
|
653
896
|
serializeFragmentAssets("", tracking.boundaryModules, solidJs.sharedConfig.context);
|
|
654
897
|
solidJs.sharedConfig.context.noHydrate = true;
|
|
655
898
|
serializer.close();
|
|
656
|
-
const assetsHtml = resolveAssetsHtml(solidJs.sharedConfig.context.assets);
|
|
657
899
|
const head = renderShellHead(headRegistry, nonce, null);
|
|
658
|
-
return assembleDocument(html,
|
|
900
|
+
return assembleDocument(html, tracking.emittedAssets, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead);
|
|
659
901
|
}
|
|
660
902
|
function renderToStream(code, options = {}) {
|
|
661
903
|
let {
|
|
@@ -668,6 +910,41 @@ function renderToStream(code, options = {}) {
|
|
|
668
910
|
onHead
|
|
669
911
|
} = options;
|
|
670
912
|
let dispose;
|
|
913
|
+
let dead = false;
|
|
914
|
+
const abandon = () => {
|
|
915
|
+
if (dead) return;
|
|
916
|
+
dead = true;
|
|
917
|
+
completed = true;
|
|
918
|
+
buffer = {
|
|
919
|
+
write() {}
|
|
920
|
+
};
|
|
921
|
+
writable = {
|
|
922
|
+
end() {}
|
|
923
|
+
};
|
|
924
|
+
if (dispose) {
|
|
925
|
+
const d = dispose;
|
|
926
|
+
dispose = () => {};
|
|
927
|
+
d();
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
const guardSink = w => ({
|
|
931
|
+
write(payload) {
|
|
932
|
+
if (dead) return;
|
|
933
|
+
try {
|
|
934
|
+
w.write(payload);
|
|
935
|
+
} catch (_) {
|
|
936
|
+
abandon();
|
|
937
|
+
}
|
|
938
|
+
},
|
|
939
|
+
end() {
|
|
940
|
+
if (dead) return;
|
|
941
|
+
try {
|
|
942
|
+
w.end();
|
|
943
|
+
} catch (_) {
|
|
944
|
+
abandon();
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
});
|
|
671
948
|
const blockingPromises = new Set();
|
|
672
949
|
let headerEmitted = false;
|
|
673
950
|
const pushTask = task => {
|
|
@@ -731,7 +1008,7 @@ function renderToStream(code, options = {}) {
|
|
|
731
1008
|
}
|
|
732
1009
|
},
|
|
733
1010
|
shell(shellHtml, meta) {
|
|
734
|
-
buffer.write(assembleDocument(shellHtml, meta.
|
|
1011
|
+
buffer.write(assembleDocument(shellHtml, meta.preloads, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead));
|
|
735
1012
|
},
|
|
736
1013
|
...options.sink
|
|
737
1014
|
};
|
|
@@ -811,7 +1088,6 @@ function renderToStream(code, options = {}) {
|
|
|
811
1088
|
};
|
|
812
1089
|
solidJs.sharedConfig.context = context = {
|
|
813
1090
|
async: true,
|
|
814
|
-
assets: [],
|
|
815
1091
|
nonce,
|
|
816
1092
|
registerHeadTags(tags) {
|
|
817
1093
|
registerHeadTags(headRegistry, context, tracking,
|
|
@@ -1011,9 +1287,9 @@ function renderToStream(code, options = {}) {
|
|
|
1011
1287
|
}
|
|
1012
1288
|
function doShell() {
|
|
1013
1289
|
if (shellCompleted) return;
|
|
1014
|
-
if (!resolveRootHoles()) return;
|
|
1015
1290
|
solidJs.sharedConfig.context = context;
|
|
1016
|
-
|
|
1291
|
+
if (!resolveRootHoles()) return;
|
|
1292
|
+
if (!headShellReady(headRegistry, p => blockingPromises.add(p))) return;
|
|
1017
1293
|
headStyles = new Set();
|
|
1018
1294
|
for (const url of tracking.emittedAssets) {
|
|
1019
1295
|
if (isCssUrl(url)) headStyles.add(url);
|
|
@@ -1021,7 +1297,6 @@ function renderToStream(code, options = {}) {
|
|
|
1021
1297
|
serializeRootAssets();
|
|
1022
1298
|
const head = renderShellHead(headRegistry, nonce, k => registry.has(k));
|
|
1023
1299
|
sink.shell(html, {
|
|
1024
|
-
assets: assetsHtml,
|
|
1025
1300
|
preloads: tracking.emittedAssets,
|
|
1026
1301
|
inlineStyles: tracking.inlineStyles,
|
|
1027
1302
|
tasks,
|
|
@@ -1069,14 +1344,24 @@ function renderToStream(code, options = {}) {
|
|
|
1069
1344
|
function flush() {
|
|
1070
1345
|
allSettled(blockingPromises).then(() => {
|
|
1071
1346
|
scheduleFlush(() => {
|
|
1347
|
+
if (dead) return resolve();
|
|
1072
1348
|
doShell();
|
|
1073
1349
|
if (!shellCompleted) return flush();
|
|
1074
1350
|
const encoder = new TextEncoder();
|
|
1075
1351
|
const writer = w.getWriter();
|
|
1076
1352
|
let pendingWrites = Promise.resolve();
|
|
1353
|
+
let ended = false;
|
|
1354
|
+
const failed = () => {
|
|
1355
|
+
if (!ended) {
|
|
1356
|
+
abandon();
|
|
1357
|
+
resolve();
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
writer.closed && writer.closed.catch(failed);
|
|
1077
1361
|
writable = {
|
|
1078
1362
|
end() {
|
|
1079
1363
|
pendingWrites.then(() => {
|
|
1364
|
+
ended = true;
|
|
1080
1365
|
writer.releaseLock();
|
|
1081
1366
|
w.close().catch(() => {});
|
|
1082
1367
|
resolve();
|
|
@@ -1085,7 +1370,7 @@ function renderToStream(code, options = {}) {
|
|
|
1085
1370
|
};
|
|
1086
1371
|
buffer = {
|
|
1087
1372
|
write(payload) {
|
|
1088
|
-
pendingWrites = pendingWrites.then(() => writer.write(encoder.encode(payload))).catch(
|
|
1373
|
+
pendingWrites = pendingWrites.then(() => writer.write(encoder.encode(payload))).catch(failed);
|
|
1089
1374
|
}
|
|
1090
1375
|
};
|
|
1091
1376
|
buffer.write(tmp);
|
|
@@ -1101,36 +1386,40 @@ function renderToStream(code, options = {}) {
|
|
|
1101
1386
|
return p;
|
|
1102
1387
|
};
|
|
1103
1388
|
return {
|
|
1104
|
-
then(
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1389
|
+
then(onFulfilled, onRejected) {
|
|
1390
|
+
const p = new Promise(resolve => {
|
|
1391
|
+
function complete() {
|
|
1392
|
+
dispose();
|
|
1393
|
+
resolve(tmp);
|
|
1394
|
+
}
|
|
1395
|
+
if (onCompleteAll) {
|
|
1396
|
+
let ogComplete = onCompleteAll;
|
|
1397
|
+
onCompleteAll = options => {
|
|
1398
|
+
ogComplete(options);
|
|
1399
|
+
complete();
|
|
1400
|
+
};
|
|
1401
|
+
} else onCompleteAll = complete;
|
|
1402
|
+
function flush() {
|
|
1403
|
+
allSettled(blockingPromises).then(() => {
|
|
1404
|
+
scheduleFlush(() => {
|
|
1405
|
+
if (!resolveRootHoles() || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
|
|
1406
|
+
queue(flushEnd);
|
|
1407
|
+
});
|
|
1121
1408
|
});
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
|
|
1409
|
+
}
|
|
1410
|
+
flush();
|
|
1411
|
+
});
|
|
1412
|
+
return p.then(onFulfilled, onRejected);
|
|
1125
1413
|
},
|
|
1126
1414
|
pipe(w) {
|
|
1127
1415
|
claimConsumer("pipe");
|
|
1128
1416
|
function flush() {
|
|
1129
1417
|
allSettled(blockingPromises).then(() => {
|
|
1130
1418
|
scheduleFlush(() => {
|
|
1419
|
+
if (dead) return;
|
|
1131
1420
|
doShell();
|
|
1132
1421
|
if (!shellCompleted) return flush();
|
|
1133
|
-
buffer = writable = w;
|
|
1422
|
+
buffer = writable = guardSink(w);
|
|
1134
1423
|
buffer.write(tmp);
|
|
1135
1424
|
firstFlushed = true;
|
|
1136
1425
|
if (completed) {
|
|
@@ -1491,18 +1780,6 @@ function getHydrationKey() {
|
|
|
1491
1780
|
function applyRef(r, element) {
|
|
1492
1781
|
Array.isArray(r) ? r.flat(Infinity).forEach(f => f && f(element)) : r(element);
|
|
1493
1782
|
}
|
|
1494
|
-
function useAssets(fn) {
|
|
1495
|
-
solidJs.sharedConfig.context.assets.push(() => resolveSSRSync(escape(fn())));
|
|
1496
|
-
}
|
|
1497
|
-
function getAssets() {
|
|
1498
|
-
const assets = solidJs.sharedConfig.context.assets;
|
|
1499
|
-
let out = "";
|
|
1500
|
-
for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
|
|
1501
|
-
return out;
|
|
1502
|
-
}
|
|
1503
|
-
function Assets(props) {
|
|
1504
|
-
useAssets(() => props.children);
|
|
1505
|
-
}
|
|
1506
1783
|
function generateHydrationScript({
|
|
1507
1784
|
eventNames = ["click", "input"],
|
|
1508
1785
|
nonce
|
|
@@ -1519,17 +1796,11 @@ function allSettled(promises) {
|
|
|
1519
1796
|
return;
|
|
1520
1797
|
});
|
|
1521
1798
|
}
|
|
1522
|
-
function
|
|
1523
|
-
if (!assets || !assets.length) return "";
|
|
1524
|
-
let out = "";
|
|
1525
|
-
for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
|
|
1526
|
-
return out;
|
|
1527
|
-
}
|
|
1528
|
-
function assembleDocument(html, assetsHtml, emittedAssets, inlineStyles, scripts, nonce, headTags, onHead) {
|
|
1799
|
+
function assembleDocument(html, emittedAssets, inlineStyles, scripts, nonce, headTags, onHead) {
|
|
1529
1800
|
const scriptTag = scripts ? `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>` : "";
|
|
1530
1801
|
const headTagsHtml = headTags ? headTags.html : "";
|
|
1531
1802
|
const headPrelude = headTags ? headTags.prelude : "";
|
|
1532
|
-
if (!onHead && !
|
|
1803
|
+
if (!onHead && !headTagsHtml && !headPrelude && !(emittedAssets && emittedAssets.size) && !(inlineStyles && inlineStyles.size)) {
|
|
1533
1804
|
if (!scriptTag) return html;
|
|
1534
1805
|
const xs = html.indexOf("<!--xs-->");
|
|
1535
1806
|
return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
|
|
@@ -1544,13 +1815,13 @@ function assembleDocument(html, assetsHtml, emittedAssets, inlineStyles, scripts
|
|
|
1544
1815
|
const headIdx = html.indexOf("</head>");
|
|
1545
1816
|
if (headIdx === -1) {
|
|
1546
1817
|
if (onHead) {
|
|
1547
|
-
onHead(headPrelude + headTagsHtml +
|
|
1818
|
+
onHead(headPrelude + headTagsHtml + renderHeadAssets(emittedAssets, inlineStyles, nonce));
|
|
1548
1819
|
}
|
|
1549
1820
|
if (!scriptTag) return html;
|
|
1550
1821
|
const xs = html.indexOf("<!--xs-->");
|
|
1551
1822
|
return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
|
|
1552
1823
|
}
|
|
1553
|
-
const head = headTagsHtml +
|
|
1824
|
+
const head = headTagsHtml + renderHeadAssets(emittedAssets, inlineStyles, nonce);
|
|
1554
1825
|
if (!scriptTag) return html.slice(0, headIdx) + head + html.slice(headIdx);
|
|
1555
1826
|
const xsIdx = html.indexOf("<!--xs-->");
|
|
1556
1827
|
if (xsIdx === -1) return html.slice(0, headIdx) + head + html.slice(headIdx) + scriptTag;
|
|
@@ -1750,90 +2021,226 @@ const RequestContext = Symbol.for("solid.RequestContext");
|
|
|
1750
2021
|
function getRequestEvent() {
|
|
1751
2022
|
return globalThis[RequestContext] ? globalThis[RequestContext].getStore() || solidJs.sharedConfig.context && solidJs.sharedConfig.context.event || console.warn("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.") : undefined;
|
|
1752
2023
|
}
|
|
1753
|
-
function
|
|
1754
|
-
return
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
function claimElement(node) {
|
|
1761
|
-
return node;
|
|
2024
|
+
function createResponseStub() {
|
|
2025
|
+
return {
|
|
2026
|
+
status: undefined,
|
|
2027
|
+
statusText: undefined,
|
|
2028
|
+
headers: new Headers(),
|
|
2029
|
+
committed: false
|
|
2030
|
+
};
|
|
1762
2031
|
}
|
|
1763
|
-
function
|
|
1764
|
-
return
|
|
2032
|
+
function createRequestEvent(request, init) {
|
|
2033
|
+
return {
|
|
2034
|
+
request,
|
|
2035
|
+
locals: {},
|
|
2036
|
+
response: createResponseStub(),
|
|
2037
|
+
...init
|
|
2038
|
+
};
|
|
1765
2039
|
}
|
|
1766
|
-
function
|
|
1767
|
-
|
|
2040
|
+
function reportLostHeaderWrite(method, name) {
|
|
2041
|
+
const message = `Response header write dropped: headers.${method}(${JSON.stringify(String(name))}) ` + "ran after the response head was sent. Write headers before the shell flushes " + "(or before the handler returns).";
|
|
2042
|
+
throw new Error(message);
|
|
1768
2043
|
}
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
2044
|
+
function commitResponseStub(stub, {
|
|
2045
|
+
allowLateLocation = false
|
|
2046
|
+
} = {}) {
|
|
2047
|
+
if (!stub || stub.committed) return stub;
|
|
2048
|
+
stub.committed = true;
|
|
2049
|
+
const headers = stub.headers;
|
|
2050
|
+
if (!headers || typeof headers.set !== "function") return stub;
|
|
2051
|
+
for (const method of ["set", "append", "delete"]) {
|
|
2052
|
+
const original = headers[method].bind(headers);
|
|
2053
|
+
headers[method] = function (name, ...rest) {
|
|
2054
|
+
if (allowLateLocation && method === "set" && String(name).toLowerCase() === "location") {
|
|
2055
|
+
return original(name, ...rest);
|
|
2056
|
+
}
|
|
2057
|
+
reportLostHeaderWrite(method, name);
|
|
2058
|
+
};
|
|
1775
2059
|
}
|
|
2060
|
+
return stub;
|
|
1776
2061
|
}
|
|
1777
|
-
|
|
1778
|
-
function
|
|
1779
|
-
|
|
2062
|
+
const validRedirectStatuses = /*#__PURE__*/new Set([301, 302, 303, 307, 308]);
|
|
2063
|
+
function getExpectedRedirectStatus(response) {
|
|
2064
|
+
if (response.status && validRedirectStatuses.has(response.status)) return response.status;
|
|
2065
|
+
return 302;
|
|
1780
2066
|
}
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
2067
|
+
function mergeStubHeaders(target, stub) {
|
|
2068
|
+
if (!stub) return target;
|
|
2069
|
+
stub.headers.forEach((value, key) => {
|
|
2070
|
+
if (key !== "set-cookie") target.set(key, value);
|
|
2071
|
+
});
|
|
2072
|
+
const setCookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
|
|
2073
|
+
for (const cookie of setCookies) target.append("set-cookie", cookie);
|
|
2074
|
+
return target;
|
|
2075
|
+
}
|
|
2076
|
+
function copyInitHeaders(init) {
|
|
2077
|
+
if (!init || !init.getSetCookie) return new Headers(init);
|
|
2078
|
+
const headers = new Headers();
|
|
2079
|
+
init.forEach((value, key) => {
|
|
2080
|
+
if (key !== "set-cookie") headers.append(key, value);
|
|
2081
|
+
});
|
|
2082
|
+
for (const cookie of init.getSetCookie()) headers.append("Set-Cookie", cookie);
|
|
2083
|
+
return headers;
|
|
2084
|
+
}
|
|
2085
|
+
const STUB_GAP_FILL_EXCLUDED = /*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, "Location"].map(header => header.toLowerCase()));
|
|
2086
|
+
function fillsStubGap(key, headers, response) {
|
|
2087
|
+
if (key === "set-cookie" || STUB_GAP_FILL_EXCLUDED.has(key)) return false;
|
|
2088
|
+
if (response.body === null && (key === "content-type" || key === "content-length")) return false;
|
|
2089
|
+
return !headers.has(key);
|
|
2090
|
+
}
|
|
2091
|
+
function commitEventResponse(response, event = getRequestEvent()) {
|
|
2092
|
+
const stub = event && event.response;
|
|
2093
|
+
if (!stub || !stub.headers || stub.committed) return response;
|
|
2094
|
+
const cookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
|
|
2095
|
+
commitResponseStub(stub);
|
|
2096
|
+
let hasGaps = false;
|
|
2097
|
+
stub.headers.forEach((value, key) => {
|
|
2098
|
+
if (fillsStubGap(key, response.headers, response)) hasGaps = true;
|
|
2099
|
+
});
|
|
2100
|
+
if (!cookies.length && !hasGaps) return response;
|
|
2101
|
+
try {
|
|
2102
|
+
for (const cookie of cookies) response.headers.append("Set-Cookie", cookie);
|
|
2103
|
+
stub.headers.forEach((value, key) => {
|
|
2104
|
+
if (fillsStubGap(key, response.headers, response)) response.headers.set(key, value);
|
|
2105
|
+
});
|
|
2106
|
+
return response;
|
|
2107
|
+
} catch {
|
|
2108
|
+
const headers = copyInitHeaders(response.headers);
|
|
2109
|
+
for (const cookie of cookies) headers.append("Set-Cookie", cookie);
|
|
2110
|
+
stub.headers.forEach((value, key) => {
|
|
2111
|
+
if (fillsStubGap(key, headers, response)) headers.set(key, value);
|
|
2112
|
+
});
|
|
2113
|
+
return new Response(response.body, {
|
|
2114
|
+
status: response.status,
|
|
2115
|
+
statusText: response.statusText,
|
|
2116
|
+
headers
|
|
2117
|
+
});
|
|
2118
|
+
}
|
|
1784
2119
|
}
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
const
|
|
1788
|
-
|
|
1789
|
-
...responseInit
|
|
1790
|
-
} = init;
|
|
1791
|
-
const headers = new Headers(responseInit.headers);
|
|
1792
|
-
revalidate !== undefined && headers.set(REVALIDATE_HEADER, revalidate.toString());
|
|
2120
|
+
function deriveHead(stub, responseInit = {}) {
|
|
2121
|
+
const headers = mergeStubHeaders(copyInitHeaders(responseInit.headers), stub);
|
|
2122
|
+
const status = stub && stub.status || responseInit.status || 200;
|
|
2123
|
+
const statusText = stub && stub.statusText || responseInit.statusText || undefined;
|
|
1793
2124
|
return {
|
|
1794
|
-
|
|
2125
|
+
status,
|
|
2126
|
+
statusText,
|
|
1795
2127
|
headers
|
|
1796
2128
|
};
|
|
1797
2129
|
}
|
|
1798
|
-
function
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
2130
|
+
function escapeAttribute(value) {
|
|
2131
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
2132
|
+
}
|
|
2133
|
+
function createSSRResponse(result, event, options = {}) {
|
|
2134
|
+
const stub = event && event.response;
|
|
1802
2135
|
const {
|
|
1803
2136
|
responseInit,
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
2137
|
+
nonce,
|
|
2138
|
+
transformChunk
|
|
2139
|
+
} = options;
|
|
2140
|
+
if (typeof result === "string") {
|
|
2141
|
+
if (stub) commitResponseStub(stub);
|
|
2142
|
+
const head = deriveHead(stub, responseInit);
|
|
2143
|
+
if (stub && stub.headers.get("Location")) {
|
|
2144
|
+
return new Response(null, {
|
|
2145
|
+
status: getExpectedRedirectStatus(stub),
|
|
2146
|
+
headers: head.headers
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
if (!head.headers.has("content-type")) {
|
|
2150
|
+
head.headers.set("content-type", "text/html; charset=utf-8");
|
|
2151
|
+
}
|
|
2152
|
+
return new Response(transformChunk ? transformChunk(result) : result, {
|
|
2153
|
+
status: head.status,
|
|
2154
|
+
statusText: head.statusText,
|
|
2155
|
+
headers: head.headers
|
|
2156
|
+
});
|
|
1810
2157
|
}
|
|
1811
|
-
|
|
1812
|
-
return new
|
|
1813
|
-
|
|
1814
|
-
|
|
2158
|
+
const encoder = new TextEncoder();
|
|
2159
|
+
return new Promise(resolve => {
|
|
2160
|
+
let controller;
|
|
2161
|
+
let closed = false;
|
|
2162
|
+
let flushed = false;
|
|
2163
|
+
const enqueue = value => {
|
|
2164
|
+
if (closed || !controller) return;
|
|
2165
|
+
try {
|
|
2166
|
+
controller.enqueue(encoder.encode(value));
|
|
2167
|
+
} catch {
|
|
2168
|
+
closed = true;
|
|
2169
|
+
}
|
|
2170
|
+
};
|
|
2171
|
+
result.pipe({
|
|
2172
|
+
write(chunk) {
|
|
2173
|
+
if (!flushed) {
|
|
2174
|
+
flushed = true;
|
|
2175
|
+
if (stub) commitResponseStub(stub, {
|
|
2176
|
+
allowLateLocation: true
|
|
2177
|
+
});
|
|
2178
|
+
const head = deriveHead(stub, responseInit);
|
|
2179
|
+
if (stub && stub.headers.get("Location")) {
|
|
2180
|
+
closed = true;
|
|
2181
|
+
resolve(new Response(null, {
|
|
2182
|
+
status: getExpectedRedirectStatus(stub),
|
|
2183
|
+
headers: head.headers
|
|
2184
|
+
}));
|
|
2185
|
+
return;
|
|
2186
|
+
}
|
|
2187
|
+
if (!head.headers.has("content-type")) {
|
|
2188
|
+
head.headers.set("content-type", "text/html; charset=utf-8");
|
|
2189
|
+
}
|
|
2190
|
+
resolve(new Response(new ReadableStream({
|
|
2191
|
+
start(c) {
|
|
2192
|
+
controller = c;
|
|
2193
|
+
},
|
|
2194
|
+
cancel() {
|
|
2195
|
+
closed = true;
|
|
2196
|
+
}
|
|
2197
|
+
}), {
|
|
2198
|
+
status: head.status,
|
|
2199
|
+
statusText: head.statusText,
|
|
2200
|
+
headers: head.headers
|
|
2201
|
+
}));
|
|
2202
|
+
}
|
|
2203
|
+
enqueue(transformChunk ? transformChunk(chunk) : chunk);
|
|
2204
|
+
},
|
|
2205
|
+
end() {
|
|
2206
|
+
if (closed || !controller) return;
|
|
2207
|
+
const location = stub && stub.headers.get("Location");
|
|
2208
|
+
if (location) {
|
|
2209
|
+
const attr = nonce ? ` nonce="${escapeAttribute(nonce)}"` : "";
|
|
2210
|
+
enqueue(`<script${attr}>window.location=${JSON.stringify(location).replace(/</g, "\\u003c")}</script>`);
|
|
2211
|
+
}
|
|
2212
|
+
closed = true;
|
|
2213
|
+
try {
|
|
2214
|
+
controller.close();
|
|
2215
|
+
} catch {}
|
|
2216
|
+
}
|
|
2217
|
+
});
|
|
1815
2218
|
});
|
|
1816
2219
|
}
|
|
1817
|
-
function
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
2220
|
+
function composeMiddleware(middlewares) {
|
|
2221
|
+
return function run(request, next) {
|
|
2222
|
+
let index = -1;
|
|
2223
|
+
function dispatch(i, req) {
|
|
2224
|
+
if (i <= index) return Promise.reject(new Error("next() called multiple times"));
|
|
2225
|
+
index = i;
|
|
2226
|
+
if (i === middlewares.length) return Promise.resolve(next(req));
|
|
2227
|
+
return Promise.resolve(middlewares[i](req, override => dispatch(i + 1, override || req)));
|
|
2228
|
+
}
|
|
2229
|
+
return dispatch(0, request);
|
|
2230
|
+
};
|
|
1826
2231
|
}
|
|
1827
|
-
function
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
2232
|
+
function registerElementClaim() {
|
|
2233
|
+
return noopCleanup;
|
|
2234
|
+
}
|
|
2235
|
+
function noopCleanup() {}
|
|
2236
|
+
function claimElement(node) {
|
|
2237
|
+
return node;
|
|
2238
|
+
}
|
|
2239
|
+
function claimElementTree(root) {
|
|
2240
|
+
return root;
|
|
2241
|
+
}
|
|
2242
|
+
function notSup() {
|
|
2243
|
+
throw new Error("Client-only API called on the server side. Run client-only code in onMount, or conditionally run client-only component with <Show>.");
|
|
1837
2244
|
}
|
|
1838
2245
|
|
|
1839
2246
|
const isServer = true;
|
|
@@ -1921,11 +2328,16 @@ function httpHeader(name, value, options) {
|
|
|
1921
2328
|
const response = event && event.response;
|
|
1922
2329
|
if (response && !response.committed) {
|
|
1923
2330
|
const headers = response.headers;
|
|
1924
|
-
const
|
|
2331
|
+
const setCookie = name.toLowerCase() === "set-cookie";
|
|
2332
|
+
const prevCookies = setCookie ? headers.getSetCookie() : undefined;
|
|
2333
|
+
const prev = setCookie ? null : headers.get(name);
|
|
1925
2334
|
if (options && options.append) headers.append(name, value);else headers.set(name, value);
|
|
1926
2335
|
solidJs.onCleanup(() => {
|
|
1927
2336
|
if (response.committed) return;
|
|
1928
|
-
if (
|
|
2337
|
+
if (setCookie) {
|
|
2338
|
+
headers.delete(name);
|
|
2339
|
+
for (const cookie of prevCookies) headers.append(name, cookie);
|
|
2340
|
+
} else if (prev === null) headers.delete(name);else headers.set(name, prev);
|
|
1929
2341
|
});
|
|
1930
2342
|
}
|
|
1931
2343
|
}
|
|
@@ -1990,7 +2402,6 @@ Object.defineProperty(exports, "untrack", {
|
|
|
1990
2402
|
enumerable: true,
|
|
1991
2403
|
get: function () { return solidJs.untrack; }
|
|
1992
2404
|
});
|
|
1993
|
-
exports.Assets = Assets;
|
|
1994
2405
|
exports.ChildProperties = ChildProperties;
|
|
1995
2406
|
exports.DOMElements = DOMElements;
|
|
1996
2407
|
exports.DOMWithState = DOMWithState;
|
|
@@ -2005,6 +2416,7 @@ exports.REVALIDATE_HEADER = REVALIDATE_HEADER;
|
|
|
2005
2416
|
exports.RawTextElements = RawTextElements;
|
|
2006
2417
|
exports.RequestContext = RequestContext;
|
|
2007
2418
|
exports.ResponseEnvelope = ResponseEnvelope;
|
|
2419
|
+
exports.SAFE_ERROR = SAFE_ERROR;
|
|
2008
2420
|
exports.SVGElements = SVGElements;
|
|
2009
2421
|
exports.VoidElements = VoidElements;
|
|
2010
2422
|
exports.acquireAsset = notSup;
|
|
@@ -2015,14 +2427,20 @@ exports.claimElement = claimElement;
|
|
|
2015
2427
|
exports.claimElementTree = claimElementTree;
|
|
2016
2428
|
exports.className = notSup;
|
|
2017
2429
|
exports.clientOnly = clientOnly;
|
|
2430
|
+
exports.commitEventResponse = commitEventResponse;
|
|
2431
|
+
exports.commitResponseStub = commitResponseStub;
|
|
2432
|
+
exports.composeMiddleware = composeMiddleware;
|
|
2433
|
+
exports.createRequestEvent = createRequestEvent;
|
|
2434
|
+
exports.createResponseStub = createResponseStub;
|
|
2435
|
+
exports.createSSRResponse = createSSRResponse;
|
|
2018
2436
|
exports.delegateEvents = notSup;
|
|
2019
2437
|
exports.dynamic = dynamic;
|
|
2020
2438
|
exports.dynamicProperty = notSup;
|
|
2021
2439
|
exports.effect = effect;
|
|
2022
2440
|
exports.escape = escape;
|
|
2023
2441
|
exports.generateHydrationScript = generateHydrationScript;
|
|
2024
|
-
exports.getAssets = getAssets;
|
|
2025
2442
|
exports.getDelegatedRoot = notSup;
|
|
2443
|
+
exports.getExpectedRedirectStatus = getExpectedRedirectStatus;
|
|
2026
2444
|
exports.getHydrationKey = getHydrationKey;
|
|
2027
2445
|
exports.getNextElement = notSup;
|
|
2028
2446
|
exports.getNextMarker = notSup;
|
|
@@ -2035,8 +2453,11 @@ exports.insert = notSup;
|
|
|
2035
2453
|
exports.isDev = isDev;
|
|
2036
2454
|
exports.isHref = isHref;
|
|
2037
2455
|
exports.isResponseEnvelope = isResponseEnvelope;
|
|
2456
|
+
exports.isSafeError = isSafeError;
|
|
2038
2457
|
exports.isServer = isServer;
|
|
2458
|
+
exports.markSafeError = markSafeError;
|
|
2039
2459
|
exports.memo = memo;
|
|
2460
|
+
exports.parseCookieHeader = parseCookieHeader;
|
|
2040
2461
|
exports.redirect = redirect;
|
|
2041
2462
|
exports.ref = notSup;
|
|
2042
2463
|
exports.registerDelegatedContainer = notSup;
|
|
@@ -2046,9 +2467,9 @@ exports.reload = reload;
|
|
|
2046
2467
|
exports.render = notSup;
|
|
2047
2468
|
exports.renderToStream = renderToStream;
|
|
2048
2469
|
exports.renderToString = renderToString;
|
|
2049
|
-
exports.renderToStringAsync = renderToStringAsync;
|
|
2050
2470
|
exports.respond = respond;
|
|
2051
2471
|
exports.runHydrationEvents = notSup;
|
|
2472
|
+
exports.serializeCookie = serializeCookie;
|
|
2052
2473
|
exports.setAttribute = notSup;
|
|
2053
2474
|
exports.setAttributeNS = notSup;
|
|
2054
2475
|
exports.setProperty = notSup;
|
|
@@ -2066,5 +2487,4 @@ exports.style = notSup;
|
|
|
2066
2487
|
exports.template = notSup;
|
|
2067
2488
|
exports.unregisterDelegatedContainer = notSup;
|
|
2068
2489
|
exports.unregisterDelegatedRoot = notSup;
|
|
2069
|
-
exports.useAssets = useAssets;
|
|
2070
2490
|
exports.useHead = useHead;
|