stx-router 0.2.411 → 0.2.412
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 +17 -2
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -456,7 +456,7 @@ function routerSource() {
|
|
|
456
456
|
// whole fix \u2014 the click then goes to the network, where navigate does
|
|
457
457
|
// the reload properly.
|
|
458
458
|
function readPrefetchResponse(r,wantsFragment){
|
|
459
|
-
if(r.redirected)return Promise.resolve(null);
|
|
459
|
+
if(r.redirected||r.headers.get('X-STX-Location'))return Promise.resolve(null);
|
|
460
460
|
if(isBuildSkew(r.headers.get('X-STX-Build')||''))return Promise.resolve(null);
|
|
461
461
|
var isFrag=wantsFragment&&r.headers.get('X-STX-Fragment')==='true';
|
|
462
462
|
var layout=r.headers.get('X-STX-Layout')||'';
|
|
@@ -985,6 +985,18 @@ function routerSource() {
|
|
|
985
985
|
// swap() through pendingCtx, the same way pendingContainerAttrs is.
|
|
986
986
|
var navCtxNext=null;
|
|
987
987
|
var pendingCtx=null;
|
|
988
|
+
// The page belongs to another origin: the server says so with
|
|
989
|
+
// X-STX-Location (it cannot redirect a router fetch there, because a
|
|
990
|
+
// cross-origin redirect of a request carrying X-STX-Router fails CORS), or
|
|
991
|
+
// a plain fetch was redirected off-origin. Either way the browser goes
|
|
992
|
+
// there itself; a fragment from another origin is never swapped in.
|
|
993
|
+
function leaveOrigin(r){
|
|
994
|
+
var away=r.headers.get('X-STX-Location');
|
|
995
|
+
if(!away&&r.redirected&&r.url&&new URL(r.url,location.href).origin!==location.origin)away=r.url;
|
|
996
|
+
if(!away)return false;
|
|
997
|
+
location.href=away;
|
|
998
|
+
return true;
|
|
999
|
+
}
|
|
988
1000
|
function routerFetch(url,headers){
|
|
989
1001
|
var init={headers:headers};
|
|
990
1002
|
if(navAbort)init.signal=navAbort.signal;
|
|
@@ -1076,10 +1088,11 @@ function routerSource() {
|
|
|
1076
1088
|
// Layout changed \u2014 fetch full page and do full document swap
|
|
1077
1089
|
log('[router] cache hit but layout changed \u2014 fetching full page');
|
|
1078
1090
|
return routerFetch(url,{'Accept':'text/html'}).then(function(r){
|
|
1091
|
+
if(leaveOrigin(r))return null;
|
|
1079
1092
|
if(!r.ok)throw httpError(r.status);
|
|
1080
1093
|
return r.text();
|
|
1081
1094
|
}).then(function(html){
|
|
1082
|
-
if(stale())return false;
|
|
1095
|
+
if(html===null||stale())return false;
|
|
1083
1096
|
log('[router] full page fetched from cache path, len:',html.length);
|
|
1084
1097
|
pendingLayoutDecl={layout:layoutCache[targetPath]||'',group:layoutGroupCache[targetPath]||''};
|
|
1085
1098
|
return swapWith(html,targetPath);
|
|
@@ -1104,6 +1117,7 @@ else {
|
|
|
1104
1117
|
var wantsFragment=shouldUseFragmentResponse();
|
|
1105
1118
|
return routerFetch(url,wantsFragment?{'X-STX-Router':'true','Accept':'text/html'}:{'Accept':'text/html'}).then(function(r){
|
|
1106
1119
|
if(stale())return null;
|
|
1120
|
+
if(leaveOrigin(r))return null;
|
|
1107
1121
|
if(!r.ok)throw httpError(r.status);
|
|
1108
1122
|
// A route guard answered with a redirect and fetch followed it
|
|
1109
1123
|
// transparently, so r.ok is the DESTINATION's 200 and this markup
|
|
@@ -1137,6 +1151,7 @@ else {
|
|
|
1137
1151
|
log('[router] layout change \u2014 fetching full page for document swap');
|
|
1138
1152
|
return routerFetch(url,{'Accept':'text/html'}).then(function(fullRes){
|
|
1139
1153
|
log('[router] full page fetched:',fullRes.status,'ok:',fullRes.ok);
|
|
1154
|
+
if(leaveOrigin(fullRes))return null;
|
|
1140
1155
|
if(!fullRes.ok)throw httpError(fullRes.status);
|
|
1141
1156
|
return fullRes.text().then(function(html){
|
|
1142
1157
|
log('[router] full page html length:',html.length);
|
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.412",
|
|
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",
|