@k8ordo/router 1.4.2 → 1.4.4

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.
@@ -182,7 +182,16 @@ function useInterceptedNavigation(handler) {
182
182
  useEffect(() => {
183
183
  shown.current = normalizePathname(location.pathname);
184
184
  readLeftAt();
185
+ let reloading = false;
186
+ const reload = () => {
187
+ reloading = true;
188
+ location.reload();
189
+ };
190
+ let announced = null;
191
+ if (navigation.currentEntry === null && navigation.entries().length > 0) reload();
185
192
  const onNavigate = (event) => {
193
+ announced = event.destination.url;
194
+ if (reloading) return;
186
195
  const traverse = event.navigationType === "traverse";
187
196
  if (traverse && isOurs(event) && onScreenEntry.current === null && event.destination.key === navigation.currentEntry?.key) {
188
197
  event.intercept({
@@ -278,7 +287,14 @@ function useInterceptedNavigation(handler) {
278
287
  };
279
288
  navigation.addEventListener("navigate", onNavigate);
280
289
  const onPopState = () => {
281
- if (navigation.currentEntry === null) location.reload();
290
+ if (reloading || navigation.currentEntry === null) {
291
+ reload();
292
+ return;
293
+ }
294
+ if (announced === location.href) return;
295
+ const url = new URL(location.href);
296
+ if (normalizePathname(url.pathname) === shown.current && pendingPathname === null && !refresh(url)) return;
297
+ reload();
282
298
  };
283
299
  window.addEventListener("popstate", onPopState);
284
300
  return () => {
package/docs/GUIDE.md CHANGED
@@ -474,9 +474,14 @@ another origin, it gives a traversal to an earlier entry no key, so the router
474
474
  has no recorded position to look up and the browser restores it instead. If
475
475
  the visitor scrolled the page still on screen while the next one loaded, the
476
476
  browser does not restore it, and the page stays where they scrolled it. Coming
477
- back from another site, WebKit does not report that traversal at all, so the
478
- router reloads the page: the browser restores the position of a page rendered
479
- on the server, and a page rendered on the client starts at the top.
477
+ back from another site, WebKit does not report some traversals at all — to an
478
+ entry from before that site, and, once the visitor has moved on, back to the
479
+ page they came back to, even before the next page has loaded — so the router
480
+ reloads the page: the browser restores the position of a page rendered on the
481
+ server, and a page rendered on the client starts at the top. A step within a
482
+ page that only moves the search is not reloaded unless `refresh(url)` says the
483
+ page reads it or a page is still loading. A link followed while the page
484
+ reloads opens as a document load.
480
485
 
481
486
  Any other state change never moves the viewport — same pathname, same
482
487
  place — so a filter update does not scroll the reader back to the top.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k8ordo/router",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
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",