@sveltejs/kit 1.0.0-next.282 → 1.0.0-next.285

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.
@@ -8,7 +8,7 @@ import { init } from './singletons.js';
8
8
 
9
9
  /**
10
10
  * @param {string} path
11
- * @param {'always' | 'never' | 'ignore'} trailing_slash
11
+ * @param {import('types').TrailingSlash} trailing_slash
12
12
  */
13
13
  function normalize_path(path, trailing_slash) {
14
14
  if (path === '/' || trailing_slash === 'ignore') return path;
@@ -200,6 +200,7 @@ class Router {
200
200
 
201
201
  if (!a.href) return;
202
202
 
203
+ const is_svg_a_element = a instanceof SVGAElement;
203
204
  const url = get_href(a);
204
205
  const url_string = url.toString();
205
206
  if (url_string === location.href) {
@@ -207,6 +208,11 @@ class Router {
207
208
  return;
208
209
  }
209
210
 
211
+ // Ignore if url does not have origin (e.g. `mailto:`, `tel:`.)
212
+ // MEMO: Without this condition, firefox will open mailer twice.
213
+ // See: https://github.com/sveltejs/kit/issues/4045
214
+ if (!is_svg_a_element && url.origin === 'null') return;
215
+
210
216
  // Ignore if tag has
211
217
  // 1. 'download' attribute
212
218
  // 2. 'rel' attribute includes external
@@ -217,7 +223,7 @@ class Router {
217
223
  }
218
224
 
219
225
  // Ignore if <a> has a target
220
- if (a instanceof SVGAElement ? a.target.baseVal : a.target) return;
226
+ if (is_svg_a_element ? a.target.baseVal : a.target) return;
221
227
 
222
228
  // Check if new url only differs by hash and use the browser default behavior in that case
223
229
  // This will ensure the `hashchange` event is fired
@@ -439,20 +445,13 @@ class Router {
439
445
 
440
446
  accepted();
441
447
 
442
- if (!this.navigating) {
443
- dispatchEvent(new CustomEvent('sveltekit:navigation-start'));
444
- }
445
448
  this.navigating++;
446
449
 
447
450
  const pathname = normalize_path(url.pathname, this.trailing_slash);
448
451
 
449
452
  info.url = new URL(url.origin + pathname + url.search + url.hash);
450
453
 
451
- if (details) {
452
- const change = details.replaceState ? 0 : 1;
453
- details.state['sveltekit:index'] = this.current_history_index += change;
454
- history[details.replaceState ? 'replaceState' : 'pushState'](details.state, '', info.url);
455
- }
454
+ const token = (this.navigating_token = {});
456
455
 
457
456
  await this.renderer.handle_navigation(info, chain, false, {
458
457
  scroll,
@@ -460,12 +459,19 @@ class Router {
460
459
  });
461
460
 
462
461
  this.navigating--;
463
- if (!this.navigating) {
464
- dispatchEvent(new CustomEvent('sveltekit:navigation-end'));
465
462
 
463
+ // navigation was aborted
464
+ if (this.navigating_token !== token) return;
465
+ if (!this.navigating) {
466
466
  const navigation = { from, to: url };
467
467
  this.callbacks.after_navigate.forEach((fn) => fn(navigation));
468
468
  }
469
+
470
+ if (details) {
471
+ const change = details.replaceState ? 0 : 1;
472
+ details.state['sveltekit:index'] = this.current_history_index += change;
473
+ history[details.replaceState ? 'replaceState' : 'pushState'](details.state, '', info.url);
474
+ }
469
475
  }
470
476
  }
471
477
 
@@ -892,11 +898,10 @@ class Renderer {
892
898
  });
893
899
  } else {
894
900
  if (this.router) {
895
- this.router.goto(
896
- new URL(navigation_result.redirect, info.url).href,
897
- { replaceState: true },
898
- [...chain, info.url.pathname]
899
- );
901
+ this.router.goto(new URL(navigation_result.redirect, info.url).href, {}, [
902
+ ...chain,
903
+ info.url.pathname
904
+ ]);
900
905
  } else {
901
906
  location.href = new URL(navigation_result.redirect, location.href).href;
902
907
  }
@@ -1305,7 +1305,7 @@ async function render_response({
1305
1305
  }
1306
1306
  }
1307
1307
 
1308
- if (state.prerender) {
1308
+ if (state.prerender && !options.amp) {
1309
1309
  const http_equiv = [];
1310
1310
 
1311
1311
  const csp_headers = csp.get_meta();
@@ -1491,7 +1491,7 @@ function is_root_relative(path) {
1491
1491
 
1492
1492
  /**
1493
1493
  * @param {string} path
1494
- * @param {'always' | 'never' | 'ignore'} trailing_slash
1494
+ * @param {import('types').TrailingSlash} trailing_slash
1495
1495
  */
1496
1496
  function normalize_path(path, trailing_slash) {
1497
1497
  if (path === '/' || trailing_slash === 'ignore') return path;
@@ -1637,8 +1637,6 @@ async function load_node({
1637
1637
  }
1638
1638
  }
1639
1639
 
1640
- opts.headers.set('referer', event.url.href);
1641
-
1642
1640
  const resolved = resolve(event.url.pathname, requested.split('?')[0]);
1643
1641
 
1644
1642
  /** @type {Response} */
@@ -1844,7 +1842,7 @@ async function load_node({
1844
1842
 
1845
1843
  // generate __data.json files when prerendering
1846
1844
  if (shadow.body && state.prerender) {
1847
- const pathname = `${event.url.pathname}/__data.json`;
1845
+ const pathname = `${event.url.pathname.replace(/\/$/, '')}/__data.json`;
1848
1846
 
1849
1847
  const dependency = {
1850
1848
  response: new Response(undefined),
@@ -57,7 +57,7 @@ function is_root_relative(path) {
57
57
 
58
58
  /**
59
59
  * @param {string} path
60
- * @param {'always' | 'never' | 'ignore'} trailing_slash
60
+ * @param {import('types').TrailingSlash} trailing_slash
61
61
  */
62
62
  function normalize_path(path, trailing_slash) {
63
63
  if (path === '/' || trailing_slash === 'ignore') return path;
package/dist/cli.js CHANGED
@@ -998,7 +998,7 @@ async function launch(port, https) {
998
998
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
999
999
  }
1000
1000
 
1001
- const prog = sade('svelte-kit').version('1.0.0-next.282');
1001
+ const prog = sade('svelte-kit').version('1.0.0-next.285');
1002
1002
 
1003
1003
  prog
1004
1004
  .command('dev')
@@ -1156,7 +1156,7 @@ async function check_port(port) {
1156
1156
  function welcome({ port, host, https, open, loose, allow, cwd }) {
1157
1157
  if (open) launch(port, https);
1158
1158
 
1159
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.282'}\n`));
1159
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.285'}\n`));
1160
1160
 
1161
1161
  const protocol = https ? 'https:' : 'http:';
1162
1162
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.282",
3
+ "version": "1.0.0-next.285",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "devDependencies": {
18
18
  "@playwright/test": "^1.17.1",
19
- "@rollup/plugin-replace": "^3.0.0",
19
+ "@rollup/plugin-replace": "^4.0.0",
20
20
  "@types/amphtml-validator": "^1.0.1",
21
21
  "@types/cookie": "^0.4.1",
22
22
  "@types/marked": "^4.0.1",
@@ -1,5 +1,3 @@
1
- /* eslint-disable import/no-duplicates */
2
-
3
1
  declare namespace App {
4
2
  interface Locals {}
5
3
  interface Platform {}
package/types/index.d.ts CHANGED
@@ -1,24 +1,25 @@
1
1
  /// <reference types="svelte" />
2
2
  /// <reference types="vite/client" />
3
3
 
4
+ import './ambient';
5
+
4
6
  import { CompileOptions } from 'svelte/types/compiler/interfaces';
5
7
  import {
6
- Logger,
7
- PrerenderOnErrorValue,
8
- SSRNodeLoader,
9
- SSRRoute,
10
- TrailingSlash,
8
+ AdapterEntry,
9
+ Body,
11
10
  Either,
11
+ Fallthrough,
12
+ Logger,
12
13
  MaybePromise,
14
+ PrerenderOnErrorValue,
13
15
  RecursiveRequired,
14
- RouteDefinition,
15
- AdapterEntry,
16
- ResponseHeaders,
17
- Fallthrough,
18
16
  RequiredResolveOptions,
19
- Body
17
+ ResponseHeaders,
18
+ RouteDefinition,
19
+ SSRNodeLoader,
20
+ SSRRoute,
21
+ TrailingSlash
20
22
  } from './internal';
21
- import './ambient';
22
23
 
23
24
  export interface Adapter {
24
25
  name: string;
@@ -31,7 +32,7 @@ export interface Builder {
31
32
  mkdirp(dir: string): void;
32
33
 
33
34
  appDir: string;
34
- trailingSlash: 'always' | 'never' | 'ignore';
35
+ trailingSlash: TrailingSlash;
35
36
 
36
37
  /**
37
38
  * Create entry points that map to individual functions
@@ -171,7 +172,7 @@ export namespace Csp {
171
172
  type BaseSource = 'self' | 'unsafe-eval' | 'unsafe-hashes' | 'unsafe-inline' | 'none';
172
173
  type CryptoSource = `${'nonce' | 'sha256' | 'sha384' | 'sha512'}-${string}`;
173
174
  type FrameSource = HostSource | SchemeSource | 'self' | 'none';
174
- type HostNameScheme = `${string}.${string}` | `localhost`;
175
+ type HostNameScheme = `${string}.${string}` | 'localhost';
175
176
  type HostSource = `${HostProtocolSchemes}${HostNameScheme}${PortScheme}`;
176
177
  type HostProtocolSchemes = `${string}://` | '';
177
178
  type HttpDelineator = '/' | '?' | '#' | '\\';