@sveltejs/kit 1.0.0-next.315 → 1.0.0-next.316

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.
@@ -432,8 +432,8 @@ function create_client({ target, session, base, trailing_slash }) {
432
432
  /** @type {Map<string, import('./types').NavigationResult>} */
433
433
  const cache = new Map();
434
434
 
435
- /** @type {Set<string>} */
436
- const invalidated = new Set();
435
+ /** @type {Array<((href: string) => boolean)>} */
436
+ const invalidated = [];
437
437
 
438
438
  const stores = {
439
439
  url: notifiable_store({}),
@@ -498,17 +498,28 @@ function create_client({ target, session, base, trailing_slash }) {
498
498
  let router_enabled = true;
499
499
 
500
500
  // keeping track of the history index in order to prevent popstate navigation events if needed
501
- let current_history_index = history.state?.[INDEX_KEY] ?? 0;
501
+ let current_history_index = history.state?.[INDEX_KEY];
502
+
503
+ if (!current_history_index) {
504
+ // we use Date.now() as an offset so that cross-document navigations
505
+ // within the app don't result in data loss
506
+ current_history_index = Date.now();
502
507
 
503
- if (current_history_index === 0) {
504
508
  // create initial history entry, so we can return here
505
- history.replaceState({ ...history.state, [INDEX_KEY]: 0 }, '', location.href);
509
+ history.replaceState(
510
+ { ...history.state, [INDEX_KEY]: current_history_index },
511
+ '',
512
+ location.href
513
+ );
506
514
  }
507
515
 
508
516
  // if we reload the page, or Cmd-Shift-T back to it,
509
517
  // recover scroll position
510
518
  const scroll = scroll_positions[current_history_index];
511
- if (scroll) scrollTo(scroll.x, scroll.y);
519
+ if (scroll) {
520
+ history.scrollRestoration = 'manual';
521
+ scrollTo(scroll.x, scroll.y);
522
+ }
512
523
 
513
524
  let hash_navigating = false;
514
525
 
@@ -603,7 +614,7 @@ function create_client({ target, session, base, trailing_slash }) {
603
614
  // abort if user navigated during update
604
615
  if (token !== current_token) return;
605
616
 
606
- invalidated.clear();
617
+ invalidated.length = 0;
607
618
 
608
619
  if (navigation_result.redirect) {
609
620
  if (redirect_chain.length > 10 || redirect_chain.includes(url.pathname)) {
@@ -994,7 +1005,7 @@ function create_client({ target, session, base, trailing_slash }) {
994
1005
  (changed.url && previous.uses.url) ||
995
1006
  changed.params.some((param) => previous.uses.params.has(param)) ||
996
1007
  (changed.session && previous.uses.session) ||
997
- Array.from(previous.uses.dependencies).some((dep) => invalidated.has(dep)) ||
1008
+ Array.from(previous.uses.dependencies).some((dep) => invalidated.some((fn) => fn(dep))) ||
998
1009
  (stuff_changed && previous.uses.stuff);
999
1010
 
1000
1011
  if (changed_since_last_render) {
@@ -1335,9 +1346,12 @@ function create_client({ target, session, base, trailing_slash }) {
1335
1346
  goto: (href, opts = {}) => goto(href, opts, []),
1336
1347
 
1337
1348
  invalidate: (resource) => {
1338
- const { href } = new URL(resource, location.href);
1339
-
1340
- invalidated.add(href);
1349
+ if (typeof resource === 'function') {
1350
+ invalidated.push(resource);
1351
+ } else {
1352
+ const { href } = new URL(resource, location.href);
1353
+ invalidated.push((dep) => dep === href);
1354
+ }
1341
1355
 
1342
1356
  if (!invalidating) {
1343
1357
  invalidating = Promise.resolve().then(async () => {
@@ -9,7 +9,7 @@ import { s } from './misc.js';
9
9
  import { d as deep_merge } from './object.js';
10
10
  import { n as normalize_path, r as resolve, i as is_root_relative } from './url.js';
11
11
  import { svelte } from '@sveltejs/vite-plugin-svelte';
12
- import { pathToFileURL, URL } from 'url';
12
+ import { pathToFileURL, URL as URL$1 } from 'url';
13
13
  import { installFetch } from '../install-fetch.js';
14
14
  import 'sade';
15
15
  import 'child_process';
@@ -462,6 +462,13 @@ async function build_server(
462
462
  const default_config = {
463
463
  build: {
464
464
  target: 'es2020'
465
+ },
466
+ ssr: {
467
+ // when developing against the Kit src code, we want to ensure that
468
+ // our dependencies are bundled so that apps don't need to install
469
+ // them as peerDependencies
470
+ noExternal: []
471
+
465
472
  }
466
473
  };
467
474
 
@@ -1095,7 +1102,7 @@ async function prerender({ config, entries, files, log }) {
1095
1102
  for (const [dependency_path, result] of dependencies) {
1096
1103
  // this seems circuitous, but using new URL allows us to not care
1097
1104
  // whether dependency_path is encoded or not
1098
- const encoded_dependency_path = new URL(dependency_path, 'http://localhost').pathname;
1105
+ const encoded_dependency_path = new URL$1(dependency_path, 'http://localhost').pathname;
1099
1106
  const decoded_dependency_path = decodeURI(encoded_dependency_path);
1100
1107
 
1101
1108
  const body = result.body ?? new Uint8Array(await result.response.arrayBuffer());
@@ -1117,7 +1124,7 @@ async function prerender({ config, entries, files, log }) {
1117
1124
  const resolved = resolve(encoded, href);
1118
1125
  if (!is_root_relative(resolved)) continue;
1119
1126
 
1120
- const parsed = new URL(resolved, 'http://localhost');
1127
+ const parsed = new URL$1(resolved, 'http://localhost');
1121
1128
 
1122
1129
  if (parsed.search) ;
1123
1130
 
package/dist/cli.js CHANGED
@@ -870,7 +870,7 @@ async function launch(port, https, base) {
870
870
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
871
871
  }
872
872
 
873
- const prog = sade('svelte-kit').version('1.0.0-next.315');
873
+ const prog = sade('svelte-kit').version('1.0.0-next.316');
874
874
 
875
875
  prog
876
876
  .command('dev')
@@ -1049,7 +1049,7 @@ async function check_port(port) {
1049
1049
  function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1050
1050
  if (open) launch(port, https, base);
1051
1051
 
1052
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.315'}\n`));
1052
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.316'}\n`));
1053
1053
 
1054
1054
  const protocol = https ? 'https:' : 'http:';
1055
1055
  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.315",
3
+ "version": "1.0.0-next.316",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -103,9 +103,9 @@ declare module '$app/navigation' {
103
103
  ): Promise<void>;
104
104
  /**
105
105
  * Causes any `load` functions belonging to the currently active page to re-run if they `fetch` the resource in question. Returns a `Promise` that resolves when the page is subsequently updated.
106
- * @param href The invalidated resource
106
+ * @param dependency The invalidated resource
107
107
  */
108
- export function invalidate(href: string): Promise<void>;
108
+ export function invalidate(dependency: string | ((href: string) => boolean)): Promise<void>;
109
109
  /**
110
110
  * Programmatically prefetches the given page, which means
111
111
  * 1. ensuring that the code for the page is loaded, and