bun-plugin-stx 0.2.303 → 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.
@@ -209,11 +209,16 @@ class Router {
209
209
  this.routes = [];
210
210
  for (const dir of this.pagesDirs) {
211
211
  const files = scanDirectory(dir, extensions);
212
+ const localPatterns = new Map;
212
213
  for (const filePath of files) {
213
214
  const pattern = filePathToPattern(filePath, dir);
214
- if (seenPatterns.has(pattern))
215
+ const identity = config.pagesDirs ? pattern.replace(/:[\w]+/g, ":param") : pattern;
216
+ if (config.pagesDirs && localPatterns.has(identity))
217
+ throw new Error(`Conflicting layer pages for ${pattern}: ${localPatterns.get(identity)} and ${filePath}`);
218
+ localPatterns.set(identity, filePath);
219
+ if (seenPatterns.has(identity))
215
220
  continue;
216
- seenPatterns.add(pattern);
221
+ seenPatterns.add(identity);
217
222
  const { regex, params } = patternToRegex(pattern);
218
223
  const layouts = config.layouts !== false ? resolveLayoutChain(filePath, dir) : [];
219
224
  this.routes.push({
@@ -653,6 +658,17 @@ function getRouterScript() {
653
658
  var debug=!!o.debug;
654
659
  function log(){if(debug&&typeof console!=='undefined'&&console.log)console.log.apply(console,arguments)}
655
660
 
661
+ // Replace, never merge: absent payloads must forget the outgoing page's data.
662
+ // Run at the committed swap, not during prefetch or a superseded navigation.
663
+ function hydrateServerData(html){
664
+ window.__STX_RUNTIME_CONFIG__={};
665
+ var configMatch=html.match(/<script\\b[^>]*\\bdata-stx-runtime-config\\b[^>]*>([\\s\\S]*?)<\\/script>/i);
666
+ if(configMatch){try{var configValues=JSON.parse(configMatch[1]);if(configValues&&typeof configValues==='object'&&!Array.isArray(configValues))window.__STX_RUNTIME_CONFIG__=configValues}catch(e){}}
667
+ window.__STX_DATA__={};
668
+ var match=html.match(/<script\\b[^>]*\\bdata-stx-server-data\\b[^>]*>([\\s\\S]*?)<\\/script>/i);
669
+ if(match){try{var values=JSON.parse(match[1]);if(values&&typeof values==='object'&&!Array.isArray(values))window.__STX_DATA__=values}catch(e){}}
670
+ }
671
+
656
672
  // \u2500\u2500 Build skew (stacksjs/stx#1772) \u2500\u2500
657
673
  // The build that rendered THIS document, and therefore the build the runtime
658
674
  // executing right now came from. Under bun --watch a save restarts the server,
@@ -1541,6 +1557,7 @@ else {
1541
1557
  return Promise.resolve(false);
1542
1558
  }
1543
1559
  function doFragSwap(){
1560
+ hydrateServerData(html);
1544
1561
  // Extract scripts from fragment before injecting HTML
1545
1562
  var fragScripts=[];
1546
1563
  var fragScriptId=0;
@@ -1971,6 +1988,10 @@ else {
1971
1988
  if(incomingSetupName)document.body.setAttribute('data-stx',incomingSetupName);
1972
1989
  }
1973
1990
 
1991
+ // Teardown (including outgoing layout chrome) has finished. Its destroy
1992
+ // callbacks must not be able to invalidate the incoming page's snapshot.
1993
+ hydrateServerData(html);
1994
+
1974
1995
  // \u2500\u2500 Load new external <head> scripts \u2500\u2500
1975
1996
  var loadedSrcs={};
1976
1997
  document.querySelectorAll('head script[src]').forEach(function(s){loadedSrcs[s.src]=1});
package/dist/serve.js CHANGED
@@ -9193,6 +9193,8 @@ async function serve(options) {
9193
9193
  const stxMod = options.stxModule ? options.stxModule : await defaultStxModule;
9194
9194
  if (stxMod && typeof stxMod.loadStxConfig === "function") {
9195
9195
  const pluginLoaded = await stxMod.loadStxConfig();
9196
+ if (pluginLoaded?.runtimeConfig)
9197
+ stxConfig.runtimeConfig = pluginLoaded.runtimeConfig;
9196
9198
  if (pluginLoaded?._pluginComponentDirs)
9197
9199
  stxConfig._pluginComponentDirs = pluginLoaded._pluginComponentDirs;
9198
9200
  if (pluginLoaded?._pluginPageDirs)
@@ -9709,7 +9711,7 @@ function __stxOverlay(errs){
9709
9711
  pageMiddlewarePatterns.length = 0;
9710
9712
  await Promise.all(files.map((f) => detectPageMiddleware(f)));
9711
9713
  try {
9712
- const { Router } = await import("./chunk-awcgpf66.js");
9714
+ const { Router } = await import("./chunk-ahmasn2t.js");
9713
9715
  const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
9714
9716
  const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName() });
9715
9717
  if (!options.quiet)
@@ -9935,6 +9937,7 @@ function __stxOverlay(errs){
9935
9937
  const context = {
9936
9938
  __filename: filePath,
9937
9939
  __dirname: nodePath.dirname(filePath),
9940
+ __stx_options: stxConfig,
9938
9941
  __stx_runtime_head: {}
9939
9942
  };
9940
9943
  const { processDirectives, extractVariables, defaultConfig: defaultConfig4, generateSpaShell, injectRouterScript } = await stxModule;
@@ -9958,6 +9961,7 @@ function __stxOverlay(errs){
9958
9961
  buildMode: "serve",
9959
9962
  ssr: stxConfig.ssr ?? defaultStxConfig.ssr ?? true,
9960
9963
  app: stxConfig.app || {},
9964
+ runtimeConfig: stxConfig.runtimeConfig,
9961
9965
  ..."strict" in stxConfig && { strict: stxConfig.strict },
9962
9966
  ..."router" in stxConfig && { router: stxConfig.router },
9963
9967
  ..."debug" in stxConfig && { debug: stxConfig.debug },
@@ -10131,6 +10135,7 @@ function __stxOverlay(errs){
10131
10135
  const { processDirectives, extractVariables, defaultConfig: defaultConfig4, injectRouterScript: injectRouter } = await stxModule;
10132
10136
  injectServeLocaleContext(context);
10133
10137
  injectServeRequestContext(context, reqCtx);
10138
+ context.__stx_options = stxConfig;
10134
10139
  for (const scriptBody of dynServerScripts) {
10135
10140
  await extractVariables(scriptBody, context, filePath);
10136
10141
  }
@@ -10147,6 +10152,7 @@ function __stxOverlay(errs){
10147
10152
  buildMode: "serve",
10148
10153
  ssr: stxConfig.ssr ?? defaultStxConfig.ssr ?? true,
10149
10154
  app: stxConfig.app || {},
10155
+ runtimeConfig: stxConfig.runtimeConfig,
10150
10156
  ..."strict" in stxConfig && { strict: stxConfig.strict },
10151
10157
  ..."router" in stxConfig && { router: stxConfig.router },
10152
10158
  ..."debug" in stxConfig && { debug: stxConfig.debug },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.303",
4
+ "version": "0.2.304",
5
5
  "description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",