@sveltejs/kit 1.0.0-next.251 → 1.0.0-next.255

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.
@@ -33,7 +33,8 @@ const getStores = () => {
33
33
  subscribe: stores.navigating.subscribe
34
34
  };
35
35
  },
36
- session: stores.session
36
+ session: stores.session,
37
+ updated: stores.updated
37
38
  };
38
39
  };
39
40
 
@@ -79,4 +80,18 @@ const session = {
79
80
  update: () => throw_error('update')
80
81
  };
81
82
 
82
- export { getStores, navigating, page, session, stores };
83
+ /** @type {typeof import('$app/stores').updated} */
84
+ const updated = {
85
+ subscribe(fn) {
86
+ const store = getStores().updated;
87
+
88
+ if (browser) {
89
+ updated.check = store.check;
90
+ }
91
+
92
+ return store.subscribe(fn);
93
+ },
94
+ check: () => throw_error('check')
95
+ };
96
+
97
+ export { getStores, navigating, page, session, stores, updated };
@@ -3,8 +3,8 @@ import { fallback, routes } from '__GENERATED__/manifest.js';
3
3
  import { onMount, tick } from 'svelte';
4
4
  import { g as get_base_uri } from '../chunks/utils.js';
5
5
  import { writable } from 'svelte/store';
6
+ import { base, set_paths } from '../paths.js';
6
7
  import { init } from './singletons.js';
7
- import { set_paths } from '../paths.js';
8
8
 
9
9
  function scroll_state() {
10
10
  return {
@@ -553,6 +553,56 @@ function notifiable_store(value) {
553
553
  return { notify, set, subscribe };
554
554
  }
555
555
 
556
+ function create_updated_store() {
557
+ const { set, subscribe } = writable(false);
558
+
559
+ const interval = +(
560
+ /** @type {string} */ (import.meta.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL)
561
+ );
562
+ const initial = import.meta.env.VITE_SVELTEKIT_APP_VERSION;
563
+
564
+ /** @type {NodeJS.Timeout} */
565
+ let timeout;
566
+
567
+ async function check() {
568
+ if (import.meta.env.DEV || import.meta.env.SSR) return false;
569
+
570
+ clearTimeout(timeout);
571
+
572
+ if (interval) timeout = setTimeout(check, interval);
573
+
574
+ const file = import.meta.env.VITE_SVELTEKIT_APP_VERSION_FILE;
575
+
576
+ const res = await fetch(`${base}/${file}`, {
577
+ headers: {
578
+ pragma: 'no-cache',
579
+ 'cache-control': 'no-cache'
580
+ }
581
+ });
582
+
583
+ if (res.ok) {
584
+ const { version } = await res.json();
585
+ const updated = version !== initial;
586
+
587
+ if (updated) {
588
+ set(true);
589
+ clearTimeout(timeout);
590
+ }
591
+
592
+ return updated;
593
+ } else {
594
+ throw new Error(`Version check failed: ${res.status}`);
595
+ }
596
+ }
597
+
598
+ if (interval) timeout = setTimeout(check, interval);
599
+
600
+ return {
601
+ subscribe,
602
+ check
603
+ };
604
+ }
605
+
556
606
  /**
557
607
  * @param {RequestInfo} resource
558
608
  * @param {RequestInit} [opts]
@@ -622,7 +672,8 @@ class Renderer {
622
672
  url: notifiable_store({}),
623
673
  page: notifiable_store({}),
624
674
  navigating: writable(/** @type {Navigating | null} */ (null)),
625
- session: writable(session)
675
+ session: writable(session),
676
+ updated: create_updated_store()
626
677
  };
627
678
 
628
679
  this.$session = null;
@@ -788,6 +839,12 @@ class Renderer {
788
839
  location.href = new URL(navigation_result.redirect, location.href).href;
789
840
  }
790
841
 
842
+ return;
843
+ }
844
+ } else if (navigation_result.props?.page?.status >= 400) {
845
+ const updated = await this.stores.updated.check();
846
+ if (updated) {
847
+ location.href = info.url.href;
791
848
  return;
792
849
  }
793
850
  }
@@ -413,6 +413,16 @@ function safe_not_equal(a, b) {
413
413
  Promise.resolve();
414
414
 
415
415
  const subscriber_queue = [];
416
+ /**
417
+ * Creates a `Readable` store that allows reading by subscription.
418
+ * @param value initial value
419
+ * @param {StartStopNotifier}start start and stop notifications for subscriptions
420
+ */
421
+ function readable(value, start) {
422
+ return {
423
+ subscribe: writable(value, start).subscribe
424
+ };
425
+ }
416
426
  /**
417
427
  * Create a `Writable` store that allows both updating and reading by subscription.
418
428
  * @param {*=}value initial value
@@ -1015,6 +1025,11 @@ class Csp {
1015
1025
 
1016
1026
  // TODO rename this function/module
1017
1027
 
1028
+ const updated = {
1029
+ ...readable(false),
1030
+ check: () => false
1031
+ };
1032
+
1018
1033
  /**
1019
1034
  * @param {{
1020
1035
  * branch: Array<import('./types').Loaded>;
@@ -1091,7 +1106,8 @@ async function render_response({
1091
1106
  stores: {
1092
1107
  page: writable(null),
1093
1108
  navigating: writable(null),
1094
- session
1109
+ session,
1110
+ updated
1095
1111
  },
1096
1112
  page: {
1097
1113
  url: state.prerender ? create_prerendering_url_proxy(url) : url,
@@ -1535,6 +1551,15 @@ async function load_node({
1535
1551
 
1536
1552
  opts.headers = new Headers(opts.headers);
1537
1553
 
1554
+ // merge headers from request
1555
+ for (const [key, value] of event.request.headers) {
1556
+ if (opts.headers.has(key)) continue;
1557
+ if (key === 'cookie' || key === 'authorization' || key === 'if-none-match') continue;
1558
+ opts.headers.set(key, value);
1559
+ }
1560
+
1561
+ opts.headers.set('referer', event.url.href);
1562
+
1538
1563
  const resolved = resolve(event.url.pathname, requested.split('?')[0]);
1539
1564
 
1540
1565
  /** @type {Response} */
@@ -1650,10 +1675,10 @@ async function load_node({
1650
1675
  if (!opts.body || typeof opts.body === 'string') {
1651
1676
  // prettier-ignore
1652
1677
  fetched.push({
1653
- url: requested,
1654
- body: /** @type {string} */ (opts.body),
1655
- json: `{"status":${response.status},"statusText":${s(response.statusText)},"headers":${s(headers)},"body":"${escape_json_string_in_html(body)}"}`
1656
- });
1678
+ url: requested,
1679
+ body: /** @type {string} */ (opts.body),
1680
+ json: `{"status":${response.status},"statusText":${s(response.statusText)},"headers":${s(headers)},"body":"${escape_json_string_in_html(body)}"}`
1681
+ });
1657
1682
  }
1658
1683
 
1659
1684
  if (dependency) {