@k8ordo/router 1.4.0 → 1.4.1

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.
@@ -63,6 +63,7 @@ const applyScroll = (plan) => {
63
63
  };
64
64
  const leftAt = /* @__PURE__ */ new Map();
65
65
  const LEFT_AT_KEY = "@k8ordo/router:left-at";
66
+ const LEFT_AT_LIMIT = 100;
66
67
  const readLeftAt = () => {
67
68
  try {
68
69
  const saved = sessionStorage.getItem(LEFT_AT_KEY);
@@ -71,12 +72,15 @@ const readLeftAt = () => {
71
72
  } catch {}
72
73
  };
73
74
  const rememberLeftAt = (entry) => {
75
+ leftAt.delete(entry);
74
76
  leftAt.set(entry, {
75
77
  left: window.scrollX,
76
78
  top: window.scrollY
77
79
  });
78
- const live = new Set(navigation.entries().map(({ key }) => key));
79
- for (const key of leftAt.keys()) if (!live.has(key)) leftAt.delete(key);
80
+ for (const key of leftAt.keys()) {
81
+ if (leftAt.size <= LEFT_AT_LIMIT) break;
82
+ leftAt.delete(key);
83
+ }
80
84
  try {
81
85
  sessionStorage.setItem(LEFT_AT_KEY, JSON.stringify([...leftAt]));
82
86
  } catch {}
@@ -182,6 +186,7 @@ function useInterceptedNavigation(handler) {
182
186
  const pathname = normalizePathname(url.pathname);
183
187
  const inPlace = pathname === shown.current;
184
188
  const traverse = event.navigationType === "traverse";
189
+ const browserRestores = traverse && event.destination.key === "";
185
190
  if (inPlace && !refresh(url)) {
186
191
  const calledOff = event.destination.key === (onScreenEntry.current ?? navigation.currentEntry?.key);
187
192
  onScreenEntry.current = null;
@@ -200,7 +205,7 @@ function useInterceptedNavigation(handler) {
200
205
  resolve: () => {
201
206
  resolve(void 0);
202
207
  },
203
- scroll: scrollPlanFor("traverse", url.hash, leftAt.get(event.destination.key)),
208
+ scroll: browserRestores ? null : scrollPlanFor("traverse", url.hash, leftAt.get(event.destination.key)),
204
209
  types: []
205
210
  });
206
211
  event.signal.addEventListener("abort", () => {
@@ -209,7 +214,7 @@ function useInterceptedNavigation(handler) {
209
214
  }, { once: true });
210
215
  setTraversed(id);
211
216
  event.intercept({
212
- scroll: "manual",
217
+ scroll: browserRestores ? "after-transition" : "manual",
213
218
  focusReset: "manual",
214
219
  handler: () => promise
215
220
  });
@@ -223,10 +228,10 @@ function useInterceptedNavigation(handler) {
223
228
  const settled = () => {
224
229
  if (latest.current === id) setPendingPathname(null);
225
230
  };
226
- const scroll = inPlace && !traverse ? null : scrollPlanFor(event.navigationType, url.hash, leftAt.get(event.destination.key));
231
+ const scroll = inPlace && !traverse || browserRestores ? null : scrollPlanFor(event.navigationType, url.hash, leftAt.get(event.destination.key));
227
232
  event.intercept({
228
233
  ...inPlace ? { focusReset: "manual" } : {},
229
- scroll: "manual",
234
+ scroll: browserRestores ? "after-transition" : "manual",
230
235
  handler: async () => {
231
236
  event.signal.addEventListener("abort", settled, { once: true });
232
237
  let value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k8ordo/router",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "The pathname axis of the URL, owned. One route table derives the types, the matching, the links, and the navigation, over the Navigation API and URLPattern.",
5
5
  "keywords": [
6
6
  "navigation-api",