@sveltejs/kit 1.0.10 → 1.0.12
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 +3 -3
- package/src/core/prerender/prerender.js +1 -1
- package/src/runtime/client/client.js +7 -1
- package/src/runtime/client/fetcher.js +12 -4
- package/src/runtime/client/types.d.ts +1 -1
- package/src/runtime/client/utils.js +1 -1
- package/src/runtime/server/data/index.js +2 -0
- package/src/runtime/server/page/load_data.js +6 -0
- package/src/runtime/server/page/render.js +29 -10
- package/types/index.d.ts +10 -5
- package/types/internal.d.ts +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"set-cookie-parser": "^2.5.1",
|
|
23
23
|
"sirv": "^2.0.2",
|
|
24
24
|
"tiny-glob": "^0.2.9",
|
|
25
|
-
"undici": "5.
|
|
25
|
+
"undici": "5.15.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@playwright/test": "^1.29.2",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@types/set-cookie-parser": "^2.4.2",
|
|
35
35
|
"marked": "^4.2.3",
|
|
36
36
|
"rollup": "^3.7.0",
|
|
37
|
-
"svelte": "^3.55.
|
|
37
|
+
"svelte": "^3.55.1",
|
|
38
38
|
"svelte-preprocess": "^5.0.0",
|
|
39
39
|
"typescript": "^4.9.4",
|
|
40
40
|
"uvu": "^0.5.6",
|
|
@@ -413,7 +413,7 @@ export async function prerender() {
|
|
|
413
413
|
// People can opt out of this behavior by explicitly setting prerender to false
|
|
414
414
|
(should_prerender !== false && get_option(nodes, 'ssr') === false && !page?.server?.actions
|
|
415
415
|
? 'auto'
|
|
416
|
-
: false);
|
|
416
|
+
: should_prerender ?? false);
|
|
417
417
|
|
|
418
418
|
prerender_map.set(route.id, prerender);
|
|
419
419
|
}
|
|
@@ -467,7 +467,7 @@ export function create_client({ target, base }) {
|
|
|
467
467
|
!current.url ||
|
|
468
468
|
url.href !== current.url.href ||
|
|
469
469
|
current.error !== error ||
|
|
470
|
-
form !== undefined ||
|
|
470
|
+
(form !== undefined && form !== page.form) ||
|
|
471
471
|
data_changed;
|
|
472
472
|
|
|
473
473
|
if (page_changed) {
|
|
@@ -824,6 +824,12 @@ export function create_client({ target, base }) {
|
|
|
824
824
|
status = err.status;
|
|
825
825
|
error = err.body;
|
|
826
826
|
} else {
|
|
827
|
+
// Referenced node could have been removed due to redeploy, check
|
|
828
|
+
const updated = await stores.updated.check();
|
|
829
|
+
if (updated) {
|
|
830
|
+
return await native_navigation(url);
|
|
831
|
+
}
|
|
832
|
+
|
|
827
833
|
error = await handle_error(err, { params, url, route: { id: route.id } });
|
|
828
834
|
}
|
|
829
835
|
|
|
@@ -24,12 +24,20 @@ if (DEV) {
|
|
|
24
24
|
check_stack_trace();
|
|
25
25
|
|
|
26
26
|
window.fetch = (input, init) => {
|
|
27
|
+
// Check if fetch was called via load_node. the lock method only checks if it was called at the
|
|
28
|
+
// same time, but not necessarily if it was called from `load`.
|
|
29
|
+
// We use just the filename as the method name sometimes does not appear on the CI.
|
|
27
30
|
const url = input instanceof Request ? input.url : input.toString();
|
|
28
|
-
const
|
|
31
|
+
const stack_array = /** @type {string} */ (new Error().stack).split('\n');
|
|
32
|
+
// We need to do some Firefox-specific cutoff because it (impressively) maintains the stack
|
|
33
|
+
// across events and for example traces a `fetch` call triggered from a button back
|
|
34
|
+
// to the creation of the event listener and the element creation itself,
|
|
35
|
+
// where at some point client.js will show up, leading to false positives.
|
|
36
|
+
const firefox_cutoff = stack_array.findIndex((a) => a.includes('*listen@'));
|
|
37
|
+
const stack = stack_array
|
|
38
|
+
.slice(0, firefox_cutoff !== -1 ? firefox_cutoff : undefined)
|
|
39
|
+
.join('\n');
|
|
29
40
|
|
|
30
|
-
// check if fetch was called via load_node. the lock method only checks if it was called at the
|
|
31
|
-
// same time, but not necessarily if it was called from `load`
|
|
32
|
-
// we use just the filename as the method name sometimes does not appear on the CI
|
|
33
41
|
const heuristic = can_inspect_stack_trace
|
|
34
42
|
? stack.includes('src/runtime/client/client.js')
|
|
35
43
|
: loading;
|
|
@@ -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
|
|
|
@@ -157,7 +158,7 @@ export async function render_response({
|
|
|
157
158
|
/** @param {string} path */
|
|
158
159
|
const prefixed = (path) => (path.startsWith('/') ? path : `${assets}/${path}`);
|
|
159
160
|
|
|
160
|
-
const serialized = { data: '', form: 'null' };
|
|
161
|
+
const serialized = { data: '', form: 'null', error: 'null' };
|
|
161
162
|
|
|
162
163
|
try {
|
|
163
164
|
serialized.data = `[${branch
|
|
@@ -195,6 +196,10 @@ export async function render_response({
|
|
|
195
196
|
serialized.form = uneval_action_response(form_value, /** @type {string} */ (event.route.id));
|
|
196
197
|
}
|
|
197
198
|
|
|
199
|
+
if (error) {
|
|
200
|
+
serialized.error = devalue.uneval(error);
|
|
201
|
+
}
|
|
202
|
+
|
|
198
203
|
if (inline_styles.size > 0) {
|
|
199
204
|
const content = Array.from(inline_styles.values()).join('\n');
|
|
200
205
|
|
|
@@ -255,17 +260,14 @@ export async function render_response({
|
|
|
255
260
|
const hydrate = [
|
|
256
261
|
`node_ids: [${branch.map(({ node }) => node.index).join(', ')}]`,
|
|
257
262
|
`data: ${serialized.data}`,
|
|
258
|
-
`form: ${serialized.form}
|
|
263
|
+
`form: ${serialized.form}`,
|
|
264
|
+
`error: ${serialized.error}`
|
|
259
265
|
];
|
|
260
266
|
|
|
261
267
|
if (status !== 200) {
|
|
262
268
|
hydrate.push(`status: ${status}`);
|
|
263
269
|
}
|
|
264
270
|
|
|
265
|
-
if (error) {
|
|
266
|
-
hydrate.push(`error: ${devalue.uneval(error)}`);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
271
|
if (options.embedded) {
|
|
270
272
|
hydrate.push(`params: ${devalue.uneval(event.params)}`, `route: ${s(event.route)}`);
|
|
271
273
|
}
|
|
@@ -353,17 +355,34 @@ export async function render_response({
|
|
|
353
355
|
// add the content after the script/css links so the link elements are parsed first
|
|
354
356
|
head += rendered.head;
|
|
355
357
|
|
|
358
|
+
const html = options.app_template({
|
|
359
|
+
head,
|
|
360
|
+
body,
|
|
361
|
+
assets,
|
|
362
|
+
nonce: /** @type {string} */ (csp.nonce)
|
|
363
|
+
});
|
|
364
|
+
|
|
356
365
|
// TODO flush chunks as early as we can
|
|
357
|
-
const
|
|
366
|
+
const transformed =
|
|
358
367
|
(await resolve_opts.transformPageChunk({
|
|
359
|
-
html
|
|
368
|
+
html,
|
|
360
369
|
done: true
|
|
361
370
|
})) || '';
|
|
362
371
|
|
|
372
|
+
if (DEV && page_config.csr) {
|
|
373
|
+
if (transformed.split('<!--').length < html.split('<!--').length) {
|
|
374
|
+
// the \u001B stuff is ANSI codes, so that we don't need to add a library to the runtime
|
|
375
|
+
// https://svelte.dev/repl/1b3f49696f0c44c881c34587f2537aa2
|
|
376
|
+
console.warn(
|
|
377
|
+
"\u001B[1m\u001B[31mRemoving comments in transformPageChunk can break Svelte's hydration\u001B[39m\u001B[22m"
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
363
382
|
const headers = new Headers({
|
|
364
383
|
'x-sveltekit-page': 'true',
|
|
365
384
|
'content-type': 'text/html',
|
|
366
|
-
etag: `"${hash(
|
|
385
|
+
etag: `"${hash(transformed)}"`
|
|
367
386
|
});
|
|
368
387
|
|
|
369
388
|
if (!state.prerendering) {
|
|
@@ -381,7 +400,7 @@ export async function render_response({
|
|
|
381
400
|
}
|
|
382
401
|
}
|
|
383
402
|
|
|
384
|
-
return new Response(
|
|
403
|
+
return new Response(transformed, {
|
|
385
404
|
status,
|
|
386
405
|
headers
|
|
387
406
|
});
|
package/types/index.d.ts
CHANGED
|
@@ -1080,7 +1080,7 @@ export type ActionResult<
|
|
|
1080
1080
|
* Creates an `HttpError` object with an HTTP status code and an optional message.
|
|
1081
1081
|
* This object, if thrown during request handling, will cause SvelteKit to
|
|
1082
1082
|
* return an error response without invoking `handleError`
|
|
1083
|
-
* @param status The HTTP status code
|
|
1083
|
+
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
1084
1084
|
* @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
1085
1085
|
*/
|
|
1086
1086
|
export function error(status: number, body: App.Error): HttpError;
|
|
@@ -1094,15 +1094,16 @@ export function error(
|
|
|
1094
1094
|
* The object returned by the [`error`](https://kit.svelte.dev/docs/modules#sveltejs-kit-error) function.
|
|
1095
1095
|
*/
|
|
1096
1096
|
export interface HttpError {
|
|
1097
|
-
/** The [HTTP status code](https://
|
|
1097
|
+
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
|
|
1098
1098
|
status: number;
|
|
1099
1099
|
/** The content of the error. */
|
|
1100
1100
|
body: App.Error;
|
|
1101
1101
|
}
|
|
1102
1102
|
|
|
1103
1103
|
/**
|
|
1104
|
-
* Create a `Redirect` object. If thrown during request handling, SvelteKit will
|
|
1105
|
-
*
|
|
1104
|
+
* Create a `Redirect` object. If thrown during request handling, SvelteKit will return a redirect response.
|
|
1105
|
+
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308.
|
|
1106
|
+
* @param location The location to redirect to.
|
|
1106
1107
|
*/
|
|
1107
1108
|
export function redirect(
|
|
1108
1109
|
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308,
|
|
@@ -1113,7 +1114,7 @@ export function redirect(
|
|
|
1113
1114
|
* The object returned by the [`redirect`](https://kit.svelte.dev/docs/modules#sveltejs-kit-redirect) function
|
|
1114
1115
|
*/
|
|
1115
1116
|
export interface Redirect {
|
|
1116
|
-
/** The [HTTP status code](https://
|
|
1117
|
+
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages), in the range 300-308. */
|
|
1117
1118
|
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
|
|
1118
1119
|
/** The location to redirect to. */
|
|
1119
1120
|
location: string;
|
|
@@ -1128,6 +1129,8 @@ export function json(data: any, init?: ResponseInit): Response;
|
|
|
1128
1129
|
|
|
1129
1130
|
/**
|
|
1130
1131
|
* Create an `ActionFailure` object.
|
|
1132
|
+
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
1133
|
+
* @param data Data associated with the failure (e.g. validation errors)
|
|
1131
1134
|
*/
|
|
1132
1135
|
export function fail<T extends Record<string, unknown> | undefined>(
|
|
1133
1136
|
status: number,
|
|
@@ -1139,7 +1142,9 @@ export function fail<T extends Record<string, unknown> | undefined>(
|
|
|
1139
1142
|
*/
|
|
1140
1143
|
export interface ActionFailure<T extends Record<string, unknown> | undefined = undefined>
|
|
1141
1144
|
extends UniqueInterface {
|
|
1145
|
+
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
|
|
1142
1146
|
status: number;
|
|
1147
|
+
/** Data associated with the failure (e.g. validation errors) */
|
|
1143
1148
|
data: T;
|
|
1144
1149
|
}
|
|
1145
1150
|
|
package/types/internal.d.ts
CHANGED
|
@@ -383,11 +383,8 @@ export * from './private';
|
|
|
383
383
|
|
|
384
384
|
declare global {
|
|
385
385
|
const __SVELTEKIT_ADAPTER_NAME__: string;
|
|
386
|
-
const __SVELTEKIT_APP_VERSION__: string;
|
|
387
386
|
const __SVELTEKIT_APP_VERSION_FILE__: string;
|
|
388
387
|
const __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: number;
|
|
389
|
-
const __SVELTEKIT_BROWSER__: boolean;
|
|
390
|
-
const __SVELTEKIT_DEV__: boolean;
|
|
391
388
|
const __SVELTEKIT_EMBEDDED__: boolean;
|
|
392
389
|
var Bun: object;
|
|
393
390
|
var Deno: object;
|