stx-router 0.2.302 → 0.2.304

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 CHANGED
@@ -22,6 +22,17 @@ export function getRouterScript() {
22
22
  var debug=!!o.debug;
23
23
  function log(){if(debug&&typeof console!=='undefined'&&console.log)console.log.apply(console,arguments)}
24
24
 
25
+ // Replace, never merge: absent payloads must forget the outgoing page's data.
26
+ // Run at the committed swap, not during prefetch or a superseded navigation.
27
+ function hydrateServerData(html){
28
+ window.__STX_RUNTIME_CONFIG__={};
29
+ var configMatch=html.match(/<script\\b[^>]*\\bdata-stx-runtime-config\\b[^>]*>([\\s\\S]*?)<\\/script>/i);
30
+ if(configMatch){try{var configValues=JSON.parse(configMatch[1]);if(configValues&&typeof configValues==='object'&&!Array.isArray(configValues))window.__STX_RUNTIME_CONFIG__=configValues}catch(e){}}
31
+ window.__STX_DATA__={};
32
+ var match=html.match(/<script\\b[^>]*\\bdata-stx-server-data\\b[^>]*>([\\s\\S]*?)<\\/script>/i);
33
+ if(match){try{var values=JSON.parse(match[1]);if(values&&typeof values==='object'&&!Array.isArray(values))window.__STX_DATA__=values}catch(e){}}
34
+ }
35
+
25
36
  // \u2500\u2500 Build skew (stacksjs/stx#1772) \u2500\u2500
26
37
  // The build that rendered THIS document, and therefore the build the runtime
27
38
  // executing right now came from. Under bun --watch a save restarts the server,
@@ -910,6 +921,7 @@ else {
910
921
  return Promise.resolve(false);
911
922
  }
912
923
  function doFragSwap(){
924
+ hydrateServerData(html);
913
925
  // Extract scripts from fragment before injecting HTML
914
926
  var fragScripts=[];
915
927
  var fragScriptId=0;
@@ -1340,6 +1352,10 @@ else {
1340
1352
  if(incomingSetupName)document.body.setAttribute('data-stx',incomingSetupName);
1341
1353
  }
1342
1354
 
1355
+ // Teardown (including outgoing layout chrome) has finished. Its destroy
1356
+ // callbacks must not be able to invalidate the incoming page's snapshot.
1357
+ hydrateServerData(html);
1358
+
1343
1359
  // \u2500\u2500 Load new external <head> scripts \u2500\u2500
1344
1360
  var loadedSrcs={};
1345
1361
  document.querySelectorAll('head script[src]').forEach(function(s){loadedSrcs[s.src]=1});
@@ -44,12 +44,15 @@ export class Router {
44
44
  const extensions = config.extensions || [".stx"], seenPatterns = new Set;
45
45
  this.routes = [];
46
46
  for (const dir of this.pagesDirs) {
47
- const files = scanDirectory(dir, extensions);
47
+ const files = scanDirectory(dir, extensions), localPatterns = new Map;
48
48
  for (const filePath of files) {
49
- const pattern = filePathToPattern(filePath, dir);
50
- if (seenPatterns.has(pattern))
49
+ const pattern = filePathToPattern(filePath, dir), identity = config.pagesDirs ? pattern.replace(/:[\w]+/g, ":param") : pattern;
50
+ if (config.pagesDirs && localPatterns.has(identity))
51
+ throw Error(`Conflicting layer pages for ${pattern}: ${localPatterns.get(identity)} and ${filePath}`);
52
+ localPatterns.set(identity, filePath);
53
+ if (seenPatterns.has(identity))
51
54
  continue;
52
- seenPatterns.add(pattern);
55
+ seenPatterns.add(identity);
53
56
  const { regex, params } = patternToRegex(pattern), layouts = config.layouts !== !1 ? resolveLayoutChain(filePath, dir) : [];
54
57
  this.routes.push({
55
58
  pattern,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stx-router",
3
3
  "type": "module",
4
- "version": "0.2.302",
4
+ "version": "0.2.304",
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",