stx-router 0.2.611 → 0.2.613
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/dist/client.js +7 -8
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -525,6 +525,7 @@ function routerSource() {
|
|
|
525
525
|
// rather than a Map to keep the diff localized and the runtime
|
|
526
526
|
// hand-minified shape consistent.
|
|
527
527
|
var cacheOrder=[];
|
|
528
|
+
function isFragment(html){return !html.indexOf('<!--stx-fragment')}
|
|
528
529
|
function setCache(key,html,layout,group,title,cattrs){
|
|
529
530
|
if(!(key in cache))cacheOrder.push(key);
|
|
530
531
|
cache[key]=html;
|
|
@@ -1326,7 +1327,7 @@ function routerSource() {
|
|
|
1326
1327
|
// change (prefetchLink), or kept from an earlier full-page answer. Only a
|
|
1327
1328
|
// fragment from another layout still needs its document fetched; asking
|
|
1328
1329
|
// again was a second round trip on every tap into another layout.
|
|
1329
|
-
var isDoc
|
|
1330
|
+
var isDoc=!isFragment(cached);
|
|
1330
1331
|
if(!isDoc&&checkLayoutChange(layoutCache[targetPath],url,layoutGroupCache[targetPath])){
|
|
1331
1332
|
// Layout changed \u2014 fetch full page and do full document swap
|
|
1332
1333
|
log('[router] cache hit but layout changed \u2014 fetching full page');
|
|
@@ -1352,10 +1353,8 @@ function routerSource() {
|
|
|
1352
1353
|
if(swapped===false)return false;
|
|
1353
1354
|
applyTitle(titleCache[targetPath]);
|
|
1354
1355
|
// Shown from the cache at once; asked again behind it, so a page that
|
|
1355
|
-
// changed since says so (stx:updated) instead of staying stale.
|
|
1356
|
-
|
|
1357
|
-
// read as changed.
|
|
1358
|
-
if(!isDoc)revalidate(targetPath,url);
|
|
1356
|
+
// changed since says so (stx:updated) instead of staying stale.
|
|
1357
|
+
revalidate(targetPath,url);
|
|
1359
1358
|
return true;
|
|
1360
1359
|
}).finally(done);
|
|
1361
1360
|
}
|
|
@@ -3138,8 +3137,8 @@ else {
|
|
|
3138
3137
|
function revalidate(key,url){
|
|
3139
3138
|
if(!o.revalidate||!o.cache||!key||prefetching[key])return;
|
|
3140
3139
|
if(Date.now()-(cacheAt[key]||0)<o.revalidateAfter)return;
|
|
3141
|
-
|
|
3142
|
-
var before=cache[key];
|
|
3140
|
+
// Compare like with like, including documents prefetched across layouts.
|
|
3141
|
+
var before=cache[key],wantsFragment=before?isFragment(before):shouldUseFragmentResponse();
|
|
3143
3142
|
prefetching[key]=fetch(url,{headers:wantsFragment?{'X-STX-Router':'true','Accept':'text/html'}:{'Accept':'text/html'}}).then(function(r){
|
|
3144
3143
|
var incoming=r.headers.get('X-STX-Build')||'';
|
|
3145
3144
|
if(isBuildSkew(incoming)){reloadForSkew(url,incoming,true);return null}
|
|
@@ -3532,7 +3531,7 @@ else {
|
|
|
3532
3531
|
// would read this answer, see the layout change, and fetch the whole
|
|
3533
3532
|
// document then (navigate). Fetch it now instead, while the person is
|
|
3534
3533
|
// still reaching for the link, so the tap is a swap like any other.
|
|
3535
|
-
if(!result
|
|
3534
|
+
if(!result||!isFragment(result.html)||!checkLayoutChange(result.layout,href,result.layoutGroup))return result;
|
|
3536
3535
|
// Same guards as any prefetch; the layout is the one the fragment declared.
|
|
3537
3536
|
return fetch(href,{headers:{'Accept':'text/html'}}).then(function(full){
|
|
3538
3537
|
return full.ok?readPrefetchResponse(full,false).then(function(doc){return doc&&(doc.layout=result.layout,doc.layoutGroup=result.layoutGroup,doc)}):null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stx-router",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.613",
|
|
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",
|