@sveltejs/kit 1.0.9 → 1.0.11
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/package.json
CHANGED
|
@@ -105,7 +105,7 @@ function parent_element(element) {
|
|
|
105
105
|
*/
|
|
106
106
|
export function find_anchor(element, target) {
|
|
107
107
|
while (element && element !== target) {
|
|
108
|
-
if (element.nodeName.toUpperCase() === 'A') {
|
|
108
|
+
if (element.nodeName.toUpperCase() === 'A' && element.hasAttribute('href')) {
|
|
109
109
|
return /** @type {HTMLAnchorElement | SVGAElement} */ (element);
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -33,6 +33,12 @@ export async function load_server_data({ event, options, state, node, parent })
|
|
|
33
33
|
|
|
34
34
|
const result = await node.server.load?.call(null, {
|
|
35
35
|
...event,
|
|
36
|
+
fetch: (info, init) => {
|
|
37
|
+
const url = new URL(info instanceof Request ? info.url : info, event.url);
|
|
38
|
+
uses.dependencies.add(url.href);
|
|
39
|
+
|
|
40
|
+
return event.fetch(info, init);
|
|
41
|
+
},
|
|
36
42
|
/** @param {string[]} deps */
|
|
37
43
|
depends: (...deps) => {
|
|
38
44
|
for (const dep of deps) {
|
|
@@ -6,6 +6,7 @@ import { s } from '../../../utils/misc.js';
|
|
|
6
6
|
import { Csp } from './csp.js';
|
|
7
7
|
import { uneval_action_response } from './actions.js';
|
|
8
8
|
import { clarify_devalue_error } from '../utils.js';
|
|
9
|
+
import { DEV } from 'esm-env';
|
|
9
10
|
|
|
10
11
|
// TODO rename this function/module
|
|
11
12
|
|
|
@@ -353,17 +354,34 @@ export async function render_response({
|
|
|
353
354
|
// add the content after the script/css links so the link elements are parsed first
|
|
354
355
|
head += rendered.head;
|
|
355
356
|
|
|
357
|
+
const html = options.app_template({
|
|
358
|
+
head,
|
|
359
|
+
body,
|
|
360
|
+
assets,
|
|
361
|
+
nonce: /** @type {string} */ (csp.nonce)
|
|
362
|
+
});
|
|
363
|
+
|
|
356
364
|
// TODO flush chunks as early as we can
|
|
357
|
-
const
|
|
365
|
+
const transformed =
|
|
358
366
|
(await resolve_opts.transformPageChunk({
|
|
359
|
-
html
|
|
367
|
+
html,
|
|
360
368
|
done: true
|
|
361
369
|
})) || '';
|
|
362
370
|
|
|
371
|
+
if (DEV && page_config.csr) {
|
|
372
|
+
if (transformed.split('<!--').length < html.split('<!--').length) {
|
|
373
|
+
// the \u001B stuff is ANSI codes, so that we don't need to add a library to the runtime
|
|
374
|
+
// https://svelte.dev/repl/1b3f49696f0c44c881c34587f2537aa2
|
|
375
|
+
console.warn(
|
|
376
|
+
"\u001B[1m\u001B[31mRemoving comments in transformPageChunk can break Svelte's hydration\u001B[39m\u001B[22m"
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
363
381
|
const headers = new Headers({
|
|
364
382
|
'x-sveltekit-page': 'true',
|
|
365
383
|
'content-type': 'text/html',
|
|
366
|
-
etag: `"${hash(
|
|
384
|
+
etag: `"${hash(transformed)}"`
|
|
367
385
|
});
|
|
368
386
|
|
|
369
387
|
if (!state.prerendering) {
|
|
@@ -381,7 +399,7 @@ export async function render_response({
|
|
|
381
399
|
}
|
|
382
400
|
}
|
|
383
401
|
|
|
384
|
-
return new Response(
|
|
402
|
+
return new Response(transformed, {
|
|
385
403
|
status,
|
|
386
404
|
headers
|
|
387
405
|
});
|
|
@@ -46,6 +46,7 @@ export function serialize_data(fetched, filter, prerendering = false) {
|
|
|
46
46
|
|
|
47
47
|
let cache_control = null;
|
|
48
48
|
let age = null;
|
|
49
|
+
let vary = false;
|
|
49
50
|
|
|
50
51
|
for (const [key, value] of fetched.response.headers) {
|
|
51
52
|
if (filter(key, value)) {
|
|
@@ -54,6 +55,7 @@ export function serialize_data(fetched, filter, prerendering = false) {
|
|
|
54
55
|
|
|
55
56
|
if (key === 'cache-control') cache_control = value;
|
|
56
57
|
if (key === 'age') age = value;
|
|
58
|
+
if (key === 'vary') vary = true;
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
const payload = {
|
|
@@ -75,7 +77,11 @@ export function serialize_data(fetched, filter, prerendering = false) {
|
|
|
75
77
|
attrs.push(`data-hash=${escape_html_attr(hash(fetched.request_body))}`);
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
|
|
80
|
+
// Compute the time the response should be cached, taking into account max-age and age.
|
|
81
|
+
// Do not cache at all if a vary header is present, as this indicates that the cache is
|
|
82
|
+
// likely to get busted. It would also mean we'd have to add more logic to computing the
|
|
83
|
+
// selector on the client which results in more code for 99% of people for the 1% who use vary.
|
|
84
|
+
if (!prerendering && fetched.method === 'GET' && cache_control && !vary) {
|
|
79
85
|
const match = /s-maxage=(\d+)/g.exec(cache_control) ?? /max-age=(\d+)/g.exec(cache_control);
|
|
80
86
|
if (match) {
|
|
81
87
|
const ttl = +match[1] - +(age ?? '0');
|