@sveltejs/kit 2.19.1 → 2.20.0

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": "2.19.1",
3
+ "version": "2.20.0",
4
4
  "description": "SvelteKit is the fastest way to build Svelte apps",
5
5
  "keywords": [
6
6
  "framework",
@@ -990,7 +990,7 @@ export interface NavigationEvent<
990
990
  */
991
991
  route: {
992
992
  /**
993
- * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
993
+ * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
994
994
  */
995
995
  id: RouteId;
996
996
  };
@@ -1012,7 +1012,12 @@ export interface NavigationTarget {
1012
1012
  /**
1013
1013
  * Info about the target route
1014
1014
  */
1015
- route: { id: string | null };
1015
+ route: {
1016
+ /**
1017
+ * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
1018
+ */
1019
+ id: string | null;
1020
+ };
1016
1021
  /**
1017
1022
  * The URL that is navigated to
1018
1023
  */
@@ -1129,7 +1134,7 @@ export interface Page<
1129
1134
  */
1130
1135
  route: {
1131
1136
  /**
1132
- * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`.
1137
+ * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
1133
1138
  */
1134
1139
  id: RouteId;
1135
1140
  };
@@ -1205,7 +1210,7 @@ export interface RequestEvent<
1205
1210
  */
1206
1211
  route: {
1207
1212
  /**
1208
- * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`.
1213
+ * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
1209
1214
  */
1210
1215
  id: RouteId;
1211
1216
  };
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import { mkdirp } from '../../../utils/filesystem.js';
3
- import { find_deps, resolve_symlinks } from './utils.js';
3
+ import { filter_fonts, find_deps, resolve_symlinks } from './utils.js';
4
4
  import { s } from '../../../utils/misc.js';
5
5
  import { normalizePath } from 'vite';
6
6
  import { basename } from 'node:path';
@@ -83,13 +83,13 @@ export function build_server_nodes(out, kit, manifest_data, server_manifest, cli
83
83
  const exports = [`export const index = ${i};`];
84
84
 
85
85
  /** @type {string[]} */
86
- const imported = [];
86
+ let imported = [];
87
87
 
88
88
  /** @type {string[]} */
89
- const stylesheets = [];
89
+ let stylesheets = [];
90
90
 
91
91
  /** @type {string[]} */
92
- const fonts = [];
92
+ let fonts = [];
93
93
 
94
94
  if (node.component && client_manifest) {
95
95
  exports.push(
@@ -119,15 +119,45 @@ export function build_server_nodes(out, kit, manifest_data, server_manifest, cli
119
119
  }
120
120
 
121
121
  if (client_manifest && (node.universal || node.component) && output_config.bundleStrategy === 'split') {
122
- const entry = find_deps(
123
- client_manifest,
124
- `${normalizePath(kit.outDir)}/generated/client-optimized/nodes/${i}.js`,
125
- true
126
- );
122
+ const entry_path = `${normalizePath(kit.outDir)}/generated/client-optimized/nodes/${i}.js`;
123
+ const entry = find_deps(client_manifest, entry_path, true);
124
+
125
+ // eagerly load stylesheets and fonts imported by the SSR-ed page to avoid FOUC.
126
+ // If it is not used during SSR, it can be lazily loaded in the browser.
127
+
128
+ /** @type {import('types').AssetDependencies | undefined} */
129
+ let component;
130
+ if (node.component) {
131
+ component = find_deps(server_manifest, node.component, true);
132
+ }
133
+
134
+ /** @type {import('types').AssetDependencies | undefined} */
135
+ let universal;
136
+ if (node.universal) {
137
+ universal = find_deps(server_manifest, node.universal, true);
138
+ }
139
+
140
+ /** @type {Set<string>} */
141
+ const css_used_by_server = new Set();
142
+ /** @type {Set<string>} */
143
+ const assets_used_by_server = new Set();
144
+
145
+ entry.stylesheet_map.forEach((value, key) => {
146
+ // pages and layouts are named as node indexes in the client manifest
147
+ // so we need to use the original filename when checking against the server manifest
148
+ if (key === entry_path) {
149
+ key = node.component ?? key;
150
+ }
151
+
152
+ if (component?.stylesheet_map.has(key) || universal?.stylesheet_map.has(key)) {
153
+ value.css.forEach(file => css_used_by_server.add(file));
154
+ value.assets.forEach(file => assets_used_by_server.add(file));
155
+ }
156
+ });
127
157
 
128
- imported.push(...entry.imports);
129
- stylesheets.push(...entry.stylesheets);
130
- fonts.push(...entry.fonts);
158
+ imported = entry.imports;
159
+ stylesheets = Array.from(css_used_by_server);
160
+ fonts = filter_fonts(Array.from(assets_used_by_server));
131
161
  }
132
162
 
133
163
  exports.push(
@@ -22,11 +22,16 @@ export function find_deps(manifest, entry, add_dynamic_css) {
22
22
  /** @type {Set<string>} */
23
23
  const imported_assets = new Set();
24
24
 
25
+ /** @type {Map<string, { css: Set<string>; assets: Set<string> }>} */
26
+ const stylesheet_map = new Map();
27
+
25
28
  /**
26
29
  * @param {string} current
27
30
  * @param {boolean} add_js
31
+ * @param {string} initial_importer
32
+ * @param {number} dynamic_import_depth
28
33
  */
29
- function traverse(current, add_js) {
34
+ function traverse(current, add_js, initial_importer, dynamic_import_depth) {
30
35
  if (seen.has(current)) return;
31
36
  seen.add(current);
32
37
 
@@ -35,9 +40,7 @@ export function find_deps(manifest, entry, add_dynamic_css) {
35
40
  if (add_js) imports.add(chunk.file);
36
41
 
37
42
  if (chunk.assets) {
38
- for (const asset of chunk.assets) {
39
- imported_assets.add(asset);
40
- }
43
+ chunk.assets.forEach(asset => imported_assets.add(asset));
41
44
  }
42
45
 
43
46
  if (chunk.css) {
@@ -45,17 +48,38 @@ export function find_deps(manifest, entry, add_dynamic_css) {
45
48
  }
46
49
 
47
50
  if (chunk.imports) {
48
- chunk.imports.forEach((file) => traverse(file, add_js));
51
+ chunk.imports.forEach((file) => traverse(file, add_js, initial_importer, dynamic_import_depth));
52
+ }
53
+
54
+ if (!add_dynamic_css) return;
55
+
56
+ if ((chunk.css || chunk.assets) && dynamic_import_depth <= 1) {
57
+ // group files based on the initial importer because if a file is only ever
58
+ // a transitive dependency, it doesn't have a suitable name we can map back to
59
+ // the server manifest
60
+ if (stylesheet_map.has(initial_importer)) {
61
+ const { css, assets } = /** @type {{ css: Set<string>; assets: Set<string> }} */ (stylesheet_map.get(initial_importer));
62
+ if (chunk.css) chunk.css.forEach((file) => css.add(file));
63
+ if (chunk.assets) chunk.assets.forEach((file) => assets.add(file));
64
+ } else {
65
+ stylesheet_map.set(initial_importer, {
66
+ css: new Set(chunk.css),
67
+ assets: new Set(chunk.assets)
68
+ });
69
+ }
49
70
  }
50
71
 
51
- if (add_dynamic_css && chunk.dynamicImports) {
52
- chunk.dynamicImports.forEach((file) => traverse(file, false));
72
+ if (chunk.dynamicImports) {
73
+ dynamic_import_depth++;
74
+ chunk.dynamicImports.forEach((file) => {
75
+ traverse(file, false, file, dynamic_import_depth);
76
+ });
53
77
  }
54
78
  }
55
79
 
56
80
  const { chunk, file } = resolve_symlinks(manifest, entry);
57
81
 
58
- traverse(file, true);
82
+ traverse(file, true, entry, 0);
59
83
 
60
84
  const assets = Array.from(imported_assets);
61
85
 
@@ -65,7 +89,8 @@ export function find_deps(manifest, entry, add_dynamic_css) {
65
89
  imports: Array.from(imports),
66
90
  stylesheets: Array.from(stylesheets),
67
91
  // TODO do we need this separately?
68
- fonts: assets.filter((asset) => /\.(woff2?|ttf|otf)$/.test(asset))
92
+ fonts: filter_fonts(assets),
93
+ stylesheet_map
69
94
  };
70
95
  }
71
96
 
@@ -85,7 +110,15 @@ export function resolve_symlinks(manifest, file) {
85
110
  return { chunk, file };
86
111
  }
87
112
 
88
- const method_names = new Set(['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'OPTIONS']);
113
+ /**
114
+ * @param {string[]} assets
115
+ * @returns {string[]}
116
+ */
117
+ export function filter_fonts(assets) {
118
+ return assets.filter((asset) => /\.(woff2?|ttf|otf)$/.test(asset));
119
+ }
120
+
121
+ const method_names = new Set((['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'OPTIONS']));
89
122
 
90
123
  // If we'd written this in TypeScript, it could be easy...
91
124
  /**
@@ -0,0 +1,54 @@
1
+ /** @import { RequestEvent } from '@sveltejs/kit' */
2
+
3
+ /** @type {RequestEvent | null} */
4
+ let request_event = null;
5
+
6
+ /** @type {import('node:async_hooks').AsyncLocalStorage<RequestEvent | null>} */
7
+ let als;
8
+
9
+ try {
10
+ const hooks = await import('node:async_hooks');
11
+ als = new hooks.AsyncLocalStorage();
12
+ } catch {
13
+ // can't use AsyncLocalStorage, but can still call getRequestEvent synchronously.
14
+ // this isn't behind `supports` because it's basically just StackBlitz (i.e.
15
+ // in-browser usage) that doesn't support it AFAICT
16
+ }
17
+
18
+ /**
19
+ * Returns the current `RequestEvent`. Can be used inside `handle`, `load` and actions (and functions called by them).
20
+ *
21
+ * In environments without [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage), this must be called synchronously (i.e. not after an `await`).
22
+ * @since 2.20.0
23
+ */
24
+ export function getRequestEvent() {
25
+ const event = request_event ?? als?.getStore();
26
+
27
+ if (!event) {
28
+ let message =
29
+ 'Can only read the current request event inside functions invoked during `handle`, such as server `load` functions, actions, and server endpoints.';
30
+
31
+ if (!als) {
32
+ message +=
33
+ ' In environments without `AsyncLocalStorage`, the event must be read synchronously, not after an `await`.';
34
+ }
35
+
36
+ throw new Error(message);
37
+ }
38
+
39
+ return event;
40
+ }
41
+
42
+ /**
43
+ * @template T
44
+ * @param {RequestEvent | null} event
45
+ * @param {() => T} fn
46
+ */
47
+ export function with_event(event, fn) {
48
+ try {
49
+ request_event = event;
50
+ return als ? als.run(event, fn) : fn();
51
+ } finally {
52
+ request_event = null;
53
+ }
54
+ }
@@ -71,3 +71,5 @@ export function read(asset) {
71
71
 
72
72
  throw new Error(`Asset does not exist: ${file}`);
73
73
  }
74
+
75
+ export { getRequestEvent } from './event.js';
@@ -1,5 +1,6 @@
1
1
  import { ENDPOINT_METHODS, PAGE_METHODS } from '../../constants.js';
2
2
  import { negotiate } from '../../utils/http.js';
3
+ import { with_event } from '../app/server/event.js';
3
4
  import { Redirect } from '../control.js';
4
5
  import { method_not_allowed } from './utils.js';
5
6
 
@@ -40,8 +41,8 @@ export async function render_endpoint(event, mod, state) {
40
41
  }
41
42
 
42
43
  try {
43
- let response = await handler(
44
- /** @type {import('@sveltejs/kit').RequestEvent<Record<string, any>>} */ (event)
44
+ let response = await with_event(event, () =>
45
+ handler(/** @type {import('@sveltejs/kit').RequestEvent<Record<string, any>>} */ (event))
45
46
  );
46
47
 
47
48
  if (!(response instanceof Response)) {
@@ -5,6 +5,7 @@ import { get_status, normalize_error } from '../../../utils/error.js';
5
5
  import { is_form_content_type, negotiate } from '../../../utils/http.js';
6
6
  import { HttpError, Redirect, ActionFailure, SvelteKitError } from '../../control.js';
7
7
  import { handle_error_and_jsonify } from '../utils.js';
8
+ import { with_event } from '../../app/server/event.js';
8
9
 
9
10
  /** @param {import('@sveltejs/kit').RequestEvent} event */
10
11
  export function is_action_json_request(event) {
@@ -246,7 +247,7 @@ async function call_action(event, actions) {
246
247
  );
247
248
  }
248
249
 
249
- return action(event);
250
+ return with_event(event, () => action(event));
250
251
  }
251
252
 
252
253
  /** @param {any} data */
@@ -2,6 +2,7 @@ import { DEV } from 'esm-env';
2
2
  import { disable_search, make_trackable } from '../../../utils/url.js';
3
3
  import { validate_depends } from '../../shared.js';
4
4
  import { b64_encode } from '../../utils.js';
5
+ import { with_event } from '../../app/server/event.js';
5
6
 
6
7
  /**
7
8
  * Calls the user's server `load` function.
@@ -16,7 +17,6 @@ import { b64_encode } from '../../utils.js';
16
17
  export async function load_server_data({ event, state, node, parent }) {
17
18
  if (!node?.server) return null;
18
19
 
19
- let done = false;
20
20
  let is_tracking = true;
21
21
 
22
22
  const uses = {
@@ -28,6 +28,13 @@ export async function load_server_data({ event, state, node, parent }) {
28
28
  search_params: new Set()
29
29
  };
30
30
 
31
+ const load = node.server.load;
32
+ const slash = node.server.trailingSlash;
33
+
34
+ if (!load) {
35
+ return { type: 'data', data: null, uses, slash };
36
+ }
37
+
31
38
  const url = make_trackable(
32
39
  event.url,
33
40
  () => {
@@ -58,92 +65,96 @@ export async function load_server_data({ event, state, node, parent }) {
58
65
  disable_search(url);
59
66
  }
60
67
 
61
- const result = await node.server.load?.call(null, {
62
- ...event,
63
- fetch: (info, init) => {
64
- const url = new URL(info instanceof Request ? info.url : info, event.url);
68
+ let done = false;
65
69
 
66
- if (DEV && done && !uses.dependencies.has(url.href)) {
67
- console.warn(
68
- `${node.server_id}: Calling \`event.fetch(...)\` in a promise handler after \`load(...)\` has returned will not cause the function to re-run when the dependency is invalidated`
69
- );
70
- }
70
+ const result = await with_event(event, () =>
71
+ load.call(null, {
72
+ ...event,
73
+ fetch: (info, init) => {
74
+ const url = new URL(info instanceof Request ? info.url : info, event.url);
71
75
 
72
- // Note: server fetches are not added to uses.depends due to security concerns
73
- return event.fetch(info, init);
74
- },
75
- /** @param {string[]} deps */
76
- depends: (...deps) => {
77
- for (const dep of deps) {
78
- const { href } = new URL(dep, event.url);
76
+ if (DEV && done && !uses.dependencies.has(url.href)) {
77
+ console.warn(
78
+ `${node.server_id}: Calling \`event.fetch(...)\` in a promise handler after \`load(...)\` has returned will not cause the function to re-run when the dependency is invalidated`
79
+ );
80
+ }
79
81
 
80
- if (DEV) {
81
- validate_depends(node.server_id || 'missing route ID', dep);
82
+ // Note: server fetches are not added to uses.depends due to security concerns
83
+ return event.fetch(info, init);
84
+ },
85
+ /** @param {string[]} deps */
86
+ depends: (...deps) => {
87
+ for (const dep of deps) {
88
+ const { href } = new URL(dep, event.url);
89
+
90
+ if (DEV) {
91
+ validate_depends(node.server_id || 'missing route ID', dep);
92
+
93
+ if (done && !uses.dependencies.has(href)) {
94
+ console.warn(
95
+ `${node.server_id}: Calling \`depends(...)\` in a promise handler after \`load(...)\` has returned will not cause the function to re-run when the dependency is invalidated`
96
+ );
97
+ }
98
+ }
82
99
 
83
- if (done && !uses.dependencies.has(href)) {
100
+ uses.dependencies.add(href);
101
+ }
102
+ },
103
+ params: new Proxy(event.params, {
104
+ get: (target, key) => {
105
+ if (DEV && done && typeof key === 'string' && !uses.params.has(key)) {
84
106
  console.warn(
85
- `${node.server_id}: Calling \`depends(...)\` in a promise handler after \`load(...)\` has returned will not cause the function to re-run when the dependency is invalidated`
107
+ `${node.server_id}: Accessing \`params.${String(
108
+ key
109
+ )}\` in a promise handler after \`load(...)\` has returned will not cause the function to re-run when the param changes`
86
110
  );
87
111
  }
88
- }
89
112
 
90
- uses.dependencies.add(href);
91
- }
92
- },
93
- params: new Proxy(event.params, {
94
- get: (target, key) => {
95
- if (DEV && done && typeof key === 'string' && !uses.params.has(key)) {
113
+ if (is_tracking) {
114
+ uses.params.add(key);
115
+ }
116
+ return target[/** @type {string} */ (key)];
117
+ }
118
+ }),
119
+ parent: async () => {
120
+ if (DEV && done && !uses.parent) {
96
121
  console.warn(
97
- `${node.server_id}: Accessing \`params.${String(
98
- key
99
- )}\` in a promise handler after \`load(...)\` has returned will not cause the function to re-run when the param changes`
122
+ `${node.server_id}: Calling \`parent(...)\` in a promise handler after \`load(...)\` has returned will not cause the function to re-run when parent data changes`
100
123
  );
101
124
  }
102
125
 
103
126
  if (is_tracking) {
104
- uses.params.add(key);
127
+ uses.parent = true;
105
128
  }
106
- return target[/** @type {string} */ (key)];
107
- }
108
- }),
109
- parent: async () => {
110
- if (DEV && done && !uses.parent) {
111
- console.warn(
112
- `${node.server_id}: Calling \`parent(...)\` in a promise handler after \`load(...)\` has returned will not cause the function to re-run when parent data changes`
113
- );
114
- }
129
+ return parent();
130
+ },
131
+ route: new Proxy(event.route, {
132
+ get: (target, key) => {
133
+ if (DEV && done && typeof key === 'string' && !uses.route) {
134
+ console.warn(
135
+ `${node.server_id}: Accessing \`route.${String(
136
+ key
137
+ )}\` in a promise handler after \`load(...)\` has returned will not cause the function to re-run when the route changes`
138
+ );
139
+ }
115
140
 
116
- if (is_tracking) {
117
- uses.parent = true;
118
- }
119
- return parent();
120
- },
121
- route: new Proxy(event.route, {
122
- get: (target, key) => {
123
- if (DEV && done && typeof key === 'string' && !uses.route) {
124
- console.warn(
125
- `${node.server_id}: Accessing \`route.${String(
126
- key
127
- )}\` in a promise handler after \`load(...)\` has returned will not cause the function to re-run when the route changes`
128
- );
141
+ if (is_tracking) {
142
+ uses.route = true;
143
+ }
144
+ return target[/** @type {'id'} */ (key)];
129
145
  }
130
-
131
- if (is_tracking) {
132
- uses.route = true;
146
+ }),
147
+ url,
148
+ untrack(fn) {
149
+ is_tracking = false;
150
+ try {
151
+ return fn();
152
+ } finally {
153
+ is_tracking = true;
133
154
  }
134
- return target[/** @type {'id'} */ (key)];
135
155
  }
136
- }),
137
- url,
138
- untrack(fn) {
139
- is_tracking = false;
140
- try {
141
- return fn();
142
- } finally {
143
- is_tracking = true;
144
- }
145
- }
146
- });
156
+ })
157
+ );
147
158
 
148
159
  if (__SVELTEKIT_DEV__) {
149
160
  validate_load_response(result, node.server_id);
@@ -155,7 +166,7 @@ export async function load_server_data({ event, state, node, parent }) {
155
166
  type: 'data',
156
167
  data: result ?? null,
157
168
  uses,
158
- slash: node.server.trailingSlash
169
+ slash
159
170
  };
160
171
  }
161
172
 
@@ -33,6 +33,7 @@ import {
33
33
  strip_data_suffix,
34
34
  strip_resolution_suffix
35
35
  } from '../pathname.js';
36
+ import { with_event } from '../app/server/event.js';
36
37
 
37
38
  /* global __SVELTEKIT_ADAPTER_NAME__ */
38
39
  /* global __SVELTEKIT_DEV__ */
@@ -350,26 +351,32 @@ export async function respond(request, options, manifest, state) {
350
351
 
351
352
  if (state.prerendering && !state.prerendering.fallback) disable_search(url);
352
353
 
353
- const response = await options.hooks.handle({
354
- event,
355
- resolve: (event, opts) =>
356
- resolve(event, page_nodes, opts).then((response) => {
357
- // add headers/cookies here, rather than inside `resolve`, so that we
358
- // can do it once for all responses instead of once per `return`
359
- for (const key in headers) {
360
- const value = headers[key];
361
- response.headers.set(key, /** @type {string} */ (value));
362
- }
363
-
364
- add_cookies_to_headers(response.headers, Object.values(new_cookies));
365
-
366
- if (state.prerendering && event.route.id !== null) {
367
- response.headers.set('x-sveltekit-routeid', encodeURI(event.route.id));
368
- }
369
-
370
- return response;
371
- })
372
- });
354
+ const response = await with_event(event, () =>
355
+ options.hooks.handle({
356
+ event,
357
+ resolve: (event, opts) =>
358
+ // counter-intuitively, we need to clear the event, so that it's not
359
+ // e.g. accessible when loading modules needed to handle the request
360
+ with_event(null, () =>
361
+ resolve(event, page_nodes, opts).then((response) => {
362
+ // add headers/cookies here, rather than inside `resolve`, so that we
363
+ // can do it once for all responses instead of once per `return`
364
+ for (const key in headers) {
365
+ const value = headers[key];
366
+ response.headers.set(key, /** @type {string} */ (value));
367
+ }
368
+
369
+ add_cookies_to_headers(response.headers, Object.values(new_cookies));
370
+
371
+ if (state.prerendering && event.route.id !== null) {
372
+ response.headers.set('x-sveltekit-routeid', encodeURI(event.route.id));
373
+ }
374
+
375
+ return response;
376
+ })
377
+ )
378
+ })
379
+ );
373
380
 
374
381
  // respond with 304 if etag matches
375
382
  if (response.status === 200 && response.headers.has('etag')) {
@@ -59,6 +59,7 @@ export interface AssetDependencies {
59
59
  imports: string[];
60
60
  stylesheets: string[];
61
61
  fonts: string[];
62
+ stylesheet_map: Map<string, { css: Set<string>; assets: Set<string> }>;
62
63
  }
63
64
 
64
65
  export interface BuildData {
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // generated during release, do not modify
2
2
 
3
3
  /** @type {string} */
4
- export const VERSION = '2.19.1';
4
+ export const VERSION = '2.20.0';
package/types/index.d.ts CHANGED
@@ -972,7 +972,7 @@ declare module '@sveltejs/kit' {
972
972
  */
973
973
  route: {
974
974
  /**
975
- * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
975
+ * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
976
976
  */
977
977
  id: RouteId;
978
978
  };
@@ -994,7 +994,12 @@ declare module '@sveltejs/kit' {
994
994
  /**
995
995
  * Info about the target route
996
996
  */
997
- route: { id: string | null };
997
+ route: {
998
+ /**
999
+ * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
1000
+ */
1001
+ id: string | null;
1002
+ };
998
1003
  /**
999
1004
  * The URL that is navigated to
1000
1005
  */
@@ -1111,7 +1116,7 @@ declare module '@sveltejs/kit' {
1111
1116
  */
1112
1117
  route: {
1113
1118
  /**
1114
- * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`.
1119
+ * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
1115
1120
  */
1116
1121
  id: RouteId;
1117
1122
  };
@@ -1187,7 +1192,7 @@ declare module '@sveltejs/kit' {
1187
1192
  */
1188
1193
  route: {
1189
1194
  /**
1190
- * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`.
1195
+ * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
1191
1196
  */
1192
1197
  id: RouteId;
1193
1198
  };
@@ -2397,6 +2402,7 @@ declare module '$app/paths' {
2397
2402
  }
2398
2403
 
2399
2404
  declare module '$app/server' {
2405
+ import type { RequestEvent } from '@sveltejs/kit';
2400
2406
  /**
2401
2407
  * Read the contents of an imported asset from the filesystem
2402
2408
  * @example
@@ -2410,6 +2416,13 @@ declare module '$app/server' {
2410
2416
  * @since 2.4.0
2411
2417
  */
2412
2418
  export function read(asset: string): Response;
2419
+ /**
2420
+ * Returns the current `RequestEvent`. Can be used inside `handle`, `load` and actions (and functions called by them).
2421
+ *
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
+ * @since 2.20.0
2424
+ */
2425
+ export function getRequestEvent(): RequestEvent<Partial<Record<string, string>>, string | null>;
2413
2426
 
2414
2427
  export {};
2415
2428
  }
@@ -120,6 +120,7 @@
120
120
  "assets",
121
121
  "resolveRoute",
122
122
  "read",
123
+ "getRequestEvent",
123
124
  "page",
124
125
  "navigating",
125
126
  "updated",
@@ -141,6 +142,7 @@
141
142
  "../src/runtime/client/client.js",
142
143
  "../src/runtime/app/paths/types.d.ts",
143
144
  "../src/runtime/app/server/index.js",
145
+ "../src/runtime/app/server/event.js",
144
146
  "../src/runtime/app/state/index.js",
145
147
  "../src/runtime/app/stores.js"
146
148
  ],
@@ -161,8 +163,9 @@
161
163
  null,
162
164
  null,
163
165
  null,
166
+ null,
164
167
  null
165
168
  ],
166
- "mappings": ";;;;;;;;;kBA2BiBA,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;aA2BZC,cAAcA;;;;;;aAMdC,cAAcA;;;;;;;;;;;;;;;kBAeTC,aAAaA;;;;;;;;;;;;;;;;;kBAiBbC,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAkGPC,MAAMA;;;;;;;;;;;;;;;;;;;;;kBAqBNC,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA4DPC,QAAQA;;;;;;;;kBAQRC,SAASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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