@sveltejs/kit 1.0.11 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.11",
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.14.0"
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.0",
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 stack = /** @type {string} */ (new Error().stack);
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;
@@ -26,7 +26,7 @@ export interface Client {
26
26
  // private API
27
27
  _hydrate(opts: {
28
28
  status: number;
29
- error: App.Error;
29
+ error: App.Error | null;
30
30
  node_ids: number[];
31
31
  params: Record<string, string>;
32
32
  route: { id: string | null };
@@ -31,6 +31,8 @@ export async function render_data(
31
31
  });
32
32
  }
33
33
 
34
+ state.initiator = route;
35
+
34
36
  try {
35
37
  const node_ids = [...route.page.layouts, route.page.leaf];
36
38
  const invalidated = invalidated_data_nodes ?? node_ids.map(() => true);
@@ -158,7 +158,7 @@ export async function render_response({
158
158
  /** @param {string} path */
159
159
  const prefixed = (path) => (path.startsWith('/') ? path : `${assets}/${path}`);
160
160
 
161
- const serialized = { data: '', form: 'null' };
161
+ const serialized = { data: '', form: 'null', error: 'null' };
162
162
 
163
163
  try {
164
164
  serialized.data = `[${branch
@@ -196,6 +196,10 @@ export async function render_response({
196
196
  serialized.form = uneval_action_response(form_value, /** @type {string} */ (event.route.id));
197
197
  }
198
198
 
199
+ if (error) {
200
+ serialized.error = devalue.uneval(error);
201
+ }
202
+
199
203
  if (inline_styles.size > 0) {
200
204
  const content = Array.from(inline_styles.values()).join('\n');
201
205
 
@@ -256,17 +260,14 @@ export async function render_response({
256
260
  const hydrate = [
257
261
  `node_ids: [${branch.map(({ node }) => node.index).join(', ')}]`,
258
262
  `data: ${serialized.data}`,
259
- `form: ${serialized.form}`
263
+ `form: ${serialized.form}`,
264
+ `error: ${serialized.error}`
260
265
  ];
261
266
 
262
267
  if (status !== 200) {
263
268
  hydrate.push(`status: ${status}`);
264
269
  }
265
270
 
266
- if (error) {
267
- hydrate.push(`error: ${devalue.uneval(error)}`);
268
- }
269
-
270
271
  if (options.embedded) {
271
272
  hydrate.push(`params: ${devalue.uneval(event.params)}`, `route: ${s(event.route)}`);
272
273
  }
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://httpstatusdogs.com), in the range 400-599 */
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
- * return a redirect response.
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://httpstatusdogs.com), in the range 300-308. */
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
 
@@ -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;