stx-router 0.2.292 → 0.2.294

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 +22 -4
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -355,8 +355,8 @@ export function getRouterScript() {
355
355
  // Unlike a fragment, a document holds the answer directly, so there is
356
356
  // nothing to infer from markers or ask the server for: look for the script.
357
357
  // Both emitted shapes carry data-stx-runtime \u2014 inline, and the serve-mode
358
- // src="/_stx/runtime.js" \u2014 with the content sniff behind it for a document
359
- // rendered by a server old enough not to stamp the attribute.
358
+ // src="/_stx/runtime.<hash>.js" \u2014 with the content sniff behind it for a
359
+ // document rendered by a server old enough not to stamp the attribute.
360
360
  function documentShipsRuntime(doc,html){
361
361
  if(doc&&doc.querySelector&&doc.querySelector('script[data-stx-runtime]'))return true;
362
362
  return html.indexOf("'use strict';var cloakStyle")!==-1
@@ -367,6 +367,22 @@ export function getRouterScript() {
367
367
  ||(code.indexOf('_cleanupContainer')!==-1&&code.indexOf('signals runtime loading')!==-1)
368
368
  ||code.indexOf("'use strict';var cloakStyle")!==-1;
369
369
  }
370
+ // The runtime and the router themselves, as external script tags.
371
+ //
372
+ // Serve mode links both by content hash, so after a deploy the incoming
373
+ // page's copy has a different URL from the one this document loaded. Every
374
+ // path below that loads a script[src] it has not seen yet would then run a
375
+ // second router and a second runtime over the live ones \u2014 two click
376
+ // handlers on every link, a fresh window.stx under scopes created by the
377
+ // old one. A new version is picked up by the build-skew reload instead; it
378
+ // is never loaded into a running page. The attrs form is for the fragment
379
+ // path, which sees a tag as text.
380
+ function isSharedClientScript(el){
381
+ return !!(el&&el.hasAttribute&&(el.hasAttribute('data-stx-runtime')||el.hasAttribute('data-stx-router')));
382
+ }
383
+ function isSharedClientScriptAttrs(attrs){
384
+ return /(?:^|\\s)data-stx-(?:runtime|router)(?:[\\s=]|$)/i.test(attrs||'');
385
+ }
370
386
  // A fragment never carries the signals runtime: the server strips the runtime
371
387
  // IIFE out of it, and every re-execution path here filters it out again. So a
372
388
  // page that never needed a runtime cannot hydrate a fragment that does \u2014 the
@@ -923,7 +939,7 @@ else {
923
939
  // file is where the page's factory usually lives.
924
940
  var srcMatch=attrs.match(/\\bsrc\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))/i);
925
941
  var fragSrc=srcMatch&&(srcMatch[1]||srcMatch[2]||srcMatch[3]);
926
- if(fragSrc){fragExternalScripts.push(fragSrc);return ''}
942
+ if(fragSrc){if(!isSharedClientScriptAttrs(attrs))fragExternalScripts.push(fragSrc);return ''}
927
943
  if(code&&code.trim()&&!isSignalsRuntimeScript({hasAttribute:function(name){return name==='data-stx-runtime'&&attrs.indexOf('data-stx-runtime')!==-1}},code)){
928
944
  var slot='fragment-'+(++fragScriptId);
929
945
  var scoped=/(?:^|\\s)data-stx-scoped(?:\\s|=|$)/i.test(attrs);
@@ -1271,7 +1287,8 @@ else {
1271
1287
  var text=s.textContent||'';
1272
1288
  // Not discarded: queued against docBase, so a relative src resolves
1273
1289
  // against the page being navigated to rather than the current URL.
1274
- if(s.hasAttribute('src')){routedExternalScripts.push(s.getAttribute('src'));s.remove();return}
1290
+ // The runtime and router are dropped, not queued: see isSharedClientScript.
1291
+ if(s.hasAttribute('src')){if(!isSharedClientScript(s))routedExternalScripts.push(s.getAttribute('src'));s.remove();return}
1275
1292
  var type=(s.getAttribute('type')||'').trim().toLowerCase();
1276
1293
  var executable=!type||type==='text/javascript'||type==='application/javascript'||type==='module';
1277
1294
  if(!executable||!text.trim())return;
@@ -1328,6 +1345,7 @@ else {
1328
1345
  document.querySelectorAll('head script[src]').forEach(function(s){loadedSrcs[s.src]=1});
1329
1346
  var extPromises=[];
1330
1347
  doc.querySelectorAll('head script[src]').forEach(function(s){
1348
+ if(isSharedClientScript(s))return;
1331
1349
  // Fetched-document script: resolve against the page being navigated to
1332
1350
  // (docBase), not the origin root \u2014 same rationale as the <link> reconcile (#1777).
1333
1351
  var src=new URL(s.getAttribute('src'),docBase).href;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stx-router",
3
3
  "type": "module",
4
- "version": "0.2.292",
4
+ "version": "0.2.294",
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",