bun-plugin-stx 0.2.316 → 0.2.317

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.
@@ -964,6 +964,15 @@ function getRouterScript() {
964
964
  // navigation, leaking a listener and an observer each time and resetting the
965
965
  // instance registry \u2014 trading a silent missing component for a silent leak.
966
966
  var REGISTERS_SCOPE=/window\\.stx\\.mount|_scopes\\s*\\[|\\.initScope\\s*\\(|__stxComponentFactories\\s*\\[/;
967
+ // The page's module registry (#1957): the bundle every component that
968
+ // imports a local module reads from, so on navigation it has to run before
969
+ // any of them. Marked data-stx-modules; the text test also finds it where
970
+ // only a script's text survives. Its wrapper names __stxModuleBundles, which
971
+ // no component script does -- they read __stxModules.
972
+ var REGISTRY_TEXT=/__stxModuleBundles/;
973
+ function isModuleRegistryScript(s){
974
+ return !!s&&((s.hasAttribute&&s.hasAttribute('data-stx-modules'))||REGISTRY_TEXT.test(s.textContent||''));
975
+ }
967
976
  function runsAlways(declared, code){
968
977
  if(declared==='always')return true;
969
978
  if(declared==='once')return false;
@@ -1968,7 +1977,7 @@ else {
1968
1977
  var slot='document-'+(++routedBodyScriptId);
1969
1978
  var setupName=generatedSetupName(text);
1970
1979
  if(setupName)incomingSetupName=setupName;
1971
- routedBodyScripts.push({text:text,runAlways:true,slot:slot,setupName:setupName,run:s.getAttribute('data-stx-run')||'',owner:s.getAttribute('data-stx-owner')||''});
1980
+ routedBodyScripts.push({text:text,runAlways:true,slot:slot,setupName:setupName,run:s.getAttribute('data-stx-run')||'',owner:s.getAttribute('data-stx-owner')||'',registry:isModuleRegistryScript(s)});
1972
1981
  s.textContent='';
1973
1982
  s.setAttribute('type','application/stx-pending');
1974
1983
  s.setAttribute('data-stx-route-script',slot);
@@ -2050,16 +2059,24 @@ else {
2050
2059
 
2051
2060
  var scripts=routedBodyScripts.slice();
2052
2061
  function addScript(text, runAlways, slot, owner){
2053
- scripts.push({text:text,runAlways:!!runAlways,slot:slot||'',owner:owner||''});
2062
+ scripts.push({text:text,runAlways:!!runAlways,slot:slot||'',owner:owner||'',registry:REGISTRY_TEXT.test(text)});
2054
2063
  }
2055
2064
  if(isLayoutChange){
2056
- // Also collect setup functions from <head>
2065
+ // Also collect setup functions from <head>, and the page's module
2066
+ // registry (#1957). The registry is anchored to the signals runtime,
2067
+ // and a layout with its own <head> script (analytics, say) pulls the
2068
+ // runtime -- and the registry with it -- into <head>. Collecting only
2069
+ // setups there dropped it, so every component that imports a local
2070
+ // module threw "is not registered on this page" and its template
2071
+ // hydrated against globals: an <input id="email"> bound to
2072
+ // :model="email" showed "[object HTMLInputElement]".
2057
2073
  doc.querySelectorAll('head script').forEach(function(s){
2058
2074
  var text=s.textContent||'';
2059
2075
  if(s.hasAttribute('src'))return;
2060
2076
  if(!text.trim())return;
2061
2077
  if(isSignalsRuntimeScript(s,text))return;
2062
- if(text.indexOf('__stx_setup_')!==-1)addScript(text,true);
2078
+ if(isModuleRegistryScript(s))addScript(text,true,'','');
2079
+ else if(text.indexOf('__stx_setup_')!==-1)addScript(text,true);
2063
2080
  });
2064
2081
  } else {
2065
2082
  // Collect page scripts from <head> AND <body> (outside container).
@@ -2107,6 +2124,12 @@ else {
2107
2124
  return aPage-bPage;
2108
2125
  });
2109
2126
  }
2127
+ // The module registry runs before anything that reads it (#1957). The
2128
+ // container's own scripts are collected first and head scripts after,
2129
+ // so without this a component in the page body could run ahead of the
2130
+ // registry it imports from. Stable: the order within each group holds.
2131
+ var registryFirst=scripts.filter(function(e){return e.registry});
2132
+ if(registryFirst.length)scripts=registryFirst.concat(scripts.filter(function(e){return !e.registry}));
2110
2133
 
2111
2134
  // Push history state (before active link updates so location.pathname is current)
2112
2135
  if(pushState!==false)writeHistory(pushState,url+(hash||''));
package/dist/serve.js CHANGED
@@ -9724,7 +9724,7 @@ function __stxOverlay(errs){
9724
9724
  pageMiddlewarePatterns.length = 0;
9725
9725
  await Promise.all(files.map((f) => detectPageMiddleware(f)));
9726
9726
  try {
9727
- const { Router } = await import("./chunk-71hprtbd.js");
9727
+ const { Router } = await import("./chunk-9gb1t22q.js");
9728
9728
  const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
9729
9729
  const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName() });
9730
9730
  if (!options.quiet)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.316",
4
+ "version": "0.2.317",
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",