@sveltejs/kit 3.0.0-next.2 → 3.0.0-next.20

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 (192) hide show
  1. package/package.json +58 -36
  2. package/src/cli.js +14 -11
  3. package/src/constants.js +6 -1
  4. package/src/core/adapt/builder.js +54 -60
  5. package/src/core/adapt/index.js +2 -5
  6. package/src/core/config/index.js +141 -76
  7. package/src/core/config/options.js +260 -260
  8. package/src/core/config/types.d.ts +1 -1
  9. package/src/core/env.js +143 -13
  10. package/src/core/generate_manifest/index.js +18 -15
  11. package/src/core/postbuild/analyse.js +7 -19
  12. package/src/core/postbuild/crawl.js +22 -6
  13. package/src/core/postbuild/entities.js +8 -2
  14. package/src/core/postbuild/fallback.js +4 -2
  15. package/src/core/postbuild/prerender.js +193 -69
  16. package/src/core/postbuild/queue.js +2 -1
  17. package/src/core/sync/create_manifest_data/conflict.js +1 -1
  18. package/src/core/sync/create_manifest_data/index.js +72 -52
  19. package/src/core/sync/sync.js +35 -26
  20. package/src/core/sync/ts.js +1 -1
  21. package/src/core/sync/utils.js +22 -2
  22. package/src/core/sync/{write_non_ambient.js → write_app_types.js} +105 -56
  23. package/src/core/sync/write_client_manifest.js +13 -28
  24. package/src/core/sync/write_env.js +7 -5
  25. package/src/core/sync/write_server.js +25 -33
  26. package/src/core/sync/write_tsconfig/index.js +274 -0
  27. package/src/core/sync/write_tsconfig/test-app/package.json +7 -0
  28. package/src/core/sync/write_tsconfig/utils.js +77 -0
  29. package/src/core/sync/write_tsconfig/validate.js +128 -0
  30. package/src/core/sync/write_types/index.js +119 -116
  31. package/src/core/utils.js +30 -5
  32. package/src/exports/env/index.js +77 -0
  33. package/src/exports/env/public.d.ts +55 -0
  34. package/src/exports/hooks/index.js +3 -9
  35. package/src/exports/hooks/public.d.ts +194 -0
  36. package/src/exports/hooks/sequence.js +9 -6
  37. package/src/exports/index.js +53 -20
  38. package/src/exports/internal/client.js +5 -0
  39. package/src/exports/internal/env.js +8 -5
  40. package/src/exports/internal/index.js +1 -90
  41. package/src/exports/internal/{event.js → server/event.js} +1 -2
  42. package/src/exports/internal/server/index.js +37 -0
  43. package/src/exports/internal/server/telemetry.js +95 -0
  44. package/src/exports/internal/shared.js +90 -0
  45. package/src/exports/node/index.js +64 -22
  46. package/src/exports/params/index.js +70 -0
  47. package/src/exports/params/public.d.ts +63 -0
  48. package/src/exports/public.d.ts +219 -1118
  49. package/src/exports/url.js +86 -0
  50. package/src/exports/vite/build/build_server.js +53 -64
  51. package/src/exports/vite/build/remote.js +24 -19
  52. package/src/exports/vite/build/utils.js +0 -8
  53. package/src/exports/vite/dev/index.js +199 -125
  54. package/src/exports/vite/index.js +1514 -833
  55. package/src/exports/vite/module_ids.js +2 -2
  56. package/src/exports/vite/preview/index.js +32 -24
  57. package/src/exports/vite/utils.js +83 -45
  58. package/src/pathname.js +55 -0
  59. package/src/runner.js +15 -0
  60. package/src/runtime/app/env/internal.js +4 -4
  61. package/src/runtime/app/env/types.d.ts +1 -1
  62. package/src/runtime/app/environment/index.js +3 -3
  63. package/src/runtime/app/{forms.js → forms/index.js} +73 -42
  64. package/src/runtime/app/forms/public.d.ts +2 -0
  65. package/src/runtime/app/forms/types.d.ts +56 -0
  66. package/src/runtime/app/internal/transport.js +53 -0
  67. package/src/runtime/app/manifest/index.js +1 -0
  68. package/src/runtime/app/{navigation.js → navigation/index.js} +2 -1
  69. package/src/runtime/app/navigation/public.d.ts +237 -0
  70. package/src/runtime/app/paths/client.js +37 -37
  71. package/src/runtime/app/paths/index.js +1 -1
  72. package/src/runtime/app/paths/internal/client.js +34 -2
  73. package/src/runtime/app/paths/internal/server.js +6 -23
  74. package/src/runtime/app/paths/internal.d.ts +3 -0
  75. package/src/runtime/app/paths/public.d.ts +1 -29
  76. package/src/runtime/app/paths/server.js +36 -17
  77. package/src/runtime/app/paths/types.d.ts +11 -19
  78. package/src/runtime/app/server/index.js +2 -2
  79. package/src/runtime/app/server/public.d.ts +519 -0
  80. package/src/runtime/app/server/remote/command.js +13 -11
  81. package/src/runtime/app/server/remote/form.js +61 -39
  82. package/src/runtime/app/server/remote/prerender.js +45 -45
  83. package/src/runtime/app/server/remote/query.js +106 -108
  84. package/src/runtime/app/server/remote/requested.js +27 -19
  85. package/src/runtime/app/server/remote/shared.js +75 -75
  86. package/src/runtime/app/service-worker/index.js +24 -0
  87. package/src/runtime/app/state/client.js +4 -2
  88. package/src/runtime/app/state/index.js +7 -5
  89. package/src/runtime/app/state/public.d.ts +72 -0
  90. package/src/runtime/app/state/server.js +3 -0
  91. package/src/runtime/app/stores.js +15 -78
  92. package/src/runtime/client/bundle.js +1 -1
  93. package/src/runtime/client/client-entry.js +3 -0
  94. package/src/runtime/client/client.js +1336 -648
  95. package/src/runtime/client/constants.js +3 -6
  96. package/src/runtime/client/entry.js +24 -3
  97. package/src/runtime/client/fetcher.js +25 -25
  98. package/src/runtime/client/ndjson.js +1 -1
  99. package/src/runtime/client/parse.js +1 -1
  100. package/src/runtime/client/payload.js +17 -0
  101. package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
  102. package/src/runtime/client/remote-functions/command.svelte.js +37 -61
  103. package/src/runtime/client/remote-functions/form.svelte.js +267 -178
  104. package/src/runtime/client/remote-functions/prerender.svelte.js +32 -11
  105. package/src/runtime/client/remote-functions/query/index.js +10 -17
  106. package/src/runtime/client/remote-functions/query/instance.svelte.js +64 -18
  107. package/src/runtime/client/remote-functions/query/proxy.js +5 -5
  108. package/src/runtime/client/remote-functions/query-batch.svelte.js +61 -70
  109. package/src/runtime/client/remote-functions/query-live/index.js +1 -1
  110. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +63 -21
  111. package/src/runtime/client/remote-functions/query-live/iterator.js +15 -12
  112. package/src/runtime/client/remote-functions/query-live/proxy.js +2 -12
  113. package/src/runtime/client/remote-functions/shared.svelte.js +90 -65
  114. package/src/runtime/client/snapshots.js +147 -0
  115. package/src/runtime/client/state.svelte.js +94 -55
  116. package/src/runtime/client/stream.js +3 -2
  117. package/src/runtime/client/types.d.ts +13 -9
  118. package/src/runtime/client/utils.js +22 -110
  119. package/src/runtime/components/root.svelte +56 -0
  120. package/src/runtime/env/dynamic/private.js +7 -0
  121. package/src/runtime/env/dynamic/public.js +7 -0
  122. package/src/runtime/env/static/private.js +6 -0
  123. package/src/runtime/env/static/public.js +6 -0
  124. package/src/runtime/form-utils.js +172 -61
  125. package/src/runtime/pathname.js +20 -32
  126. package/src/runtime/props.svelte.js +72 -0
  127. package/src/runtime/server/constants.js +0 -3
  128. package/src/runtime/server/cookie.js +70 -53
  129. package/src/runtime/server/csrf.js +65 -0
  130. package/src/runtime/server/data/index.js +48 -52
  131. package/src/runtime/server/dev.js +22 -0
  132. package/src/runtime/server/endpoint.js +3 -4
  133. package/src/runtime/server/env_module.js +0 -5
  134. package/src/runtime/server/errors.js +160 -0
  135. package/src/runtime/server/fetch.js +31 -38
  136. package/src/runtime/server/index.js +90 -64
  137. package/src/runtime/server/internal.js +71 -0
  138. package/src/runtime/server/page/actions.js +84 -64
  139. package/src/runtime/server/page/crypto.js +2 -2
  140. package/src/runtime/server/page/csp.js +88 -104
  141. package/src/runtime/server/page/data_serializer.js +22 -23
  142. package/src/runtime/server/page/index.js +35 -53
  143. package/src/runtime/server/page/load_data.js +47 -54
  144. package/src/runtime/server/page/render.js +172 -238
  145. package/src/runtime/server/page/respond_with_error.js +16 -30
  146. package/src/runtime/server/page/serialize_data.js +2 -13
  147. package/src/runtime/server/page/server_routing.js +85 -26
  148. package/src/runtime/server/remote-functions.js +639 -0
  149. package/src/runtime/server/respond.js +188 -129
  150. package/src/runtime/server/sourcemaps.js +183 -0
  151. package/src/runtime/server/state.js +53 -0
  152. package/src/runtime/server/utils.js +12 -154
  153. package/src/runtime/shared.js +20 -40
  154. package/src/runtime/utils.js +3 -0
  155. package/src/types/ambient-private.d.ts +11 -1
  156. package/src/types/ambient.d.ts +87 -36
  157. package/src/types/global-private.d.ts +25 -25
  158. package/src/types/internal.d.ts +160 -150
  159. package/src/types/private.d.ts +41 -1
  160. package/src/utils/error.js +28 -4
  161. package/src/utils/escape.js +9 -25
  162. package/src/utils/features.js +1 -1
  163. package/src/utils/filesystem.js +1 -23
  164. package/src/utils/fork.js +7 -2
  165. package/src/utils/hash.js +21 -0
  166. package/src/utils/http.js +8 -7
  167. package/src/utils/import.js +9 -2
  168. package/src/utils/imports.js +83 -0
  169. package/src/utils/mime.js +9 -0
  170. package/src/utils/page_nodes.js +6 -7
  171. package/src/utils/params.js +67 -0
  172. package/src/utils/regex.js +9 -0
  173. package/src/utils/routing.js +145 -73
  174. package/src/utils/shared-iterator.js +5 -0
  175. package/src/utils/streaming.js +14 -4
  176. package/src/utils/url.js +33 -2
  177. package/src/version.js +1 -1
  178. package/types/index.d.ts +2291 -2135
  179. package/types/index.d.ts.map +116 -108
  180. package/src/core/sync/write_ambient.js +0 -18
  181. package/src/core/sync/write_root.js +0 -148
  182. package/src/core/sync/write_tsconfig.js +0 -250
  183. package/src/exports/internal/server.js +0 -22
  184. package/src/exports/node/polyfills.js +0 -30
  185. package/src/runtime/server/app.js +0 -9
  186. package/src/runtime/server/remote.js +0 -457
  187. package/src/runtime/shared-server.js +0 -7
  188. package/src/runtime/telemetry/otel.js +0 -21
  189. package/src/runtime/telemetry/record_span.js +0 -65
  190. package/src/types/synthetic/$lib.md +0 -5
  191. /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
  192. /package/src/{runtime/telemetry/noop.js → telemetry.js} +0 -0
@@ -0,0 +1,56 @@
1
+ // kept separate from public.d.ts so generated $types can resolve these without pulling in the runtime graph
2
+ import type { MaybePromise } from '../../../types/private.js';
3
+ /**
4
+ * When calling a form action via fetch, the response will be one of these shapes.
5
+ * ```svelte
6
+ * <form method="post" use:enhance={() => {
7
+ * return ({ result }) => {
8
+ * // result is of type ActionResult
9
+ * };
10
+ * }}
11
+ * ```
12
+ *
13
+ * Success and failure results carry the root-relative `pathname + search` of the action URL, with
14
+ * the `?/actionName` parameter removed. Redirect results carry the redirect target. Server-generated
15
+ * error results also carry the action location, while client-generated errors such as network
16
+ * failures do not. `update` uses this location to emulate native form navigation.
17
+ */
18
+ export type ActionResult<
19
+ Success extends Record<string, unknown> | undefined = Record<string, any>,
20
+ Failure extends Record<string, unknown> | undefined = Record<string, any>
21
+ > =
22
+ | { type: 'success'; status: number; data?: Success; location: string }
23
+ | { type: 'failure'; status: number; data?: Failure; location: string }
24
+ | { type: 'redirect'; status: number; location: string }
25
+ | { type: 'error'; status?: number; error: App.Error; location?: string };
26
+
27
+ export type SubmitFunction<
28
+ Success extends Record<string, unknown> | undefined = Record<string, any>,
29
+ Failure extends Record<string, unknown> | undefined = Record<string, any>
30
+ > = (input: {
31
+ action: URL;
32
+ formData: FormData;
33
+ formElement: HTMLFormElement;
34
+ controller: AbortController;
35
+ submitter: HTMLElement | null;
36
+ cancel: () => void;
37
+ }) => MaybePromise<
38
+ | void
39
+ | ((opts: {
40
+ formData: FormData;
41
+ formElement: HTMLFormElement;
42
+ action: URL;
43
+ result: ActionResult<Success, Failure>;
44
+ /**
45
+ * Call this to get the default behavior of a form submission response.
46
+ * @param options Set `reset: false` if you don't want the `<form>` values to be reset after a successful submission. `refreshAll` defaults to `true` for successful results and `false` for failures. When the submission navigates, setting it to `false` still runs the destination's `load` functions but may reuse shared layout data. Set `navigate: false` to apply non-redirect results to the current page instead of navigating to `result.location`. Redirects are always followed.
47
+ */
48
+ update: (options?: {
49
+ reset?: boolean;
50
+ refreshAll?: boolean;
51
+ navigate?: boolean;
52
+ /** @deprecated Use `refreshAll` instead. */
53
+ invalidateAll?: boolean;
54
+ }) => Promise<void>;
55
+ }) => MaybePromise<void>)
56
+ >;
@@ -0,0 +1,53 @@
1
+ /** @import { Transport } from '@sveltejs/kit/hooks' */
2
+ import * as devalue from 'devalue';
3
+ import { DEV } from 'esm-env';
4
+
5
+ /** @type {(thing: any) => string} */
6
+ export let uneval = () => {
7
+ throw new Error(DEV ? 'called uneval before init_transport' : '');
8
+ };
9
+
10
+ /** @type {(data: any) => string} */
11
+ export let stringify = () => {
12
+ throw new Error(DEV ? 'called stringify before init_transport' : '');
13
+ };
14
+
15
+ /** @type {(data: string) => any} */
16
+ export let parse = () => {
17
+ throw new Error(DEV ? 'called parse before init_transport' : '');
18
+ };
19
+
20
+ /** @type {Record<string, (data: any) => any>} */
21
+ export let encoders = {};
22
+
23
+ /** @type {Record<string, (data: any) => any>} */
24
+ export let decoders = {};
25
+
26
+ export let has_custom_transporters = false;
27
+
28
+ /**
29
+ *
30
+ * @param {Transport} transport
31
+ */
32
+ export function init_transport(transport) {
33
+ const transporters = Object.entries(transport);
34
+
35
+ has_custom_transporters = transporters.length > 0;
36
+
37
+ /** @param {unknown} thing */
38
+ const replacer = (thing) => {
39
+ for (const key of Object.keys(transport)) {
40
+ const encoded = transport[key].encode(thing);
41
+ if (encoded) {
42
+ return `app.decode('${key}', ${devalue.uneval(encoded, replacer)})`;
43
+ }
44
+ }
45
+ };
46
+
47
+ encoders = Object.fromEntries(transporters.map(([k, v]) => [k, v.encode]));
48
+ decoders = Object.fromEntries(transporters.map(([k, v]) => [k, v.decode]));
49
+
50
+ uneval = (data) => devalue.uneval(data, replacer);
51
+ stringify = (data) => devalue.stringify(data, encoders);
52
+ parse = (data) => devalue.parse(data, decoders);
53
+ }
@@ -0,0 +1 @@
1
+ export * from '__sveltekit/manifest-data';
@@ -11,4 +11,5 @@ export {
11
11
  preloadData,
12
12
  pushState,
13
13
  replaceState
14
- } from '../client/client.js';
14
+ } from '../../client/client.js';
15
+ export { snapshot } from '../../client/snapshots.js';
@@ -0,0 +1,237 @@
1
+ import type { LayoutParams as AppLayoutParams, RouteId as AppRouteId } from '$app/types';
2
+
3
+ export * from './index.js';
4
+
5
+ /**
6
+ * Information about the target of a specific navigation.
7
+ */
8
+ export interface NavigationTarget<
9
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
10
+ RouteId extends AppRouteId | null = AppRouteId | null
11
+ > {
12
+ /**
13
+ * Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
14
+ * Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
15
+ */
16
+ params: Params | null;
17
+ /**
18
+ * Info about the target route
19
+ */
20
+ route: {
21
+ /**
22
+ * 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.
23
+ */
24
+ id: RouteId | null;
25
+ };
26
+ /**
27
+ * The URL that is navigated to
28
+ */
29
+ url: URL;
30
+ /**
31
+ * The scroll position associated with this navigation.
32
+ *
33
+ * For the `from` target, this is the scroll position at the moment of navigation.
34
+ *
35
+ * For the `to` target, this represents the scroll position that will be or was restored:
36
+ * - In `beforeNavigate` and `onNavigate`, this is only available for `popstate` navigations (back/forward button)
37
+ * and will be `null` for other navigation types, since the final scroll position isn't known
38
+ * ahead of time.
39
+ * - In `afterNavigate`, this is always the scroll position that was applied after the navigation
40
+ * completed.
41
+ */
42
+ scroll: { x: number; y: number } | null;
43
+ }
44
+
45
+ export interface GotoOptions {
46
+ /**
47
+ * If `true`, replaces the current history entry rather than creating a new one.
48
+ * @default false
49
+ */
50
+ replace?: boolean;
51
+ /** @deprecated Use `replace` instead. */
52
+ replaceState?: boolean;
53
+ /**
54
+ * If `true`, updates the URL and `page.state` without navigating.
55
+ * @default false
56
+ */
57
+ shallow?: boolean;
58
+ /**
59
+ * If `true`, resets the scroll position (to the top of the page, or to the element
60
+ * matching the URL's `#hash` if there is one) and resets focus (to the `<body>`, or the
61
+ * `autofocus` element if there is one) once the navigation completes.
62
+ *
63
+ * If `false`, the current scroll position and focused element are left alone.
64
+ * @default true, or false when `shallow` is true
65
+ */
66
+ reset?: boolean;
67
+ /**
68
+ * If `true`, reruns all `load` functions and queries of the page.
69
+ * @default false
70
+ */
71
+ refreshAll?: boolean;
72
+ /** Causes any `load` functions to rerun if they depend on one of the URLs. */
73
+ invalidate?: Array<string | URL | ((url: URL) => boolean)>;
74
+ /** @deprecated Use `refreshAll` instead. */
75
+ invalidateAll?: boolean;
76
+ /** An optional object that will be available as `page.state`. */
77
+ state?: App.PageState;
78
+ /**
79
+ * If `true`, `page.state` will be restored after a full page reload.
80
+ * @default false
81
+ */
82
+ persistState?: boolean;
83
+ }
84
+
85
+ /**
86
+ * - `enter`: The app has hydrated/started
87
+ * - `form`: The user submitted a `<form method="GET">`
88
+ * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
89
+ * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
90
+ * - `link`: Navigation was triggered by a link click
91
+ * - `popstate`: Navigation was triggered by back/forward navigation
92
+ */
93
+ export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
94
+
95
+ export interface NavigationBase {
96
+ /**
97
+ * The type of navigation:
98
+ * - `enter`: The app has hydrated/started
99
+ * - `form`: The user submitted a `<form method="GET">`
100
+ * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
101
+ * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
102
+ * - `link`: Navigation was triggered by a link click
103
+ * - `popstate`: Navigation was triggered by back/forward navigation
104
+ */
105
+ type: NavigationType;
106
+ /** Whether this is a shallow navigation. */
107
+ shallow: boolean;
108
+ /**
109
+ * Where navigation was triggered from
110
+ */
111
+ from: NavigationTarget | null;
112
+ /**
113
+ * Where navigation is going to/has gone to
114
+ */
115
+ to: NavigationTarget | null;
116
+ /**
117
+ * Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation).
118
+ */
119
+ willUnload: boolean;
120
+ /**
121
+ * A promise that resolves once the navigation is complete, and rejects if the navigation
122
+ * fails or is aborted. In the case of a `willUnload` navigation, the promise will never resolve
123
+ */
124
+ complete: Promise<void>;
125
+ }
126
+
127
+ /**
128
+ * The navigation that occurs when the app starts/hydrates
129
+ */
130
+ export interface NavigationEnter extends NavigationBase {
131
+ type: 'enter';
132
+
133
+ /**
134
+ * In case of a history back/forward navigation, the number of steps to go back/forward
135
+ */
136
+ delta?: undefined;
137
+
138
+ /**
139
+ * Dispatched `Event` object when navigation occurred by `popstate` or `link`.
140
+ */
141
+ event?: undefined;
142
+ }
143
+
144
+ export type NavigationExternal = NavigationGoto | NavigationLeave;
145
+
146
+ /**
147
+ * A navigation triggered by a `goto(...)` call or a redirect
148
+ */
149
+ export interface NavigationGoto extends NavigationBase {
150
+ type: 'goto';
151
+ }
152
+
153
+ /**
154
+ * A navigation triggered by the tab being closed, or the user navigating to a different document
155
+ */
156
+ export interface NavigationLeave extends NavigationBase {
157
+ type: 'leave';
158
+ }
159
+
160
+ /**
161
+ * A navigation triggered by a `<form method="GET">`
162
+ */
163
+ export interface NavigationFormSubmit extends NavigationBase {
164
+ type: 'form';
165
+
166
+ /**
167
+ * The `SubmitEvent` that caused the navigation
168
+ */
169
+ event: SubmitEvent;
170
+ }
171
+
172
+ /**
173
+ * A navigation triggered by back/forward navigation
174
+ */
175
+ export interface NavigationPopState extends NavigationBase {
176
+ type: 'popstate';
177
+
178
+ /**
179
+ * In case of a history back/forward navigation, the number of steps to go back/forward
180
+ */
181
+ delta: number;
182
+
183
+ /**
184
+ * The `PopStateEvent` that caused the navigation
185
+ */
186
+ event: PopStateEvent;
187
+ }
188
+
189
+ /**
190
+ * A navigation triggered by a link click
191
+ */
192
+ export interface NavigationLink extends NavigationBase {
193
+ type: 'link';
194
+
195
+ /**
196
+ * The `PointerEvent` that caused the navigation
197
+ */
198
+ event: PointerEvent;
199
+ }
200
+
201
+ export type Navigation =
202
+ | NavigationExternal
203
+ | NavigationFormSubmit
204
+ | NavigationPopState
205
+ | NavigationLink;
206
+
207
+ /**
208
+ * The argument passed to [`beforeNavigate`](https://svelte.dev/docs/kit/$app-navigation#beforeNavigate) callbacks.
209
+ */
210
+ export type BeforeNavigate = Navigation & {
211
+ /**
212
+ * Call this to prevent the navigation from starting.
213
+ */
214
+ cancel: () => void;
215
+ };
216
+
217
+ /**
218
+ * The argument passed to [`onNavigate`](https://svelte.dev/docs/kit/$app-navigation#onNavigate) callbacks.
219
+ */
220
+ export type OnNavigate = Navigation & {
221
+ type: Exclude<NavigationType, 'enter' | 'leave'>;
222
+ /**
223
+ * Since `onNavigate` callbacks are called immediately before a client-side navigation, they will never be called with a navigation that unloads the page.
224
+ */
225
+ willUnload: false;
226
+ };
227
+
228
+ /**
229
+ * The argument passed to [`afterNavigate`](https://svelte.dev/docs/kit/$app-navigation#afterNavigate) callbacks.
230
+ */
231
+ export type AfterNavigate = (Navigation | NavigationEnter) & {
232
+ type: Exclude<NavigationType, 'leave'>;
233
+ /**
234
+ * Since `afterNavigate` callbacks are called after a navigation completes, they will never be called with a navigation that unloads the page.
235
+ */
236
+ willUnload: false;
237
+ };
@@ -1,11 +1,13 @@
1
- /** @import { Asset, RouteId, RouteIdWithSearchOrHash, Pathname, PathnameWithSearchOrHash, ResolvedPathname } from '$app/types' */
1
+ /** @import { AssetPath, RouteId, RouteIdWithSearchOrHash, PathnameWithSearchOrHash, ResolvedPathname, RouteParams } from '$app/types' */
2
2
  /** @import { ResolveArgs } from './types.js' */
3
- import { base, assets, hash_routing } from './internal/client.js';
3
+ import { base, assets, hash_routing, match_implementation } from './internal/client.js';
4
4
  import { resolve_route } from '../../../utils/routing.js';
5
- import { get_navigation_intent } from '../../client/client.js';
5
+ import { DEV } from 'esm-env';
6
+
7
+ export { base, assets, app_dir } from './internal/client.js';
6
8
 
7
9
  /**
8
- * Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.kit.paths.assets`](https://svelte.dev/docs/kit/configuration#paths) if configured, or otherwise by prefixing it with the base path.
10
+ * Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.paths.assets`](https://svelte.dev/docs/kit/configuration#paths) if configured, or otherwise by prefixing it with the base path.
9
11
  *
10
12
  * During server rendering, the base path is relative and depends on the page currently being rendered.
11
13
  *
@@ -15,15 +17,26 @@ import { get_navigation_intent } from '../../client/client.js';
15
17
  * import { asset } from '$app/paths';
16
18
  * </script>
17
19
  *
18
- * <img alt="a potato" src={asset('/potato.jpg')} />
20
+ * <img alt="a potato" src={asset('potato.jpg')} />
19
21
  * ```
20
22
  * @since 2.26
21
23
  *
22
- * @param {Asset} file
24
+ * @param {AssetPath} file
23
25
  * @returns {string}
24
26
  */
25
27
  export function asset(file) {
26
- return (assets || base) + file;
28
+ let path = /** @type {string} */ (file);
29
+
30
+ // TODO 4.0 remove this
31
+ if (path[0] === '/') {
32
+ if (DEV) {
33
+ console.warn(`\`asset('${path}')\` should now be \`asset('${path.slice(1)}')\``);
34
+ }
35
+
36
+ path = path.slice(1);
37
+ }
38
+
39
+ return (assets || base) + '/' + path;
27
40
  }
28
41
 
29
42
  const pathname_prefix = hash_routing ? '#' : '';
@@ -38,7 +51,7 @@ const pathname_prefix = hash_routing ? '#' : '';
38
51
  * import { resolve } from '$app/paths';
39
52
  *
40
53
  * // using a pathname
41
- * const resolved = resolve(`/blog/hello-world`);
54
+ * const resolved = resolve(`blog/hello-world`);
42
55
  *
43
56
  * // using a route ID plus parameters
44
57
  * const resolved = resolve('/blog/[slug]', {
@@ -52,18 +65,20 @@ const pathname_prefix = hash_routing ? '#' : '';
52
65
  * @returns {ResolvedPathname}
53
66
  */
54
67
  export function resolve(...args) {
55
- if (!args[0].startsWith('/')) {
56
- throw new Error(
57
- `Cannot use \`resolve(...)\` with a non-absolute pathname or route ID (got "${args[0]}"). ` +
58
- '`resolve` is only for internal pathnames and route IDs; external URLs should be used directly.'
68
+ const [id, params] = /** @type {[string, Record<string, string>?]} */ (args);
69
+
70
+ if (id[0] === '/') {
71
+ // route ID
72
+ if (id.includes('[') && !params) {
73
+ throw new Error(`Missing params for dynamic route ID ${id}`);
74
+ }
75
+
76
+ return (
77
+ /** @type {ResolvedPathname} */ (base + pathname_prefix + resolve_route(id, params ?? {}))
59
78
  );
60
79
  }
61
80
 
62
- // The type error is correct here, and if someone doesn't pass params when they should there's a runtime error,
63
- // but we don't want to adjust the internal resolve_route function to accept `undefined`, hence the type cast.
64
- return (
65
- base + pathname_prefix + resolve_route(args[0], /** @type {Record<string, string>} */ (args[1]))
66
- );
81
+ return /** @type {ResolvedPathname} */ (base + pathname_prefix + '/' + id);
67
82
  }
68
83
 
69
84
  /**
@@ -73,7 +88,7 @@ export function resolve(...args) {
73
88
  * ```js
74
89
  * import { match } from '$app/paths';
75
90
  *
76
- * const route = await match('/blog/hello-world');
91
+ * const route = await match('blog/hello-world');
77
92
  *
78
93
  * if (route?.id === '/blog/[slug]') {
79
94
  * const slug = route.params.slug;
@@ -83,24 +98,9 @@ export function resolve(...args) {
83
98
  * ```
84
99
  * @since 2.52.0
85
100
  *
86
- * @param {Pathname | URL | (string & {})} url
87
- * @returns {Promise<{ id: RouteId, params: Record<string, string> } | null>}
101
+ * @param {URL | string} url
102
+ * @returns {Promise<{ [K in RouteId]: { id: K; params: RouteParams<K>; } }[RouteId] | null>}
88
103
  */
89
- export async function match(url) {
90
- if (typeof url === 'string') {
91
- url = new URL(url, location.href);
92
- }
93
-
94
- const intent = await get_navigation_intent(url, false);
95
-
96
- if (intent) {
97
- return {
98
- id: /** @type {RouteId} */ (intent.route.id),
99
- params: intent.params
100
- };
101
- }
102
-
103
- return null;
104
+ export function match(url) {
105
+ return match_implementation(url);
104
106
  }
105
-
106
- export { base, assets, resolve as resolveRoute };
@@ -1 +1 @@
1
- export * from '#app/paths';
1
+ export { asset, resolve, match } from '#app/paths';
@@ -1,4 +1,36 @@
1
- export const base = __SVELTEKIT_PAYLOAD__?.base ?? __SVELTEKIT_PATHS_BASE__;
2
- export const assets = __SVELTEKIT_PAYLOAD__?.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__;
1
+ // TODO get rid of this module — merge the contents into `../client.js`, and expose it to the
2
+ // rest of the codebase as `#app/paths/client`, with an export condition that errors if
3
+ // it is imported on the server
4
+
5
+ /** @import { RouteId } from '$app/types' */
6
+ import { payload } from '../../../client/payload.js';
7
+
8
+ export const base = payload.base ?? __SVELTEKIT_PATHS_BASE__;
9
+ export const assets = payload.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__;
3
10
  export const app_dir = __SVELTEKIT_APP_DIR__;
4
11
  export const hash_routing = __SVELTEKIT_HASH_ROUTING__;
12
+
13
+ /**
14
+ * We make this configurable per-environment so that it's possible to import `$app/paths`
15
+ * into a service worker without importing the entire client
16
+ * @param {URL | string} _url
17
+ * @returns {Promise<{ [K in RouteId]: { id: K; params: import('$app/types').RouteParams<K>; } }[RouteId] | null>}
18
+ */
19
+ // eslint-disable-next-line @typescript-eslint/require-await
20
+ export let match_implementation = async (_url) => {
21
+ // @ts-ignore
22
+ if (typeof ServiceWorkerGlobalScope !== 'undefined' && self instanceof ServiceWorkerGlobalScope) {
23
+ throw new Error(
24
+ 'Cannot use `match(...)` inside a service worker, as it depends on the SvelteKit client instance'
25
+ );
26
+ }
27
+
28
+ return null;
29
+ };
30
+
31
+ /**
32
+ * @param {typeof match_implementation} fn
33
+ */
34
+ export function set_match_implementation(fn) {
35
+ match_implementation = fn;
36
+ }
@@ -1,30 +1,13 @@
1
- export let base = __SVELTEKIT_PATHS_BASE__;
1
+ // TODO get rid of this module — merge the contents into `../server.js`, and expose it to the
2
+ // rest of the codebase as `#app/paths/server`, with an export condition that errors if
3
+ // it is imported on the client
4
+
5
+ export const base = __SVELTEKIT_PATHS_BASE__;
2
6
  export let assets = __SVELTEKIT_PATHS_ASSETS__ || base;
3
7
  export const app_dir = __SVELTEKIT_APP_DIR__;
4
8
  export const relative = __SVELTEKIT_PATHS_RELATIVE__;
5
9
 
6
- const initial = { base, assets };
7
-
8
- /**
9
- * `base` could be overridden during rendering to be relative;
10
- * this one's the original non-relative base path
11
- */
12
- export const initial_base = initial.base;
13
-
14
- /**
15
- * @param {{ base: string, assets: string }} paths
16
- */
17
- export function override(paths) {
18
- base = paths.base;
19
- assets = paths.assets;
20
- }
21
-
22
- export function reset() {
23
- base = initial.base;
24
- assets = initial.assets;
25
- }
26
-
27
10
  /** @param {string} path */
28
11
  export function set_assets(path) {
29
- assets = initial.assets = path;
12
+ assets = path;
30
13
  }
@@ -0,0 +1,3 @@
1
+ import '../../../types/global-private.js';
2
+
3
+ export * from './client.js';
@@ -1,29 +1 @@
1
- import { RouteIdWithSearchOrHash, PathnameWithSearchOrHash, ResolvedPathname } from '$app/types';
2
- import { ResolveArgs } from './types.js';
3
-
4
- export { resolve, asset, match } from './client.js';
5
-
6
- /**
7
- * A string that matches [`config.kit.paths.base`](https://svelte.dev/docs/kit/configuration#paths).
8
- *
9
- * Example usage: `<a href="{base}/your-page">Link</a>`
10
- *
11
- * @deprecated Use [`resolve(...)`](https://svelte.dev/docs/kit/$app-paths#resolve) instead
12
- */
13
- export let base: '' | `/${string}`;
14
-
15
- /**
16
- * An absolute path that matches [`config.kit.paths.assets`](https://svelte.dev/docs/kit/configuration#paths).
17
- *
18
- * > [!NOTE] If a value for `config.kit.paths.assets` is specified, it will be replaced with `'/_svelte_kit_assets'` during `vite dev` or `vite preview`, since the assets don't yet live at their eventual URL.
19
- *
20
- * @deprecated Use [`asset(...)`](https://svelte.dev/docs/kit/$app-paths#asset) instead
21
- */
22
- export let assets: '' | `https://${string}` | `http://${string}` | '/_svelte_kit_assets';
23
-
24
- /**
25
- * @deprecated Use [`resolve(...)`](https://svelte.dev/docs/kit/$app-paths#resolve) instead
26
- */
27
- export function resolveRoute<T extends RouteIdWithSearchOrHash | PathnameWithSearchOrHash>(
28
- ...args: ResolveArgs<T>
29
- ): ResolvedPathname;
1
+ export { asset, resolve, match } from './client.js';
@@ -1,32 +1,53 @@
1
- import { base, assets, relative, initial_base } from './internal/server.js';
1
+ import { base, assets, relative } from './internal/server.js';
2
2
  import { resolve_route, find_route } from '../../../utils/routing.js';
3
3
  import { decode_pathname } from '../../../utils/url.js';
4
+ import { add_data_suffix } from '../../../pathname.js';
4
5
  import { try_get_request_store } from '@sveltejs/kit/internal/server';
5
- import { manifest } from '__sveltekit/server';
6
+ import { manifest } from '../../server/internal.js';
6
7
  import { get_hooks } from '__SERVER__/internal.js';
8
+ import { DEV } from 'esm-env';
7
9
 
8
- /** @type {import('./client.js').asset} */
10
+ export { base, assets, app_dir } from './internal/server.js';
11
+
12
+ /** @type {typeof import('./client.js').asset} */
9
13
  export function asset(file) {
10
- // @ts-expect-error we use the `resolve` mechanism, but with the 'wrong' input
11
- return assets && assets !== base ? assets + file : resolve(file);
14
+ // TODO 4.0 remove this
15
+ if (file[0] === '/') {
16
+ if (DEV) {
17
+ console.warn(`\`asset('${file}')\` should now be \`asset('${file.slice(1)}')\``);
18
+ }
19
+
20
+ file = file.slice(1);
21
+ }
22
+
23
+ return assets !== base ? `${assets}/${file}` : resolve(file);
12
24
  }
13
25
 
14
- /** @type {import('./client.js').resolve} */
26
+ /** @type {typeof import('./client.js').resolve} */
15
27
  export function resolve(id, params) {
16
- if (!id.startsWith('/')) {
17
- throw new Error(
18
- `Cannot use \`resolve(...)\` with a non-absolute pathname or route ID (got "${id}"). ` +
19
- '`resolve` is only for internal pathnames and route IDs; external URLs should be used directly.'
20
- );
21
- }
28
+ let resolved;
22
29
 
23
- const resolved = resolve_route(id, /** @type {Record<string, string>} */ (params));
30
+ if (id[0] === '/') {
31
+ // route ID
32
+ if (id.includes('[') && !params) {
33
+ throw new Error(`Missing params for dynamic route ID ${id}`);
34
+ }
35
+
36
+ resolved = resolve_route(id, params ?? {});
37
+ } else {
38
+ resolved = '/' + id;
39
+ }
24
40
 
25
41
  if (relative) {
26
42
  const store = try_get_request_store();
27
43
 
28
44
  if (store && !store.state.prerendering?.fallback) {
29
- const after_base = store.event.url.pathname.slice(initial_base.length);
45
+ // the relative path depth must reflect the URL the browser is actually at, which
46
+ // for a data request includes the `__data.json` suffix that was stripped during routing
47
+ const pathname = store.event.isDataRequest
48
+ ? add_data_suffix(store.event.url.pathname)
49
+ : store.event.url.pathname;
50
+ const after_base = pathname.slice(base.length);
30
51
  const segments = after_base.split('/').slice(2);
31
52
  const prefix = segments.map(() => '..').join('/') || '.';
32
53
 
@@ -37,7 +58,7 @@ export function resolve(id, params) {
37
58
  return base + resolved;
38
59
  }
39
60
 
40
- /** @type {import('./client.js').match} */
61
+ /** @type {typeof import('./client.js').match} */
41
62
  export async function match(url) {
42
63
  const store = try_get_request_store();
43
64
 
@@ -74,5 +95,3 @@ export async function match(url) {
74
95
 
75
96
  return null;
76
97
  }
77
-
78
- export { base, assets, resolve as resolveRoute };