@sveltejs/kit 1.16.1 → 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 +1 -1
- package/src/runtime/client/client.js +41 -10
- package/src/utils/url.js +9 -5
package/package.json
CHANGED
|
@@ -1125,7 +1125,7 @@ export function create_client(app, target) {
|
|
|
1125
1125
|
document.activeElement !== document.body;
|
|
1126
1126
|
|
|
1127
1127
|
if (!keepfocus && !changed_focus) {
|
|
1128
|
-
|
|
1128
|
+
reset_focus();
|
|
1129
1129
|
}
|
|
1130
1130
|
|
|
1131
1131
|
autoscroll = true;
|
|
@@ -1135,6 +1135,11 @@ export function create_client(app, target) {
|
|
|
1135
1135
|
}
|
|
1136
1136
|
|
|
1137
1137
|
navigating = false;
|
|
1138
|
+
|
|
1139
|
+
if (type === 'popstate') {
|
|
1140
|
+
restore_snapshot(current_history_index);
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1138
1143
|
callbacks.after_navigate.forEach((fn) =>
|
|
1139
1144
|
fn(/** @type {import('types').AfterNavigate} */ (navigation))
|
|
1140
1145
|
);
|
|
@@ -1638,7 +1643,6 @@ export function create_client(app, target) {
|
|
|
1638
1643
|
}
|
|
1639
1644
|
|
|
1640
1645
|
const delta = event.state[INDEX_KEY] - current_history_index;
|
|
1641
|
-
let blocked = false;
|
|
1642
1646
|
|
|
1643
1647
|
await navigate({
|
|
1644
1648
|
url: new URL(location.href),
|
|
@@ -1651,15 +1655,10 @@ export function create_client(app, target) {
|
|
|
1651
1655
|
},
|
|
1652
1656
|
blocked: () => {
|
|
1653
1657
|
history.go(-delta);
|
|
1654
|
-
blocked = true;
|
|
1655
1658
|
},
|
|
1656
1659
|
type: 'popstate',
|
|
1657
1660
|
delta
|
|
1658
1661
|
});
|
|
1659
|
-
|
|
1660
|
-
if (!blocked) {
|
|
1661
|
-
restore_snapshot(current_history_index);
|
|
1662
|
-
}
|
|
1663
1662
|
}
|
|
1664
1663
|
});
|
|
1665
1664
|
|
|
@@ -1918,12 +1917,44 @@ function reset_focus() {
|
|
|
1918
1917
|
root.removeAttribute('tabindex');
|
|
1919
1918
|
}
|
|
1920
1919
|
|
|
1921
|
-
|
|
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
|
+
|
|
1922
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)
|
|
1923
1954
|
// fixes https://github.com/sveltejs/kit/issues/8439
|
|
1924
|
-
|
|
1955
|
+
selection.removeAllRanges();
|
|
1925
1956
|
});
|
|
1926
|
-
}
|
|
1957
|
+
}
|
|
1927
1958
|
}
|
|
1928
1959
|
}
|
|
1929
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 =
|
|
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
|
|
117
|
+
return url[property];
|
|
114
118
|
},
|
|
115
119
|
|
|
116
120
|
enumerable: true,
|