@sveltejs/kit 1.16.0 → 1.16.2

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.16.0",
3
+ "version": "1.16.2",
4
4
  "description": "The fastest way to build Svelte apps",
5
5
  "repository": {
6
6
  "type": "git",
@@ -525,6 +525,12 @@ function kit({ svelte_config }) {
525
525
  } else {
526
526
  input['entry/start'] = `${runtime_directory}/client/start.js`;
527
527
  input['entry/app'] = `${kit.outDir}/generated/client-optimized/app.js`;
528
+
529
+ manifest_data.nodes.forEach((node, i) => {
530
+ if (node.component || node.universal) {
531
+ input[`nodes/${i}`] = `${kit.outDir}/generated/client-optimized/nodes/${i}.js`;
532
+ }
533
+ });
528
534
  }
529
535
 
530
536
  // see the kit.output.preloadStrategy option for details on why we have multiple options here
@@ -171,6 +171,9 @@ export function create_client(app, target) {
171
171
  if (navigation_result.type === 'redirect') {
172
172
  return goto(new URL(navigation_result.location, url).href, {}, [url.pathname], nav_token);
173
173
  } else {
174
+ if (navigation_result.props.page !== undefined) {
175
+ page = navigation_result.props.page;
176
+ }
174
177
  root.$set(navigation_result.props);
175
178
  }
176
179
  }
@@ -1122,7 +1125,7 @@ export function create_client(app, target) {
1122
1125
  document.activeElement !== document.body;
1123
1126
 
1124
1127
  if (!keepfocus && !changed_focus) {
1125
- await reset_focus();
1128
+ reset_focus();
1126
1129
  }
1127
1130
 
1128
1131
  autoscroll = true;
@@ -1132,6 +1135,11 @@ export function create_client(app, target) {
1132
1135
  }
1133
1136
 
1134
1137
  navigating = false;
1138
+
1139
+ if (type === 'popstate') {
1140
+ restore_snapshot(current_history_index);
1141
+ }
1142
+
1135
1143
  callbacks.after_navigate.forEach((fn) =>
1136
1144
  fn(/** @type {import('types').AfterNavigate} */ (navigation))
1137
1145
  );
@@ -1635,7 +1643,6 @@ export function create_client(app, target) {
1635
1643
  }
1636
1644
 
1637
1645
  const delta = event.state[INDEX_KEY] - current_history_index;
1638
- let blocked = false;
1639
1646
 
1640
1647
  await navigate({
1641
1648
  url: new URL(location.href),
@@ -1648,15 +1655,10 @@ export function create_client(app, target) {
1648
1655
  },
1649
1656
  blocked: () => {
1650
1657
  history.go(-delta);
1651
- blocked = true;
1652
1658
  },
1653
1659
  type: 'popstate',
1654
1660
  delta
1655
1661
  });
1656
-
1657
- if (!blocked) {
1658
- restore_snapshot(current_history_index);
1659
- }
1660
1662
  }
1661
1663
  });
1662
1664
 
@@ -1737,14 +1739,30 @@ export function create_client(app, target) {
1737
1739
  });
1738
1740
  });
1739
1741
 
1742
+ /** @type {Array<import('./types').BranchNode | undefined>} */
1743
+ const branch = await Promise.all(branch_promises);
1744
+
1745
+ const parsed_route = routes.find(({ id }) => id === route.id);
1746
+
1747
+ // server-side will have compacted the branch, reinstate empty slots
1748
+ // so that error boundaries can be lined up correctly
1749
+ if (parsed_route) {
1750
+ const layouts = parsed_route.layouts;
1751
+ for (let i = 0; i < layouts.length; i++) {
1752
+ if (!layouts[i]) {
1753
+ branch.splice(i, 0, undefined);
1754
+ }
1755
+ }
1756
+ }
1757
+
1740
1758
  result = await get_navigation_result_from_branch({
1741
1759
  url,
1742
1760
  params,
1743
- branch: await Promise.all(branch_promises),
1761
+ branch,
1744
1762
  status,
1745
1763
  error,
1746
1764
  form,
1747
- route: routes.find(({ id }) => id === route.id) ?? null
1765
+ route: parsed_route ?? null
1748
1766
  });
1749
1767
  } catch (error) {
1750
1768
  if (error instanceof Redirect) {
@@ -1899,12 +1917,44 @@ function reset_focus() {
1899
1917
  root.removeAttribute('tabindex');
1900
1918
  }
1901
1919
 
1902
- return new Promise((resolve) => {
1920
+ // capture current selection, so we can compare the state after
1921
+ // snapshot restoration and afterNavigate callbacks have run
1922
+ const selection = getSelection();
1923
+
1924
+ if (selection && selection.type !== 'None') {
1925
+ /** @type {Range[]} */
1926
+ const ranges = [];
1927
+
1928
+ for (let i = 0; i < selection.rangeCount; i += 1) {
1929
+ ranges.push(selection.getRangeAt(i));
1930
+ }
1931
+
1903
1932
  setTimeout(() => {
1933
+ if (selection.rangeCount !== ranges.length) return;
1934
+
1935
+ for (let i = 0; i < selection.rangeCount; i += 1) {
1936
+ const a = ranges[i];
1937
+ const b = selection.getRangeAt(i);
1938
+
1939
+ // we need to do a deep comparison rather than just `a !== b` because
1940
+ // Safari behaves differently to other browsers
1941
+ if (
1942
+ a.commonAncestorContainer !== b.commonAncestorContainer ||
1943
+ a.startContainer !== b.startContainer ||
1944
+ a.endContainer !== b.endContainer ||
1945
+ a.startOffset !== b.startOffset ||
1946
+ a.endOffset !== b.endOffset
1947
+ ) {
1948
+ return;
1949
+ }
1950
+ }
1951
+
1952
+ // if the selection hasn't changed (as a result of an element being (auto)focused,
1953
+ // or a programmatic selection, we reset everything as part of the navigation)
1904
1954
  // fixes https://github.com/sveltejs/kit/issues/8439
1905
- resolve(getSelection()?.removeAllRanges());
1955
+ selection.removeAllRanges();
1906
1956
  });
1907
- });
1957
+ }
1908
1958
  }
1909
1959
  }
1910
1960
 
package/src/utils/url.js CHANGED
@@ -93,9 +93,15 @@ export function decode_uri(uri) {
93
93
  /**
94
94
  * URL properties that could change during the lifetime of the page,
95
95
  * which excludes things like `origin`
96
- * @type {Array<keyof URL>}
97
96
  */
98
- const tracked_url_properties = ['href', 'pathname', 'search', 'searchParams', 'toString', 'toJSON'];
97
+ const tracked_url_properties = /** @type {const} */ ([
98
+ 'href',
99
+ 'pathname',
100
+ 'search',
101
+ 'searchParams',
102
+ 'toString',
103
+ 'toJSON'
104
+ ]);
99
105
 
100
106
  /**
101
107
  * @param {URL} url
@@ -105,12 +111,10 @@ export function make_trackable(url, callback) {
105
111
  const tracked = new URL(url);
106
112
 
107
113
  for (const property of tracked_url_properties) {
108
- let value = tracked[property];
109
-
110
114
  Object.defineProperty(tracked, property, {
111
115
  get() {
112
116
  callback();
113
- return value;
117
+ return url[property];
114
118
  },
115
119
 
116
120
  enumerable: true,