@sveltejs/kit 1.0.0-next.502 → 1.0.0-next.504
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 +1 -1
- package/src/core/prerender/prerender.js +23 -0
- package/src/runtime/app/forms.js +6 -0
- package/src/runtime/client/client.js +10 -8
- package/src/runtime/server/endpoint.js +0 -1
- package/src/runtime/server/index.js +5 -0
- package/src/runtime/server/page/render.js +2 -1
- package/types/index.d.ts +25 -0
package/package.json
CHANGED
|
@@ -85,6 +85,9 @@ export async function prerender() {
|
|
|
85
85
|
/** @type {import('types').PrerenderMap} */
|
|
86
86
|
const prerender_map = new Map();
|
|
87
87
|
|
|
88
|
+
/** @type {Set<string>} */
|
|
89
|
+
const prerendered_routes = new Set();
|
|
90
|
+
|
|
88
91
|
/** @type {import('types').ValidatedKitConfig} */
|
|
89
92
|
const config = (await load_config()).kit;
|
|
90
93
|
|
|
@@ -302,6 +305,9 @@ export async function prerender() {
|
|
|
302
305
|
|
|
303
306
|
if (written.has(file)) return;
|
|
304
307
|
|
|
308
|
+
const route_id = response.headers.get('x-sveltekit-routeid');
|
|
309
|
+
if (route_id !== null) prerendered_routes.add(route_id);
|
|
310
|
+
|
|
305
311
|
if (response_type === REDIRECT) {
|
|
306
312
|
const location = headers['location'];
|
|
307
313
|
|
|
@@ -410,6 +416,23 @@ export async function prerender() {
|
|
|
410
416
|
|
|
411
417
|
await q.done();
|
|
412
418
|
|
|
419
|
+
/** @type {string[]} */
|
|
420
|
+
const not_prerendered = [];
|
|
421
|
+
|
|
422
|
+
for (const [route_id, prerender] of prerender_map) {
|
|
423
|
+
if (prerender === true && !prerendered_routes.has(route_id)) {
|
|
424
|
+
not_prerendered.push(route_id);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (not_prerendered.length > 0) {
|
|
429
|
+
throw new Error(
|
|
430
|
+
`The following routes were marked as prerenderable, but were not prerendered:\n${not_prerendered.map(
|
|
431
|
+
(id) => ` - ${id}`
|
|
432
|
+
)}\n\nSee https://kit.svelte.dev/docs/page-options#prerender-troubleshooting for more info`
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
|
|
413
436
|
const rendered = await server.respond(new Request(config.prerender.origin + '/[fallback]'), {
|
|
414
437
|
getClientAddress,
|
|
415
438
|
prerendering: {
|
package/src/runtime/app/forms.js
CHANGED
|
@@ -51,6 +51,12 @@ export function enhance(form, submit = () => {}) {
|
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
const data = new FormData(form);
|
|
54
|
+
|
|
55
|
+
const submitter_name = event.submitter?.getAttribute('name');
|
|
56
|
+
if (submitter_name) {
|
|
57
|
+
data.append(submitter_name, event.submitter?.getAttribute('value') ?? '');
|
|
58
|
+
}
|
|
59
|
+
|
|
54
60
|
const controller = new AbortController();
|
|
55
61
|
|
|
56
62
|
let cancelled = false;
|
|
@@ -438,7 +438,11 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
const page_changed =
|
|
441
|
-
!current.url ||
|
|
441
|
+
!current.url ||
|
|
442
|
+
url.href !== current.url.href ||
|
|
443
|
+
current.error !== error ||
|
|
444
|
+
form !== undefined ||
|
|
445
|
+
data_changed;
|
|
442
446
|
|
|
443
447
|
if (page_changed) {
|
|
444
448
|
result.props.page = {
|
|
@@ -447,6 +451,7 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
447
451
|
routeId: route && route.id,
|
|
448
452
|
status,
|
|
449
453
|
url,
|
|
454
|
+
form,
|
|
450
455
|
// The whole page store is updated, but this way the object reference stays the same
|
|
451
456
|
data: data_changed ? data : page.data
|
|
452
457
|
};
|
|
@@ -1203,13 +1208,10 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
1203
1208
|
goto(result.location, {}, []);
|
|
1204
1209
|
} else {
|
|
1205
1210
|
/** @type {Record<string, any>} */
|
|
1206
|
-
const props = {
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
props.page = page;
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1211
|
+
const props = {
|
|
1212
|
+
form: result.data,
|
|
1213
|
+
page: { ...page, form: result.data, status: result.status }
|
|
1214
|
+
};
|
|
1213
1215
|
const post_update = pre_update();
|
|
1214
1216
|
root.$set(props);
|
|
1215
1217
|
post_update();
|
|
@@ -296,6 +296,11 @@ export async function respond(request, options, state) {
|
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
add_cookies_to_headers(response.headers, Array.from(new_cookies.values()));
|
|
299
|
+
|
|
300
|
+
if (state.prerendering && event.routeId !== null) {
|
|
301
|
+
response.headers.set('x-sveltekit-routeid', event.routeId);
|
|
302
|
+
}
|
|
303
|
+
|
|
299
304
|
return response;
|
|
300
305
|
}),
|
|
301
306
|
// TODO remove for 1.0
|
package/types/index.d.ts
CHANGED
|
@@ -295,13 +295,38 @@ export interface Navigation {
|
|
|
295
295
|
delta?: number;
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
+
/**
|
|
299
|
+
* The shape of the `$page` store
|
|
300
|
+
*/
|
|
298
301
|
export interface Page<Params extends Record<string, string> = Record<string, string>> {
|
|
302
|
+
/**
|
|
303
|
+
* The URL of the current page
|
|
304
|
+
*/
|
|
299
305
|
url: URL;
|
|
306
|
+
/**
|
|
307
|
+
* The parameters of the current page - e.g. for a route like `/blog/[slug]`, the `slug` parameter
|
|
308
|
+
*/
|
|
300
309
|
params: Params;
|
|
310
|
+
/**
|
|
311
|
+
* The route ID of the current page - e.g. for `src/routes/blog/[slug]`, it would be `blog/[slug]`
|
|
312
|
+
*/
|
|
301
313
|
routeId: string | null;
|
|
314
|
+
/**
|
|
315
|
+
* Http status code of the current page
|
|
316
|
+
*/
|
|
302
317
|
status: number;
|
|
318
|
+
/**
|
|
319
|
+
* The error object of the current page, if any. Filled from the `handleError` hooks.
|
|
320
|
+
*/
|
|
303
321
|
error: App.Error | null;
|
|
322
|
+
/**
|
|
323
|
+
* The merged result of all data from all `load` functions on the current page. You can type a common denominator through `App.PageData`.
|
|
324
|
+
*/
|
|
304
325
|
data: App.PageData & Record<string, any>;
|
|
326
|
+
/**
|
|
327
|
+
* Filled only after a form submission. See [form actions](https://kit.svelte.dev/docs/form-actions) for more info.
|
|
328
|
+
*/
|
|
329
|
+
form: any;
|
|
305
330
|
}
|
|
306
331
|
|
|
307
332
|
export interface ParamMatcher {
|