stx-router 0.2.393 → 0.2.395

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.
Files changed (2) hide show
  1. package/dist/client.js +31 -2
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -87,6 +87,10 @@ function routerSource() {
87
87
  // there. sessionStorage is per tab and dies with it, same as the history.
88
88
  var SCROLL_TOKEN='__stxScroll';
89
89
  var SCROLL_STORE='stx:scroll:';
90
+ // On every entry the router pushes, never on the one the app opened with
91
+ // (which carries a scroll token too): going back from a pushed entry stays
92
+ // in the app, from the first it leaves it (or, in a phone app, does nothing).
93
+ var PUSHED_MARK='__stxPushed';
90
94
  var scrollSeq=0;
91
95
  var pendingScroll=null;
92
96
  var restoreScroll=!!o.scrollRestoration;
@@ -870,9 +874,18 @@ function routerSource() {
870
874
  // The position belongs to the entry being left, and scrollToken still
871
875
  // names it here.
872
876
  rememberScroll();
873
- if(mode==='replace'){history.replaceState(tokenState(),'',href);return}
877
+ if(mode==='replace'){
878
+ // A replaced entry is still the one it replaces: pushed by the app or
879
+ // the one the app opened with.
880
+ var replaced=tokenState();
881
+ if(history.state&&history.state[PUSHED_MARK])replaced[PUSHED_MARK]=true;
882
+ history.replaceState(replaced,'',href);
883
+ return;
884
+ }
874
885
  scrollToken=newScrollToken();
875
- history.pushState(tokenState(),'',href);
886
+ var pushed=tokenState();
887
+ pushed[PUSHED_MARK]=true;
888
+ history.pushState(pushed,'',href);
876
889
  }
877
890
  function tokenState(){var state={};state[SCROLL_TOKEN]=scrollToken;return state}
878
891
 
@@ -2179,6 +2192,22 @@ else {
2179
2192
  navigate(location.pathname+location.search+location.hash,false);
2180
2193
  });
2181
2194
 
2195
+ // \u2500\u2500 Offline stand-in \u2500\u2500
2196
+ // Without a network the offline worker answers a screen it has not kept
2197
+ // whole with the app's first screen, marked. A screen reached inside the
2198
+ // app was kept as a fragment, so ask for that and show it in place. Only
2199
+ // when it is there: a failed navigate reloads, and the reload would be
2200
+ // answered with the stand-in again.
2201
+ var standIn=document.querySelector('meta[name="stx-offline-fallback"]');
2202
+ if(standIn&&shouldUseFragmentResponse()){
2203
+ standIn.remove();
2204
+ var wanted=location.pathname+location.search;
2205
+ fetch(wanted,{headers:{'X-STX-Router':'true','Accept':'text/html'}}).then(function(r){
2206
+ if(r.ok&&r.headers.get('X-STX-Fragment')==='true'&&location.pathname+location.search===wanted)
2207
+ navigate(wanted+location.hash,false,true);
2208
+ }).catch(function(){});
2209
+ }
2210
+
2182
2211
  // \u2500\u2500 Prefetch \u2500\u2500
2183
2212
  // A link's page, fetched before it is followed into the cache navigate
2184
2213
  // reads, so following it is a swap rather than a round trip.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stx-router",
3
3
  "type": "module",
4
- "version": "0.2.393",
4
+ "version": "0.2.395",
5
5
  "description": "File-based router for STX — .stx template discovery, nested layouts, typed route params, middleware, and client-side SPA navigation.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",