@sveltejs/kit 2.20.4 → 2.20.6
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/exports/vite/index.js +13 -1
- package/src/runtime/app/server/event.js +2 -2
- package/src/runtime/server/data/index.js +3 -3
- package/src/runtime/server/page/render.js +6 -4
- package/src/runtime/server/utils.js +15 -10
- package/src/version.js +1 -1
- package/types/index.d.ts +1 -1
package/package.json
CHANGED
|
@@ -678,7 +678,19 @@ Tips:
|
|
|
678
678
|
manualChunks: split ? undefined : () => 'bundle',
|
|
679
679
|
inlineDynamicImports: false
|
|
680
680
|
},
|
|
681
|
-
preserveEntrySignatures: 'strict'
|
|
681
|
+
preserveEntrySignatures: 'strict',
|
|
682
|
+
onwarn(warning, handler) {
|
|
683
|
+
if (
|
|
684
|
+
warning.code === 'MISSING_EXPORT' &&
|
|
685
|
+
warning.id === `${kit.outDir}/generated/client-optimized/app.js`
|
|
686
|
+
) {
|
|
687
|
+
// ignore e.g. undefined `handleError` hook when
|
|
688
|
+
// referencing `client_hooks.handleError`
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
handler(warning);
|
|
693
|
+
}
|
|
682
694
|
},
|
|
683
695
|
ssrEmitAssets: true,
|
|
684
696
|
target: ssr ? 'node18.13' : undefined
|
|
@@ -15,7 +15,7 @@ import('node:async_hooks')
|
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Returns the current `RequestEvent`. Can be used inside
|
|
18
|
+
* Returns the current `RequestEvent`. Can be used inside server hooks, server `load` functions, actions, and endpoints (and functions called by them).
|
|
19
19
|
*
|
|
20
20
|
* In environments without [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage), this must be called synchronously (i.e. not after an `await`).
|
|
21
21
|
* @since 2.20.0
|
|
@@ -25,7 +25,7 @@ export function getRequestEvent() {
|
|
|
25
25
|
|
|
26
26
|
if (!event) {
|
|
27
27
|
let message =
|
|
28
|
-
'Can only read the current request event inside functions invoked during `handle`, such as server `load` functions, actions, and server
|
|
28
|
+
'Can only read the current request event inside functions invoked during `handle`, such as server `load` functions, actions, endpoints, and other server hooks.';
|
|
29
29
|
|
|
30
30
|
if (!als) {
|
|
31
31
|
message +=
|
|
@@ -2,7 +2,7 @@ import { HttpError, SvelteKitError, Redirect } from '../../control.js';
|
|
|
2
2
|
import { normalize_error } from '../../../utils/error.js';
|
|
3
3
|
import { once } from '../../../utils/functions.js';
|
|
4
4
|
import { load_server_data } from '../page/load_data.js';
|
|
5
|
-
import { clarify_devalue_error, handle_error_and_jsonify,
|
|
5
|
+
import { clarify_devalue_error, handle_error_and_jsonify, serialize_uses } from '../utils.js';
|
|
6
6
|
import { normalize_path } from '../../../utils/url.js';
|
|
7
7
|
import { text } from '../../../exports/index.js';
|
|
8
8
|
import * as devalue from 'devalue';
|
|
@@ -253,8 +253,8 @@ export function get_data_json(event, options, nodes) {
|
|
|
253
253
|
return JSON.stringify(node);
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
return `{"type":"data","data":${devalue.stringify(node.data, reducers)},${
|
|
257
|
-
node
|
|
256
|
+
return `{"type":"data","data":${devalue.stringify(node.data, reducers)},${JSON.stringify(
|
|
257
|
+
serialize_uses(node)
|
|
258
258
|
)}${node.slash ? `,"slash":${JSON.stringify(node.slash)}` : ''}}`;
|
|
259
259
|
});
|
|
260
260
|
|
|
@@ -7,7 +7,7 @@ import { serialize_data } from './serialize_data.js';
|
|
|
7
7
|
import { s } from '../../../utils/misc.js';
|
|
8
8
|
import { Csp } from './csp.js';
|
|
9
9
|
import { uneval_action_response } from './actions.js';
|
|
10
|
-
import { clarify_devalue_error,
|
|
10
|
+
import { clarify_devalue_error, handle_error_and_jsonify, serialize_uses } from '../utils.js';
|
|
11
11
|
import { public_env, safe_public_env } from '../../shared-server.js';
|
|
12
12
|
import { text } from '../../../exports/index.js';
|
|
13
13
|
import { create_async_iterator } from '../../../utils/streaming.js';
|
|
@@ -646,9 +646,11 @@ function get_data(event, options, nodes, csp, global) {
|
|
|
646
646
|
const strings = nodes.map((node) => {
|
|
647
647
|
if (!node) return 'null';
|
|
648
648
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
649
|
+
/** @type {any} */
|
|
650
|
+
const payload = { type: 'data', data: node.data, uses: serialize_uses(node) };
|
|
651
|
+
if (node.slash) payload.slash = node.slash;
|
|
652
|
+
|
|
653
|
+
return devalue.uneval(payload, replacer);
|
|
652
654
|
});
|
|
653
655
|
|
|
654
656
|
return {
|
|
@@ -6,6 +6,7 @@ import { HttpError } from '../control.js';
|
|
|
6
6
|
import { fix_stack_trace } from '../shared-server.js';
|
|
7
7
|
import { ENDPOINT_METHODS } from '../../constants.js';
|
|
8
8
|
import { escape_html } from '../../utils/escape.js';
|
|
9
|
+
import { with_event } from '../app/server/event.js';
|
|
9
10
|
|
|
10
11
|
/** @param {any} body */
|
|
11
12
|
export function is_pojo(body) {
|
|
@@ -107,7 +108,11 @@ export async function handle_error_and_jsonify(event, options, error) {
|
|
|
107
108
|
const status = get_status(error);
|
|
108
109
|
const message = get_message(error);
|
|
109
110
|
|
|
110
|
-
return (
|
|
111
|
+
return (
|
|
112
|
+
(await with_event(event, () =>
|
|
113
|
+
options.hooks.handleError({ error, event, status, message })
|
|
114
|
+
)) ?? { message }
|
|
115
|
+
);
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
/**
|
|
@@ -142,26 +147,26 @@ export function clarify_devalue_error(event, error) {
|
|
|
142
147
|
/**
|
|
143
148
|
* @param {import('types').ServerDataNode} node
|
|
144
149
|
*/
|
|
145
|
-
export function
|
|
146
|
-
const uses =
|
|
150
|
+
export function serialize_uses(node) {
|
|
151
|
+
const uses = {};
|
|
147
152
|
|
|
148
153
|
if (node.uses && node.uses.dependencies.size > 0) {
|
|
149
|
-
uses.
|
|
154
|
+
uses.dependencies = Array.from(node.uses.dependencies);
|
|
150
155
|
}
|
|
151
156
|
|
|
152
157
|
if (node.uses && node.uses.search_params.size > 0) {
|
|
153
|
-
uses.
|
|
158
|
+
uses.search_params = Array.from(node.uses.search_params);
|
|
154
159
|
}
|
|
155
160
|
|
|
156
161
|
if (node.uses && node.uses.params.size > 0) {
|
|
157
|
-
uses.
|
|
162
|
+
uses.params = Array.from(node.uses.params);
|
|
158
163
|
}
|
|
159
164
|
|
|
160
|
-
if (node.uses?.parent) uses.
|
|
161
|
-
if (node.uses?.route) uses.
|
|
162
|
-
if (node.uses?.url) uses.
|
|
165
|
+
if (node.uses?.parent) uses.parent = 1;
|
|
166
|
+
if (node.uses?.route) uses.route = 1;
|
|
167
|
+
if (node.uses?.url) uses.url = 1;
|
|
163
168
|
|
|
164
|
-
return
|
|
169
|
+
return uses;
|
|
165
170
|
}
|
|
166
171
|
|
|
167
172
|
/**
|
package/src/version.js
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -2417,7 +2417,7 @@ declare module '$app/server' {
|
|
|
2417
2417
|
*/
|
|
2418
2418
|
export function read(asset: string): Response;
|
|
2419
2419
|
/**
|
|
2420
|
-
* Returns the current `RequestEvent`. Can be used inside
|
|
2420
|
+
* Returns the current `RequestEvent`. Can be used inside server hooks, server `load` functions, actions, and endpoints (and functions called by them).
|
|
2421
2421
|
*
|
|
2422
2422
|
* In environments without [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage), this must be called synchronously (i.e. not after an `await`).
|
|
2423
2423
|
* @since 2.20.0
|