@sveltejs/kit 2.0.8 → 2.1.1

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.0.8",
3
+ "version": "2.1.1",
4
4
  "description": "The fastest way to build Svelte apps",
5
5
  "repository": {
6
6
  "type": "git",
@@ -349,6 +349,7 @@ export interface KitConfig {
349
349
  };
350
350
  /**
351
351
  * Whether or not the app is embedded inside a larger app. If `true`, SvelteKit will add its event listeners related to navigation etc on the parent of `%sveltekit.body%` instead of `window`, and will pass `params` from the server rather than inferring them from `location.pathname`.
352
+ * Note that it is generally not supported to embed multiple SvelteKit apps on the same page and use client-side SvelteKit features within them (things such as pushing to the history state assume a single instance).
352
353
  * @default false
353
354
  */
354
355
  embedded?: boolean;
@@ -116,7 +116,7 @@ export async function dev(vite, vite_config, svelte_config) {
116
116
  mimeTypes: get_mime_lookup(manifest_data),
117
117
  _: {
118
118
  client: {
119
- start: `${runtime_base}/client/start.js`,
119
+ start: `${runtime_base}/client/entry.js`,
120
120
  app: `${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`,
121
121
  imports: [],
122
122
  stylesheets: [],
@@ -555,7 +555,7 @@ async function kit({ svelte_config }) {
555
555
  input[name] = path.resolve(file);
556
556
  });
557
557
  } else {
558
- input['entry/start'] = `${runtime_directory}/client/start.js`;
558
+ input['entry/start'] = `${runtime_directory}/client/entry.js`;
559
559
  input['entry/app'] = `${kit.outDir}/generated/client-optimized/app.js`;
560
560
 
561
561
  manifest_data.nodes.forEach((node, i) => {
@@ -619,7 +619,7 @@ async function kit({ svelte_config }) {
619
619
  rollupOptions: {
620
620
  // Vite dependency crawler needs an explicit JS entry point
621
621
  // eventhough server otherwise works without it
622
- input: `${runtime_directory}/client/start.js`
622
+ input: `${runtime_directory}/client/entry.js`
623
623
  }
624
624
  },
625
625
  publicDir: kit.files.assets
@@ -757,7 +757,7 @@ async function kit({ svelte_config }) {
757
757
 
758
758
  const deps_of = /** @param {string} f */ (f) =>
759
759
  find_deps(client_manifest, posixify(path.relative('.', f)), false);
760
- const start = deps_of(`${runtime_directory}/client/start.js`);
760
+ const start = deps_of(`${runtime_directory}/client/entry.js`);
761
761
  const app = deps_of(`${kit.outDir}/generated/client-optimized/app.js`);
762
762
 
763
763
  build_data.client = {
@@ -1,23 +1,9 @@
1
1
  import * as devalue from 'devalue';
2
- import { BROWSER, DEV } from 'esm-env';
3
- import { client } from '../client/singletons.js';
2
+ import { DEV } from 'esm-env';
4
3
  import { invalidateAll } from './navigation.js';
4
+ import { applyAction } from '../client/client.js';
5
5
 
6
- /**
7
- * This action updates the `form` property of the current page with the given data and updates `$page.status`.
8
- * In case of an error, it redirects to the nearest error page.
9
- * @template {Record<string, unknown> | undefined} Success
10
- * @template {Record<string, unknown> | undefined} Failure
11
- * @param {import('@sveltejs/kit').ActionResult<Success, Failure>} result
12
- * @returns {Promise<void>}
13
- */
14
- export function applyAction(result) {
15
- if (BROWSER) {
16
- return client.apply_action(result);
17
- } else {
18
- throw new Error('Cannot call applyAction(...) on the server');
19
- }
20
- }
6
+ export { applyAction };
21
7
 
22
8
  /**
23
9
  * Use this function to deserialize the response from a form submission.
@@ -1,142 +1,13 @@
1
- import { client_method } from '../client/singletons.js';
2
-
3
- /**
4
- * If called when the page is being updated following a navigation (in `onMount` or `afterNavigate` or an action, for example), this disables SvelteKit's built-in scroll handling.
5
- * This is generally discouraged, since it breaks user expectations.
6
- * @returns {void}
7
- */
8
- export const disableScrollHandling = /* @__PURE__ */ client_method('disable_scroll_handling');
9
-
10
- /**
11
- * Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `url`.
12
- * For external URLs, use `window.location = url` instead of calling `goto(url)`.
13
- *
14
- * @type {(url: string | URL, opts?: { replaceState?: boolean; noScroll?: boolean; keepFocus?: boolean; invalidateAll?: boolean; state?: App.PageState }) => Promise<void>}
15
- * @param {string | URL} url Where to navigate to. Note that if you've set [`config.kit.paths.base`](https://kit.svelte.dev/docs/configuration#paths) and the URL is root-relative, you need to prepend the base path if you want to navigate within the app.
16
- * @param {Object} [opts] Options related to the navigation
17
- * @param {boolean} [opts.replaceState] If `true`, will replace the current `history` entry rather than creating a new one with `pushState`
18
- * @param {boolean} [opts.noScroll] If `true`, the browser will maintain its scroll position rather than scrolling to the top of the page after navigation
19
- * @param {boolean} [opts.keepFocus] If `true`, the currently focused element will retain focus after navigation. Otherwise, focus will be reset to the body
20
- * @param {boolean} [opts.invalidateAll] If `true`, all `load` functions of the page will be rerun. See https://kit.svelte.dev/docs/load#rerunning-load-functions for more info on invalidation.
21
- * @param {App.PageState} [opts.state] An optional object that will be available on the `$page.state` store
22
- * @returns {Promise<void>}
23
- */
24
- export const goto = /* @__PURE__ */ client_method('goto');
25
-
26
- /**
27
- * Causes any `load` functions belonging to the currently active page to re-run if they depend on the `url` in question, via `fetch` or `depends`. Returns a `Promise` that resolves when the page is subsequently updated.
28
- *
29
- * If the argument is given as a `string` or `URL`, it must resolve to the same URL that was passed to `fetch` or `depends` (including query parameters).
30
- * To create a custom identifier, use a string beginning with `[a-z]+:` (e.g. `custom:state`) — this is a valid URL.
31
- *
32
- * The `function` argument can be used define a custom predicate. It receives the full `URL` and causes `load` to rerun if `true` is returned.
33
- * This can be useful if you want to invalidate based on a pattern instead of a exact match.
34
- *
35
- * ```ts
36
- * // Example: Match '/path' regardless of the query parameters
37
- * import { invalidate } from '$app/navigation';
38
- *
39
- * invalidate((url) => url.pathname === '/path');
40
- * ```
41
- * @type {(url: string | URL | ((url: URL) => boolean)) => Promise<void>}
42
- * @param {string | URL | ((url: URL) => boolean)} url The invalidated URL
43
- * @returns {Promise<void>}
44
- */
45
- export const invalidate = /* @__PURE__ */ client_method('invalidate');
46
-
47
- /**
48
- * Causes all `load` functions belonging to the currently active page to re-run. Returns a `Promise` that resolves when the page is subsequently updated.
49
- * @type {() => Promise<void>}
50
- * @returns {Promise<void>}
51
- */
52
- export const invalidateAll = /* @__PURE__ */ client_method('invalidate_all');
53
-
54
- /**
55
- * Programmatically preloads the given page, which means
56
- * 1. ensuring that the code for the page is loaded, and
57
- * 2. calling the page's load function with the appropriate options.
58
- *
59
- * This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with `data-sveltekit-preload-data`.
60
- * If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous.
61
- * Returns a Promise that resolves with the result of running the new route's `load` functions once the preload is complete.
62
- *
63
- * @type {(href: string) => Promise<Record<string, any>>}
64
- * @param {string} href Page to preload
65
- * @returns {Promise<{ type: 'loaded'; status: number; data: Record<string, any> } | { type: 'redirect'; location: string }>}
66
- */
67
- export const preloadData = /* @__PURE__ */ client_method('preload_data');
68
-
69
- /**
70
- * Programmatically imports the code for routes that haven't yet been fetched.
71
- * Typically, you might call this to speed up subsequent navigation.
72
- *
73
- * You can specify routes by any matching pathname such as `/about` (to match `src/routes/about/+page.svelte`) or `/blog/*` (to match `src/routes/blog/[slug]/+page.svelte`).
74
- *
75
- * Unlike `preloadData`, this won't call `load` functions.
76
- * Returns a Promise that resolves when the modules have been imported.
77
- *
78
- * @type {(url: string) => Promise<void>}
79
- * @param {string} url
80
- * @returns {Promise<void>}
81
- */
82
- export const preloadCode = /* @__PURE__ */ client_method('preload_code');
83
-
84
- /**
85
- * A navigation interceptor that triggers before we navigate to a new URL, whether by clicking a link, calling `goto(...)`, or using the browser back/forward controls.
86
- *
87
- * Calling `cancel()` will prevent the navigation from completing. If `navigation.type === 'leave'` — meaning the user is navigating away from the app (or closing the tab) — calling `cancel` will trigger the native browser unload confirmation dialog. In this case, the navigation may or may not be cancelled depending on the user's response.
88
- *
89
- * When a navigation isn't to a SvelteKit-owned route (and therefore controlled by SvelteKit's client-side router), `navigation.to.route.id` will be `null`.
90
- *
91
- * If the navigation will (if not cancelled) cause the document to unload — in other words `'leave'` navigations and `'link'` navigations where `navigation.to.route === null` — `navigation.willUnload` is `true`.
92
- *
93
- * `beforeNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
94
- * @type {(callback: (navigation: import('@sveltejs/kit').BeforeNavigate) => void) => void}
95
- * @param {(navigation: import('@sveltejs/kit').BeforeNavigate) => void} callback
96
- * @returns {void}
97
- */
98
- export const beforeNavigate = /* @__PURE__ */ client_method('before_navigate');
99
-
100
- /**
101
- * A lifecycle function that runs the supplied `callback` immediately before we navigate to a new URL except during full-page navigations.
102
- *
103
- * If you return a `Promise`, SvelteKit will wait for it to resolve before completing the navigation. This allows you to — for example — use `document.startViewTransition`. Avoid promises that are slow to resolve, since navigation will appear stalled to the user.
104
- *
105
- * If a function (or a `Promise` that resolves to a function) is returned from the callback, it will be called once the DOM has updated.
106
- *
107
- * `onNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
108
- * @type {(callback: (navigation: import('@sveltejs/kit').OnNavigate) => import('types').MaybePromise<(() => void) | void>) => void}
109
- * @param {(navigation: import('@sveltejs/kit').OnNavigate) => void} callback
110
- * @returns {void}
111
- */
112
- export const onNavigate = /* @__PURE__ */ client_method('on_navigate');
113
-
114
- /**
115
- * A lifecycle function that runs the supplied `callback` when the current component mounts, and also whenever we navigate to a new URL.
116
- *
117
- * `afterNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
118
- * @type {(callback: (navigation: import('@sveltejs/kit').AfterNavigate) => void) => void}
119
- * @param {(navigation: import('@sveltejs/kit').AfterNavigate) => void} callback
120
- * @returns {void}
121
- */
122
- export const afterNavigate = /* @__PURE__ */ client_method('after_navigate');
123
-
124
- /**
125
- * Programmatically create a new history entry with the given `$page.state`. To use the current URL, you can pass `''` as the first argument. Used for [shallow routing](https://kit.svelte.dev/docs/shallow-routing).
126
- *
127
- * @type {(url: string | URL, state: App.PageState) => void}
128
- * @param {string | URL} url
129
- * @param {App.PageState} state
130
- * @returns {void}
131
- */
132
- export const pushState = /* @__PURE__ */ client_method('push_state');
133
-
134
- /**
135
- * Programmatically replace the current history entry with the given `$page.state`. To use the current URL, you can pass `''` as the first argument. Used for [shallow routing](https://kit.svelte.dev/docs/shallow-routing).
136
- *
137
- * @type {(url: string | URL, state: App.PageState) => void}
138
- * @param {string | URL} url
139
- * @param {App.PageState} state
140
- * @returns {void}
141
- */
142
- export const replaceState = /* @__PURE__ */ client_method('replace_state');
1
+ export {
2
+ afterNavigate,
3
+ beforeNavigate,
4
+ disableScrollHandling,
5
+ goto,
6
+ invalidate,
7
+ invalidateAll,
8
+ onNavigate,
9
+ preloadCode,
10
+ preloadData,
11
+ pushState,
12
+ replaceState
13
+ } from '../client/client.js';
@@ -1,13 +1,13 @@
1
1
  import { getContext } from 'svelte';
2
- import { browser } from './environment.js';
3
- import { stores as browser_stores } from '../client/singletons.js';
2
+ import { BROWSER } from 'esm-env';
3
+ import { stores as browser_stores } from '../client/client.js';
4
4
 
5
5
  /**
6
6
  * A function that returns all of the contextual stores. On the server, this must be called during component initialization.
7
7
  * Only use this if you need to defer store subscription until after the component has mounted, for some reason.
8
8
  */
9
9
  export const getStores = () => {
10
- const stores = browser ? browser_stores : getContext('__svelte__');
10
+ const stores = BROWSER ? browser_stores : getContext('__svelte__');
11
11
 
12
12
  return {
13
13
  /** @type {typeof page} */
@@ -62,7 +62,7 @@ export const updated = {
62
62
  subscribe(fn) {
63
63
  const store = __SVELTEKIT_DEV__ ? get_store('updated') : getStores().updated;
64
64
 
65
- if (browser) {
65
+ if (BROWSER) {
66
66
  updated.check = store.check;
67
67
  }
68
68
 
@@ -70,7 +70,7 @@ export const updated = {
70
70
  },
71
71
  check: () => {
72
72
  throw new Error(
73
- browser
73
+ BROWSER
74
74
  ? 'Cannot check updated store before subscribing'
75
75
  : 'Can only check updated store in browser'
76
76
  );