@sveltejs/kit 3.0.0-next.1 → 3.0.0-next.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.
Files changed (144) hide show
  1. package/package.json +33 -21
  2. package/src/constants.js +2 -0
  3. package/src/core/adapt/builder.js +32 -49
  4. package/src/core/adapt/index.js +1 -4
  5. package/src/core/config/index.js +137 -71
  6. package/src/core/config/options.js +236 -244
  7. package/src/core/config/types.d.ts +1 -1
  8. package/src/core/env.js +121 -5
  9. package/src/core/generate_manifest/index.js +12 -15
  10. package/src/core/postbuild/analyse.js +7 -19
  11. package/src/core/postbuild/crawl.js +22 -6
  12. package/src/core/postbuild/fallback.js +2 -1
  13. package/src/core/postbuild/prerender.js +114 -48
  14. package/src/core/postbuild/queue.js +2 -1
  15. package/src/core/sync/create_manifest_data/index.js +53 -50
  16. package/src/core/sync/sync.js +0 -2
  17. package/src/core/sync/write_client_manifest.js +8 -15
  18. package/src/core/sync/write_env.js +2 -1
  19. package/src/core/sync/write_non_ambient.js +12 -9
  20. package/src/core/sync/write_server.js +14 -15
  21. package/src/core/sync/write_tsconfig.js +16 -8
  22. package/src/core/sync/write_tsconfig_test/package.json +7 -0
  23. package/src/core/sync/write_types/index.js +28 -24
  24. package/src/core/utils.js +30 -5
  25. package/src/exports/env/index.js +77 -0
  26. package/src/exports/hooks/index.js +3 -9
  27. package/src/exports/hooks/sequence.js +3 -2
  28. package/src/exports/index.js +35 -13
  29. package/src/exports/internal/client.js +5 -0
  30. package/src/exports/internal/env.js +8 -5
  31. package/src/exports/internal/index.js +1 -90
  32. package/src/exports/internal/{event.js → server/event.js} +1 -2
  33. package/src/exports/internal/server/index.js +33 -0
  34. package/src/exports/internal/shared.js +89 -0
  35. package/src/exports/node/index.js +62 -15
  36. package/src/exports/params.js +68 -0
  37. package/src/exports/public.d.ts +363 -189
  38. package/src/exports/url.js +86 -0
  39. package/src/exports/vite/build/build_server.js +53 -59
  40. package/src/exports/vite/build/remote.js +18 -11
  41. package/src/exports/vite/build/utils.js +0 -8
  42. package/src/exports/vite/dev/index.js +92 -50
  43. package/src/exports/vite/index.js +903 -681
  44. package/src/exports/vite/module_ids.js +0 -2
  45. package/src/exports/vite/preview/index.js +32 -24
  46. package/src/exports/vite/static_analysis/index.js +2 -4
  47. package/src/exports/vite/static_analysis/types.d.ts +14 -0
  48. package/src/exports/vite/utils.js +40 -35
  49. package/src/runtime/app/env/internal.js +4 -4
  50. package/src/runtime/app/env/types.d.ts +1 -1
  51. package/src/runtime/app/environment/index.js +3 -3
  52. package/src/runtime/app/forms.js +24 -7
  53. package/src/runtime/app/paths/client.js +4 -10
  54. package/src/runtime/app/paths/internal/client.js +4 -2
  55. package/src/runtime/app/paths/internal/server.js +2 -23
  56. package/src/runtime/app/paths/public.d.ts +0 -28
  57. package/src/runtime/app/paths/server.js +10 -6
  58. package/src/runtime/app/server/index.js +1 -1
  59. package/src/runtime/app/server/remote/command.js +0 -3
  60. package/src/runtime/app/server/remote/form.js +27 -15
  61. package/src/runtime/app/server/remote/prerender.js +29 -36
  62. package/src/runtime/app/server/remote/query.js +101 -99
  63. package/src/runtime/app/server/remote/requested.js +22 -14
  64. package/src/runtime/app/server/remote/shared.js +30 -26
  65. package/src/runtime/app/state/client.js +1 -2
  66. package/src/runtime/app/stores.js +13 -76
  67. package/src/runtime/client/bundle.js +1 -1
  68. package/src/runtime/client/client-entry.js +3 -0
  69. package/src/runtime/client/client.js +411 -318
  70. package/src/runtime/client/entry.js +24 -3
  71. package/src/runtime/client/fetcher.js +3 -2
  72. package/src/runtime/client/ndjson.js +6 -33
  73. package/src/runtime/client/payload.js +17 -0
  74. package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
  75. package/src/runtime/client/remote-functions/command.svelte.js +7 -32
  76. package/src/runtime/client/remote-functions/form.svelte.js +183 -112
  77. package/src/runtime/client/remote-functions/prerender.svelte.js +29 -8
  78. package/src/runtime/client/remote-functions/query/index.js +7 -14
  79. package/src/runtime/client/remote-functions/query/instance.svelte.js +63 -18
  80. package/src/runtime/client/remote-functions/query/proxy.js +3 -3
  81. package/src/runtime/client/remote-functions/query-batch.svelte.js +60 -68
  82. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +60 -18
  83. package/src/runtime/client/remote-functions/query-live/iterator.js +36 -55
  84. package/src/runtime/client/remote-functions/shared.svelte.js +88 -62
  85. package/src/runtime/client/sse.js +32 -0
  86. package/src/runtime/client/state.svelte.js +65 -49
  87. package/src/runtime/client/stream.js +39 -0
  88. package/src/runtime/client/types.d.ts +11 -7
  89. package/src/runtime/client/utils.js +0 -96
  90. package/src/runtime/components/root.svelte +66 -0
  91. package/src/runtime/env/dynamic/private.js +7 -0
  92. package/src/runtime/env/dynamic/public.js +7 -0
  93. package/src/runtime/env/static/private.js +6 -0
  94. package/src/runtime/env/static/public.js +6 -0
  95. package/src/runtime/form-utils.js +100 -22
  96. package/src/runtime/server/cookie.js +69 -52
  97. package/src/runtime/server/csrf.js +65 -0
  98. package/src/runtime/server/data/index.js +15 -19
  99. package/src/runtime/server/env_module.js +0 -5
  100. package/src/runtime/server/errors.js +135 -0
  101. package/src/runtime/server/fetch.js +1 -1
  102. package/src/runtime/server/index.js +22 -12
  103. package/src/runtime/server/internal.js +25 -0
  104. package/src/runtime/server/page/actions.js +43 -27
  105. package/src/runtime/server/page/data_serializer.js +10 -10
  106. package/src/runtime/server/page/index.js +12 -17
  107. package/src/runtime/server/page/load_data.js +2 -2
  108. package/src/runtime/server/page/render.js +114 -193
  109. package/src/runtime/server/page/respond_with_error.js +11 -11
  110. package/src/runtime/server/page/server_routing.js +27 -18
  111. package/src/runtime/server/remote-functions.js +596 -0
  112. package/src/runtime/server/respond.js +100 -68
  113. package/src/runtime/server/sourcemaps.js +183 -0
  114. package/src/runtime/server/utils.js +2 -134
  115. package/src/runtime/shared.js +83 -13
  116. package/src/runtime/telemetry/otel.js +1 -1
  117. package/src/runtime/types.d.ts +8 -0
  118. package/src/types/ambient-private.d.ts +2 -0
  119. package/src/types/ambient.d.ts +10 -5
  120. package/src/types/global-private.d.ts +13 -25
  121. package/src/types/internal.d.ts +95 -80
  122. package/src/types/private.d.ts +41 -1
  123. package/src/utils/error.js +24 -4
  124. package/src/utils/escape.js +9 -25
  125. package/src/utils/features.js +1 -1
  126. package/src/utils/fork.js +7 -2
  127. package/src/utils/import.js +6 -1
  128. package/src/utils/imports.js +83 -0
  129. package/src/utils/mime.js +9 -0
  130. package/src/utils/page_nodes.js +3 -5
  131. package/src/utils/params.js +66 -0
  132. package/src/utils/routing.js +90 -44
  133. package/src/utils/shared-iterator.js +5 -0
  134. package/src/utils/streaming.js +14 -4
  135. package/src/utils/url.js +20 -2
  136. package/src/version.js +1 -1
  137. package/types/index.d.ts +537 -557
  138. package/types/index.d.ts.map +24 -39
  139. package/src/core/sync/write_root.js +0 -148
  140. package/src/exports/internal/server.js +0 -22
  141. package/src/runtime/server/remote.js +0 -457
  142. package/src/runtime/shared-server.js +0 -7
  143. package/src/types/synthetic/$lib.md +0 -5
  144. /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
@@ -0,0 +1,135 @@
1
+ import { json, text } from '@sveltejs/kit';
2
+ import { HttpError, SvelteKitError } from '@sveltejs/kit/internal';
3
+ import { with_request_store } from '@sveltejs/kit/internal/server';
4
+ import { coalesce_to_error, get_message, get_status } from '../../utils/error.js';
5
+ import { negotiate } from '../../utils/http.js';
6
+ import { fix_stack_trace } from './internal.js';
7
+ import { escape_html } from '../../utils/escape.js';
8
+
9
+ /**
10
+ * @param {import('@sveltejs/kit').RequestEvent} event
11
+ * @param {import('types').RequestState} state
12
+ * @param {import('types').SSROptions} options
13
+ * @param {unknown} error
14
+ */
15
+ export async function handle_fatal_error(event, state, options, error) {
16
+ error = error instanceof HttpError ? error : coalesce_to_error(error);
17
+ const body = await handle_error_and_jsonify(event, state, options, error);
18
+ const status = body.status;
19
+
20
+ // ideally we'd use sec-fetch-dest instead, but Safari — quelle surprise — doesn't support it
21
+ const type = negotiate(event.request.headers.get('accept') || 'text/html', [
22
+ 'application/json',
23
+ 'text/html'
24
+ ]);
25
+
26
+ if (event.isDataRequest || type === 'application/json') {
27
+ return json(body, {
28
+ status
29
+ });
30
+ }
31
+
32
+ return static_error_page(options, status, body.message);
33
+ }
34
+
35
+ /**
36
+ * @param {import('@sveltejs/kit').RequestEvent} event
37
+ * @param {import('types').RequestState} state
38
+ * @param {import('types').SSROptions} options
39
+ * @param {any} error
40
+ * @returns {App.Error | Promise<App.Error>}
41
+ */
42
+ export function handle_error_and_jsonify(event, state, options, error) {
43
+ if (error instanceof HttpError) {
44
+ // @ts-expect-error custom user errors may not have a message field if App.Error is overwritten
45
+ return { message: 'Unknown Error', ...error.body };
46
+ }
47
+
48
+ let e = error;
49
+ while (e instanceof Error) {
50
+ fix_stack_trace(e);
51
+ e = e.cause;
52
+ }
53
+
54
+ const status = get_status(error);
55
+ const message = get_message(error);
56
+
57
+ // TODO 4.0 await this, rather than handling the non-Promise case
58
+ let result;
59
+ try {
60
+ result = with_request_store({ event, state }, () =>
61
+ options.hooks.handleError({ error, event, status, message })
62
+ ) ?? { status, message };
63
+ } catch (hook_error) {
64
+ log_handle_error_hook_failure(error, hook_error);
65
+ return { status, message: 'Internal Error' };
66
+ }
67
+
68
+ if (result instanceof Promise) {
69
+ if (!__SVELTEKIT_SUPPORTS_ASYNC__ && state.is_in_render) {
70
+ console.warn(
71
+ `To use an async \`handleError\` hook to handle errors that occur during rendering, you must enable \`compilerOptions.experimental.async\` in the SvelteKit plugin of your Vite config. The returned error has been replaced with a generic object`
72
+ );
73
+
74
+ // we're discarding the result, but we still need to prevent an unhandled
75
+ // rejection if the user's async `handleError` hook rejects
76
+ result.catch((hook_error) => log_handle_error_hook_failure(error, hook_error));
77
+
78
+ return {
79
+ status,
80
+ message: 'Internal Error'
81
+ };
82
+ }
83
+
84
+ return result.then(
85
+ (body) => {
86
+ body ??= { status, message };
87
+ return { ...body, status: get_status(body, error) };
88
+ },
89
+ (hook_error) => {
90
+ log_handle_error_hook_failure(error, hook_error);
91
+ return { status, message: 'Internal Error' };
92
+ }
93
+ );
94
+ }
95
+
96
+ return { ...result, status: get_status(result, error) };
97
+ }
98
+
99
+ /**
100
+ * @param {unknown} error
101
+ * @param {unknown} hook_error
102
+ */
103
+ function log_handle_error_hook_failure(error, hook_error) {
104
+ const failure = new Error('The `handleError` hook failed', {
105
+ cause: coalesce_to_error(hook_error)
106
+ });
107
+ failure.stack = failure.message;
108
+ console.error(failure);
109
+ if (error instanceof SvelteKitError) {
110
+ console.error(`Original error: ${error.status} ${error.text}: ${error.message}`);
111
+ } else {
112
+ console.error('Original error:', error);
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Return as a response that renders the error.html
118
+ *
119
+ * @param {import('types').SSROptions} options
120
+ * @param {number} status
121
+ * @param {string} message
122
+ */
123
+ export function static_error_page(options, status, message) {
124
+ let page = options.templates.error({ status, message: escape_html(message) });
125
+
126
+ if (__SVELTEKIT_DEV__) {
127
+ // inject Vite HMR client, for easier debugging
128
+ page = page.replace('</head>', '<script type="module" src="/@vite/client"></script></head>');
129
+ }
130
+
131
+ return text(page, {
132
+ headers: { 'content-type': 'text/html; charset=utf-8' },
133
+ status
134
+ });
135
+ }
@@ -2,7 +2,7 @@ import { parseSetCookie } from 'cookie';
2
2
  import { noop } from '../../utils/functions.js';
3
3
  import { respond } from './respond.js';
4
4
  import * as paths from '$app/paths/internal/server';
5
- import { read_implementation } from '__sveltekit/server';
5
+ import { read_implementation } from './internal.js';
6
6
  import { has_prerendered_path } from './utils.js';
7
7
 
8
8
  /**
@@ -2,10 +2,10 @@ import { noop } from '../../utils/functions.js';
2
2
  import { IN_WEBCONTAINER } from './constants.js';
3
3
  import { respond } from './respond.js';
4
4
  import { options, get_hooks } from '__SERVER__/internal.js';
5
- import { format_server_error } from './utils.js';
6
- import { set_read_implementation, set_manifest } from '__sveltekit/server';
5
+ import { set_read_implementation, set_manifest } from './internal.js';
7
6
  import { set_env } from '__sveltekit/env';
8
7
  import { set_app } from './app.js';
8
+ import { SvelteKitError } from '@sveltejs/kit/internal';
9
9
 
10
10
  /** @type {Promise<any>} */
11
11
  let init_promise;
@@ -27,7 +27,7 @@ export class Server {
27
27
  this.#manifest = manifest;
28
28
 
29
29
  // Since AsyncLocalStorage is not working in webcontainers, we don't reset `sync_store`
30
- // in `src/exports/internal/event.js` and handle only one request at a time.
30
+ // in `src/exports/internal/server/event.js` and handle only one request at a time.
31
31
  if (IN_WEBCONTAINER) {
32
32
  const respond = this.respond.bind(this);
33
33
 
@@ -107,20 +107,30 @@ export class Server {
107
107
  handle: module.handle || (({ event, resolve }) => resolve(event)),
108
108
  handleError:
109
109
  module.handleError ||
110
- (({ status, error, event }) => {
111
- const error_message = format_server_error(
112
- status,
113
- /** @type {Error} */ (error),
114
- event
115
- );
116
- console.error(error_message);
110
+ (({ error }) => {
111
+ if (error instanceof SvelteKitError) {
112
+ // don't log stack traces for 404s etc, it's all internal gubbins
113
+ return;
114
+ }
115
+
116
+ let e = error;
117
+ while (e instanceof Error) {
118
+ if (e.stack) {
119
+ console.error(e.stack);
120
+ }
121
+ e = e.cause;
122
+ }
123
+
124
+ if (e) {
125
+ console.error(String(e));
126
+ }
117
127
  }),
118
128
  handleFetch: module.handleFetch || (({ request, fetch }) => fetch(request)),
119
129
  handleValidationError:
120
130
  module.handleValidationError ||
121
131
  (({ issues }) => {
122
132
  console.error('Remote function schema validation failed:', issues);
123
- return { message: 'Bad Request' };
133
+ return { message: 'Bad Request', status: 400 };
124
134
  }),
125
135
  reroute: module.reroute || noop,
126
136
  transport: module.transport || {}
@@ -164,7 +174,7 @@ export class Server {
164
174
  * @param {Request} request
165
175
  * @param {import('types').RequestOptions} options
166
176
  */
167
- async respond(request, options) {
177
+ respond(request, options) {
168
178
  return respond(request, this.#options, this.#manifest, {
169
179
  ...options,
170
180
  error: false,
@@ -0,0 +1,25 @@
1
+ /** @import { SSRManifest } from '@sveltejs/kit'; */
2
+
3
+ /**
4
+ * @type {((path: string) => ReadableStream<any>) | null}
5
+ */
6
+ export let read_implementation = null;
7
+
8
+ export let manifest = /** @type {SSRManifest} */ (/** @type {unknown} */ (null));
9
+
10
+ /**
11
+ * @param {(path: string) => ReadableStream<any>} fn
12
+ */
13
+ export function set_read_implementation(fn) {
14
+ read_implementation = fn;
15
+ }
16
+
17
+ /**
18
+ *
19
+ * @param {SSRManifest} value
20
+ */
21
+ export function set_manifest(value) {
22
+ manifest = value;
23
+ }
24
+
25
+ export { fix_stack_trace, set_fix_stack_trace } from './sourcemaps.js';
@@ -5,9 +5,10 @@ import { DEV } from 'esm-env';
5
5
  import { json } from '@sveltejs/kit';
6
6
  import { HttpError, Redirect, ActionFailure, SvelteKitError } from '@sveltejs/kit/internal';
7
7
  import { with_request_store, merge_tracing } from '@sveltejs/kit/internal/server';
8
- import { get_status, normalize_error } from '../../../utils/error.js';
8
+ import { normalize_error } from '../../../utils/error.js';
9
9
  import { is_form_content_type, negotiate } from '../../../utils/http.js';
10
- import { create_replacer, handle_error_and_jsonify } from '../utils.js';
10
+ import { create_replacer } from '../utils.js';
11
+ import { handle_error_and_jsonify } from '../errors.js';
11
12
  import { record_span } from '../../telemetry/record_span.js';
12
13
 
13
14
  /** @param {RequestEvent} event */
@@ -36,13 +37,15 @@ export async function handle_action_json_request(event, event_state, options, se
36
37
  `POST method not allowed. No form actions exist for ${DEV ? `the page at ${event.route.id}` : 'this page'}`
37
38
  );
38
39
 
40
+ const error = await handle_error_and_jsonify(event, event_state, options, no_actions_error);
41
+
39
42
  return action_json(
40
43
  {
41
44
  type: 'error',
42
- error: await handle_error_and_jsonify(event, event_state, options, no_actions_error)
45
+ error
43
46
  },
44
47
  {
45
- status: no_actions_error.status,
48
+ status: error.status,
46
49
  headers: {
47
50
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
48
51
  // "The server must generate an Allow header field in a 405 status code response"
@@ -62,22 +65,27 @@ export async function handle_action_json_request(event, event_state, options, se
62
65
  }
63
66
 
64
67
  if (data instanceof ActionFailure) {
65
- return action_json({
66
- type: 'failure',
67
- status: data.status,
68
- // @ts-expect-error we assign a string to what is supposed to be an object. That's ok
69
- // because we don't use the object outside, and this way we have better code navigation
70
- // through knowing where the related interface is used.
71
- data: stringify_action_response(
72
- data.data,
73
- /** @type {string} */ (event.route.id),
74
- options.hooks.transport
75
- )
76
- });
77
- } else {
68
+ return action_json(
69
+ {
70
+ type: 'failure',
71
+ status: data.status,
72
+ // @ts-expect-error we assign a string to what is supposed to be an object. That's ok
73
+ // because we don't use the object outside, and this way we have better code navigation
74
+ // through knowing where the related interface is used.
75
+ data: stringify_action_response(
76
+ data.data,
77
+ /** @type {string} */ (event.route.id),
78
+ options.hooks.transport
79
+ )
80
+ },
81
+ {
82
+ status: data.status
83
+ }
84
+ );
85
+ } else if (data) {
78
86
  return action_json({
79
87
  type: 'success',
80
- status: data ? 200 : 204,
88
+ status: 200,
81
89
  // @ts-expect-error see comment above
82
90
  data: stringify_action_response(
83
91
  data,
@@ -85,6 +93,9 @@ export async function handle_action_json_request(event, event_state, options, se
85
93
  options.hooks.transport
86
94
  )
87
95
  });
96
+ } else {
97
+ // no data returned — use 204 No Content (without a body, per the spec)
98
+ return new Response(null, { status: 204 });
88
99
  }
89
100
  } catch (e) {
90
101
  const err = normalize_error(e);
@@ -93,18 +104,20 @@ export async function handle_action_json_request(event, event_state, options, se
93
104
  return action_json_redirect(err);
94
105
  }
95
106
 
107
+ const transformed = await handle_error_and_jsonify(
108
+ event,
109
+ event_state,
110
+ options,
111
+ check_incorrect_fail_use(err)
112
+ );
113
+
96
114
  return action_json(
97
115
  {
98
116
  type: 'error',
99
- error: await handle_error_and_jsonify(
100
- event,
101
- event_state,
102
- options,
103
- check_incorrect_fail_use(err)
104
- )
117
+ error: transformed
105
118
  },
106
119
  {
107
- status: get_status(err)
120
+ status: transformed.status
108
121
  }
109
122
  );
110
123
  }
@@ -163,6 +176,7 @@ export async function handle_action_request(event, event_state, server) {
163
176
  });
164
177
  return {
165
178
  type: 'error',
179
+ // We're lying a bit with the types here; this will be transformed into a proper App.Error object later
166
180
  error: new SvelteKitError(
167
181
  405,
168
182
  'Method Not Allowed',
@@ -207,6 +221,7 @@ export async function handle_action_request(event, event_state, server) {
207
221
 
208
222
  return {
209
223
  type: 'error',
224
+ // @ts-expect-error We're lying a bit with the types here; this will be transformed into a proper App.Error object later
210
225
  error: check_incorrect_fail_use(err)
211
226
  };
212
227
  }
@@ -243,11 +258,12 @@ async function call_action(event, event_state, actions) {
243
258
  }
244
259
  }
245
260
 
246
- const action = actions[name];
247
- if (!action) {
261
+ if (!Object.hasOwn(actions, name)) {
248
262
  throw new SvelteKitError(404, 'Not Found', `No action with name '${name}' found`);
249
263
  }
250
264
 
265
+ const action = actions[name];
266
+
251
267
  if (!is_form_content_type(event.request)) {
252
268
  throw new SvelteKitError(
253
269
  415,
@@ -1,12 +1,8 @@
1
1
  import * as devalue from 'devalue';
2
2
  import { compact } from '../../../utils/array.js';
3
3
  import { create_async_iterator } from '../../../utils/streaming.js';
4
- import {
5
- clarify_devalue_error,
6
- get_global_name,
7
- handle_error_and_jsonify,
8
- serialize_uses
9
- } from '../utils.js';
4
+ import { clarify_devalue_error, get_global_name, serialize_uses } from '../utils.js';
5
+ import { handle_error_and_jsonify } from '../errors.js';
10
6
 
11
7
  /**
12
8
  * If the serialized data contains promises, `chunks` will be an
@@ -45,12 +41,14 @@ export function server_data_serializer(event, event_state, options) {
45
41
  let str;
46
42
  try {
47
43
  str = devalue.uneval(error ? [, error] : [data], replacer);
48
- } catch {
44
+ } catch (e) {
49
45
  error = await handle_error_and_jsonify(
50
46
  event,
51
47
  event_state,
52
48
  options,
53
- new Error(`Failed to serialize promise while rendering ${event.route.id}`)
49
+ new Error(`Failed to serialize promise while rendering ${event.route.id}`, {
50
+ cause: e
51
+ })
54
52
  );
55
53
  str = devalue.uneval([, error], replacer);
56
54
  }
@@ -164,12 +162,14 @@ export function server_data_serializer_json(event, event_state, options) {
164
162
  let str;
165
163
  try {
166
164
  str = devalue.stringify(value, reducers);
167
- } catch {
165
+ } catch (e) {
168
166
  const error = await handle_error_and_jsonify(
169
167
  event,
170
168
  event_state,
171
169
  options,
172
- new Error(`Failed to serialize promise while rendering ${event.route.id}`)
170
+ new Error(`Failed to serialize promise while rendering ${event.route.id}`, {
171
+ cause: e
172
+ })
173
173
  );
174
174
 
175
175
  key = 'error';
@@ -1,12 +1,14 @@
1
+ /** @import { Component } from 'svelte' */
1
2
  /** @import { ActionResult, RequestEvent, SSRManifest } from '@sveltejs/kit' */
2
- /** @import { PageNodeIndexes, RequestState, RequiredResolveOptions, ServerDataNode, SSRComponent, SSRNode, SSROptions, SSRState } from 'types' */
3
+ /** @import { PageNodeIndexes, RequestState, RequiredResolveOptions, ServerDataNode, SSRNode, SSROptions, SSRState } from 'types' */
3
4
  import { text } from '@sveltejs/kit';
4
5
  import { HttpError, Redirect } from '@sveltejs/kit/internal';
5
6
  import { compact } from '../../../utils/array.js';
6
7
  import { get_status, normalize_error } from '../../../utils/error.js';
7
8
  import { noop } from '../../../utils/functions.js';
8
9
  import { add_data_suffix } from '../../pathname.js';
9
- import { redirect_response, static_error_page, handle_error_and_jsonify } from '../utils.js';
10
+ import { redirect_response } from '../utils.js';
11
+ import { static_error_page, handle_error_and_jsonify } from '../errors.js';
10
12
  import {
11
13
  handle_action_json_request,
12
14
  handle_action_request,
@@ -18,7 +20,7 @@ import { load_data, load_server_data } from './load_data.js';
18
20
  import { render_response } from './render.js';
19
21
  import { respond_with_error } from './respond_with_error.js';
20
22
  import { DEV } from 'esm-env';
21
- import { get_remote_action, handle_remote_form_post } from '../remote.js';
23
+ import { get_remote_action, handle_remote_form_post } from '../remote-functions.js';
22
24
  import { PageNodes } from '../../../utils/page_nodes.js';
23
25
 
24
26
  /**
@@ -269,6 +271,7 @@ export async function render_page(
269
271
  if (state.prerendering && should_prerender_data) {
270
272
  const body = JSON.stringify({
271
273
  type: 'redirect',
274
+ status: err.status,
272
275
  location: err.location
273
276
  });
274
277
 
@@ -281,8 +284,8 @@ export async function render_page(
281
284
  return redirect_response(err.status, err.location);
282
285
  }
283
286
 
284
- const status = get_status(err);
285
287
  const error = await handle_error_and_jsonify(event, event_state, options, err);
288
+ const status = error.status;
286
289
 
287
290
  while (i--) {
288
291
  if (page.errors[i]) {
@@ -315,13 +318,7 @@ export async function render_page(
315
318
  },
316
319
  status,
317
320
  error,
318
- error_components: await load_error_components(
319
- options,
320
- ssr,
321
- error_branch,
322
- page,
323
- manifest
324
- ),
321
+ error_components: await load_error_components(ssr, error_branch, page, manifest),
325
322
  branch: error_branch,
326
323
  fetched,
327
324
  data_serializer
@@ -373,7 +370,7 @@ export async function render_page(
373
370
  action_result,
374
371
  fetched,
375
372
  data_serializer: !ssr ? server_data_serializer(event, event_state, options) : data_serializer,
376
- error_components: await load_error_components(options, ssr, branch, page, manifest)
373
+ error_components: await load_error_components(ssr, branch, page, manifest)
377
374
  });
378
375
  } catch (e) {
379
376
  // a remote function could have thrown a redirect during render
@@ -397,18 +394,16 @@ export async function render_page(
397
394
  }
398
395
 
399
396
  /**
400
- *
401
- * @param {SSROptions} options
402
397
  * @param {boolean} ssr
403
398
  * @param {Array<import('./types.js').Loaded | null>} branch
404
399
  * @param {PageNodeIndexes} page
405
400
  * @param {SSRManifest} manifest
406
401
  */
407
- async function load_error_components(options, ssr, branch, page, manifest) {
408
- /** @type {Array<SSRComponent | undefined> | undefined} */
402
+ async function load_error_components(ssr, branch, page, manifest) {
403
+ /** @type {Array<Component | undefined> | undefined} */
409
404
  let error_components;
410
405
 
411
- if (options.server_error_boundaries && ssr) {
406
+ if (ssr) {
412
407
  let last_idx = -1;
413
408
  error_components = await Promise.all(
414
409
  // eslint-disable-next-line @typescript-eslint/await-thenable
@@ -377,7 +377,7 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
377
377
  }
378
378
 
379
379
  void push_fetched(base64_encode(result), true);
380
- })();
380
+ })().catch(noop); // prevent unhandled rejection potentially crashing the process
381
381
 
382
382
  return (teed_body = b);
383
383
  }
@@ -465,7 +465,7 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
465
465
  const included = resolve_opts.filterSerializedResponseHeaders(lower, value);
466
466
  if (!included) {
467
467
  throw new Error(
468
- `Failed to get response header "${lower}" — it must be included by the \`filterSerializedResponseHeaders\` option: https://svelte.dev/docs/kit/hooks#Server-hooks-handle (at ${event.route.id})`
468
+ `Failed to get response header "${lower}" — it must be included by the \`filterSerializedResponseHeaders\` option: https://svelte.dev/docs/kit/hooks#handle (at ${event.route.id})`
469
469
  );
470
470
  }
471
471
  }