@sveltejs/kit 1.15.5 → 1.15.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.15.5",
3
+ "version": "1.15.6",
4
4
  "description": "The fastest way to build Svelte apps",
5
5
  "repository": {
6
6
  "type": "git",
@@ -57,8 +57,7 @@ export function build_server_nodes(out, kit, manifest_data, server_manifest, cli
57
57
  exports.push(
58
58
  `export const component = async () => (await import('../${
59
59
  resolve_symlinks(server_manifest, node.component).chunk.file
60
- }')).default;`,
61
- `export const file = '${entry.file}';` // TODO what is this?
60
+ }')).default;`
62
61
  );
63
62
  }
64
63
 
@@ -145,12 +145,11 @@ export async function dev(vite, vite_config, svelte_config) {
145
145
 
146
146
  if (node.component) {
147
147
  result.component = async () => {
148
- const { module_node, module, url } = await resolve(
148
+ const { module_node, module } = await resolve(
149
149
  /** @type {string} */ (node.component)
150
150
  );
151
151
 
152
152
  module_nodes.push(module_node);
153
- result.file = url.endsWith('.svelte') ? url : url + '?import'; // TODO what is this for?
154
153
 
155
154
  return module.default;
156
155
  };
@@ -1266,8 +1266,8 @@ export function create_client(app, target) {
1266
1266
  const a = find_anchor(element, container);
1267
1267
  if (!a) return;
1268
1268
 
1269
- const { url, external } = get_link_info(a, base);
1270
- if (external) return;
1269
+ const { url, external, download } = get_link_info(a, base);
1270
+ if (external || download) return;
1271
1271
 
1272
1272
  const options = get_router_options(a);
1273
1273
 
@@ -1300,8 +1300,8 @@ export function create_client(app, target) {
1300
1300
  observer.disconnect();
1301
1301
 
1302
1302
  for (const a of container.querySelectorAll('a')) {
1303
- const { url, external } = get_link_info(a, base);
1304
- if (external) continue;
1303
+ const { url, external, download } = get_link_info(a, base);
1304
+ if (external || download) continue;
1305
1305
 
1306
1306
  const options = get_router_options(a);
1307
1307
  if (options.reload) continue;
@@ -1517,7 +1517,7 @@ export function create_client(app, target) {
1517
1517
  const a = find_anchor(/** @type {Element} */ (event.composedPath()[0]), container);
1518
1518
  if (!a) return;
1519
1519
 
1520
- const { url, external, target } = get_link_info(a, base);
1520
+ const { url, external, target, download } = get_link_info(a, base);
1521
1521
  if (!url) return;
1522
1522
 
1523
1523
  // bail out before `beforeNavigate` if link opens in a different tab
@@ -1545,6 +1545,8 @@ export function create_client(app, target) {
1545
1545
  )
1546
1546
  return;
1547
1547
 
1548
+ if (download) return;
1549
+
1548
1550
  // Ignore the following but fire beforeNavigate
1549
1551
  if (external || options.reload) {
1550
1552
  if (before_navigate({ url, type: 'link' })) {
@@ -133,10 +133,11 @@ export function get_link_info(a, base) {
133
133
  !url ||
134
134
  !!target ||
135
135
  is_external_url(url, base) ||
136
- (a.getAttribute('rel') || '').split(/\s+/).includes('external') ||
137
- a.hasAttribute('download');
136
+ (a.getAttribute('rel') || '').split(/\s+/).includes('external');
138
137
 
139
- return { url, external, target };
138
+ const download = url?.origin === location.origin && a.hasAttribute('download');
139
+
140
+ return { url, external, target, download };
140
141
  }
141
142
 
142
143
  /**
@@ -231,14 +232,18 @@ export function create_updated_store() {
231
232
 
232
233
  if (interval) timeout = setTimeout(check, interval);
233
234
 
234
- const res = await fetch(`${assets}/${__SVELTEKIT_APP_VERSION_FILE__}`, {
235
- headers: {
236
- pragma: 'no-cache',
237
- 'cache-control': 'no-cache'
235
+ try {
236
+ const res = await fetch(`${assets}/${__SVELTEKIT_APP_VERSION_FILE__}`, {
237
+ headers: {
238
+ pragma: 'no-cache',
239
+ 'cache-control': 'no-cache'
240
+ }
241
+ });
242
+
243
+ if (!res.ok) {
244
+ return false;
238
245
  }
239
- });
240
246
 
241
- if (res.ok) {
242
247
  const data = await res.json();
243
248
  const updated = data.version !== version;
244
249
 
@@ -248,8 +253,8 @@ export function create_updated_store() {
248
253
  }
249
254
 
250
255
  return updated;
251
- } else {
252
- throw new Error(`Version check failed: ${res.status}`);
256
+ } catch {
257
+ return false;
253
258
  }
254
259
  }
255
260
 
@@ -72,11 +72,7 @@ export async function handle_action_json_request(event, options, server) {
72
72
  const err = normalize_error(e);
73
73
 
74
74
  if (err instanceof Redirect) {
75
- return action_json({
76
- type: 'redirect',
77
- status: err.status,
78
- location: err.location
79
- });
75
+ return action_json_redirect(err);
80
76
  }
81
77
 
82
78
  return action_json(
@@ -100,6 +96,17 @@ function check_incorrect_fail_use(error) {
100
96
  : error;
101
97
  }
102
98
 
99
+ /**
100
+ * @param {import('types').Redirect} redirect
101
+ */
102
+ export function action_json_redirect(redirect) {
103
+ return action_json({
104
+ type: 'redirect',
105
+ status: redirect.status,
106
+ location: redirect.location
107
+ });
108
+ }
109
+
103
110
  /**
104
111
  * @param {import('types').ActionResult} data
105
112
  * @param {ResponseInit} [init]
@@ -95,23 +95,12 @@ export async function render_response({
95
95
 
96
96
  // if appropriate, use relative paths for greater portability
97
97
  if (paths.relative !== false && !state.prerendering?.fallback) {
98
- const segments = event.url.pathname.slice(paths.base.length).split('/');
98
+ const segments = event.url.pathname.slice(paths.base.length).split('/').slice(2);
99
99
 
100
- if (segments.length === 1 && paths.base !== '') {
101
- // if we're on `/my-base-path`, relative links need to start `./my-base-path` rather than `.`
102
- base = `./${paths.base.split('/').at(-1)}`;
100
+ base = segments.map(() => '..').join('/') || '.';
103
101
 
104
- base_expression = `new URL(${s(base)}, location).pathname`;
105
- } else {
106
- base =
107
- segments
108
- .slice(2)
109
- .map(() => '..')
110
- .join('/') || '.';
111
-
112
- // resolve e.g. '../..' against current location, then remove trailing slash
113
- base_expression = `new URL(${s(base)}, location).pathname.slice(0, -1)`;
114
- }
102
+ // resolve e.g. '../..' against current location, then remove trailing slash
103
+ base_expression = `new URL(${s(base)}, location).pathname.slice(0, -1)`;
115
104
 
116
105
  if (!paths.assets || (paths.assets[0] === '/' && paths.assets !== SVELTE_KIT_ASSETS)) {
117
106
  assets = base;
@@ -26,6 +26,7 @@ import {
26
26
  } from '../../utils/exports.js';
27
27
  import { get_option } from '../../utils/options.js';
28
28
  import { error, json, text } from '../../exports/index.js';
29
+ import { action_json_redirect, is_action_json_request } from './page/actions.js';
29
30
 
30
31
  /* global __SVELTEKIT_ADAPTER_NAME__ */
31
32
 
@@ -175,7 +176,11 @@ export async function respond(request, options, manifest, state) {
175
176
  try {
176
177
  // determine whether we need to redirect to add/remove a trailing slash
177
178
  if (route && !is_data_request) {
178
- if (route.page) {
179
+ // if `paths.base === '/a/b/c`, then the root route is `/a/b/c/`,
180
+ // regardless of the `trailingSlash` route option
181
+ if (url.pathname === base || url.pathname === base + '/') {
182
+ trailing_slash = 'always';
183
+ } else if (route.page) {
179
184
  const nodes = await Promise.all([
180
185
  // we use == here rather than === because [undefined] serializes as "[null]"
181
186
  ...route.page.layouts.map((n) => (n == undefined ? n : manifest._.nodes[n]())),
@@ -309,6 +314,8 @@ export async function respond(request, options, manifest, state) {
309
314
  if (e instanceof Redirect) {
310
315
  const response = is_data_request
311
316
  ? redirect_json_response(e)
317
+ : route?.page && is_action_json_request(event)
318
+ ? action_json_redirect(e)
312
319
  : redirect_response(e.status, e.location);
313
320
  add_cookies_to_headers(response.headers, Object.values(cookies_to_add));
314
321
  return response;
@@ -290,8 +290,6 @@ export interface SSRNode {
290
290
  component: SSRComponentLoader;
291
291
  /** index into the `components` array in client/manifest.js */
292
292
  index: number;
293
- /** client-side module URL for this component */
294
- file: string;
295
293
  /** external JS files */
296
294
  imports: string[];
297
295
  /** external CSS files */