stx-router 0.2.684 → 0.2.686

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 +21 -9
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -59,6 +59,10 @@ function routerSource() {
59
59
  var o=Object.assign({},defaults,window.__stxRouterConfig||{},window.STX_ROUTER_OPTIONS||{});
60
60
  var containerSel=o.container;
61
61
  var debug=!!o.debug;
62
+ function pagePath(){return location.pathname+location.search}
63
+ // location already points at the destination when popstate fires. Keep the
64
+ // document we actually rendered so a native anchor visit does not remount it.
65
+ var renderedPage=pagePath();
62
66
  function log(){if(debug&&typeof console!=='undefined'&&console.log)console.log.apply(console,arguments)}
63
67
 
64
68
  // Shorthands for the document-rooted queries this script makes ~33 times.
@@ -1305,7 +1309,7 @@ function routerSource() {
1305
1309
  isNavigating=false;navAbort=null;
1306
1310
  document.body.classList.remove(o.loadingClass);finishProgress();
1307
1311
  settleDirection();
1308
- if(openingUrl&&location.pathname+location.search!==openingUrl)keepOpeningPage();
1312
+ if(openingUrl&&pagePath()!==openingUrl)keepOpeningPage();
1309
1313
  }
1310
1314
  function stale(){return id!==navSeq}
1311
1315
  // A failed fetch keeps the app: the destination shows a way to try again
@@ -1853,6 +1857,7 @@ else {
1853
1857
  // Remove old page scripts
1854
1858
  qsa('script[data-stx-page]').forEach(function(s){s.remove()});
1855
1859
  if(pushState!==false)writeHistory(pushState,url+(hash||''));
1860
+ renderedPage=cacheKey(url);
1856
1861
  if(scr)screenCommit(scr,url+(hash||''));
1857
1862
  refreshCurrentLinks();
1858
1863
  applyScroll(hash);
@@ -2314,6 +2319,7 @@ else {
2314
2319
 
2315
2320
  // Push history state (before active link updates so location.pathname is current)
2316
2321
  if(pushState!==false)writeHistory(pushState,url+(hash||''));
2322
+ renderedPage=cacheKey(url);
2317
2323
 
2318
2324
  // Update active nav links
2319
2325
  refreshCurrentLinks();
@@ -2555,7 +2561,7 @@ else {
2555
2561
  // are hidden (off the page, so out of reach of a DOM walk) goes with them.
2556
2562
  if(host.__stx_detached_if){el.__stx_detached_if=host.__stx_detached_if;host.__stx_detached_if=null}
2557
2563
  if(!curTab)curTab=currentTabId();
2558
- active=newEntry(location.pathname+location.search+location.hash,scrollToken,histDepth);
2564
+ active=newEntry(pagePath()+location.hash,scrollToken,histDepth);
2559
2565
  active.el=el;
2560
2566
  active.cattrs=hostAttrString(host);
2561
2567
  active.shown=++shownSeq;
@@ -2739,6 +2745,7 @@ else {
2739
2745
  // told it is on screen again (stx:screen-shown) so it can refresh whatever
2740
2746
  // may have gone stale while it was hidden.
2741
2747
  function showRetained(to,dir,opts){
2748
+ renderedPage=cacheKey(to.url);
2742
2749
  opts=opts||{};
2743
2750
  settleAnimation();
2744
2751
  var from=active,host=getContainer();
@@ -3332,7 +3339,7 @@ else {
3332
3339
  }
3333
3340
 
3334
3341
  function formTargetUrl(form,submitter){
3335
- return formAttrOf(form,submitter,'formaction','action')||(location.pathname+location.search);
3342
+ return formAttrOf(form,submitter,'formaction','action')||(pagePath());
3336
3343
  }
3337
3344
 
3338
3345
  function formMethodOf(form,submitter){
@@ -3477,8 +3484,13 @@ else {
3477
3484
  var target=(tabs[curTab]||[])[depth];
3478
3485
  if(target&&target.el&&target.token===scrollToken&&target!==active){showRetained(target,dir==='replace'?'pop':dir,{settled:settled===target});return}
3479
3486
  }
3487
+ if(renderedPage===pagePath()){
3488
+ applyScroll(location.hash);
3489
+ refreshCurrentLinks();
3490
+ return;
3491
+ }
3480
3492
  navCtxNext={direction:dir};
3481
- navigate(location.pathname+location.search+location.hash,false);
3493
+ navigate(pagePath()+location.hash,false);
3482
3494
  });
3483
3495
 
3484
3496
  // \u2500\u2500 Offline stand-in \u2500\u2500
@@ -3490,9 +3502,9 @@ else {
3490
3502
  var standIn=document.querySelector('meta[name="stx-offline-fallback"]');
3491
3503
  if(standIn&&shouldUseFragmentResponse()){
3492
3504
  standIn.remove();
3493
- var wanted=location.pathname+location.search;
3505
+ var wanted=pagePath();
3494
3506
  fetch(wanted,{headers:{'X-STX-Router':'true','Accept':'text/html'}}).then(function(r){
3495
- if(r.ok&&r.headers.get('X-STX-Fragment')==='true'&&location.pathname+location.search===wanted)
3507
+ if(r.ok&&r.headers.get('X-STX-Fragment')==='true'&&pagePath()===wanted)
3496
3508
  navigate(wanted+location.hash,false,true);
3497
3509
  }).catch(function(){});
3498
3510
  }
@@ -3680,7 +3692,7 @@ else {
3680
3692
  // on load, it cost the opening page its instant restore when the person
3681
3693
  // left the app and came back (a full-document Back). A router navigation
3682
3694
  // has already fetched one, so after it nothing more is lost.
3683
- var openingUrl=location.pathname+location.search;
3695
+ var openingUrl=pagePath();
3684
3696
  function keepOpeningPage(){
3685
3697
  var url=openingUrl;
3686
3698
  openingUrl='';
@@ -3948,12 +3960,12 @@ else {
3948
3960
  // had rather than adding a second code path. 'replace' because a refresh
3949
3961
  // is not a new place \u2014 it must not add a history entry you can go Back to.
3950
3962
  refresh:function(){
3951
- return navigate(location.pathname+location.search+location.hash,'replace',true);
3963
+ return navigate(pagePath()+location.hash,'replace',true);
3952
3964
  },
3953
3965
  // Expire ONE entry, so a mutation can invalidate just the page it affected
3954
3966
  // and let the next visit re-fetch, instead of throwing the whole cache away.
3955
3967
  invalidate:function(url){
3956
- evictCache(cacheKey(url||(location.pathname+location.search)));
3968
+ evictCache(cacheKey(url||(pagePath())));
3957
3969
  },
3958
3970
  clearCache:function(){for(var k in cache)delete cache[k];for(var lk in layoutCache)delete layoutCache[lk];for(var gk in layoutGroupCache)delete layoutGroupCache[gk];cacheOrder.length=0},
3959
3971
  // Switch to the tab whose link points at href, as a tap on it would:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stx-router",
3
3
  "type": "module",
4
- "version": "0.2.684",
4
+ "version": "0.2.686",
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",