bun-plugin-stx 0.2.287 → 0.2.288

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.
@@ -953,6 +953,23 @@ function getRouterScript() {
953
953
  var head=code.trimStart();
954
954
  return head.charAt(0)==='('||head.charAt(0)===';';
955
955
  }
956
+ // A component scope script names the root it binds in data-stx-owner (#1958).
957
+ // On navigation it runs only for a root that just ARRIVED: one swapped in
958
+ // with the new content, which is not bound yet. A layout component that
959
+ // stayed on screen is skipped, in both shapes that reach here:
960
+ // - its root is gone: it keeps its first render's id while the fragment
961
+ // carries the next page's id for it (ids are page-keyed on purpose), so
962
+ // the script has no markup of its own;
963
+ // - its root is present and already bound: the same page file on both
964
+ // sides of the navigation gives the same id.
965
+ // Either way running it built a second instance of a component whose markup
966
+ // stays bound to the first -- setup and its side effects repeated on every
967
+ // navigation. Scripts without an owner are unaffected.
968
+ function ownerStays(owner){
969
+ if(!owner)return false;
970
+ var root=document.querySelector('[data-stx-scope="'+owner+'"]');
971
+ return !root||typeof root.__stx_disposers==='function';
972
+ }
956
973
  function hashScript(code){
957
974
  var h=0;for(var i=0;i<code.length;i++){h=((h<<5)-h)+code.charCodeAt(i);h|=0}
958
975
  return h;
@@ -1450,7 +1467,8 @@ else {
1450
1467
  var slot='fragment-'+(++fragScriptId);
1451
1468
  var scoped=/(?:^|\\s)data-stx-scoped(?:\\s|=|$)/i.test(attrs);
1452
1469
  var runDecl=(attrs.match(/data-stx-run\\s*=\\s*["']?(always|once)["']?/i)||[])[1];
1453
- fragScripts.push({text:code,slot:slot,setupName:generatedSetupName(code),scoped:scoped,run:runDecl?runDecl.toLowerCase():''});
1470
+ var ownerDecl=(attrs.match(/data-stx-owner\\s*=\\s*["']([^"']+)["']/i)||[])[1]||'';
1471
+ fragScripts.push({text:code,slot:slot,setupName:generatedSetupName(code),scoped:scoped,run:runDecl?runDecl.toLowerCase():'',owner:ownerDecl});
1454
1472
  // Retain scoped setup code in its inert placeholder. A placeholder
1455
1473
  // inside template.content is unreachable through document, so the
1456
1474
  // repeated component runtime must execute it for each clone.
@@ -1565,6 +1583,10 @@ else {
1565
1583
  // declarations would throw "Identifier has already been declared"
1566
1584
  // on re-execution. Setup functions (__stx_setup_) must always
1567
1585
  // re-execute because each page has its own setup.
1586
+ if(ownerStays(entry.owner)){
1587
+ log('[router] skipping component that stayed on the page:', entry.owner);
1588
+ return;
1589
+ }
1568
1590
  var h=hashScript(code);
1569
1591
  var isSetup=code.indexOf('__stx_setup_')!==-1;
1570
1592
  // Self-contained scope scripts must re-execute on every navigation:
@@ -1788,7 +1810,7 @@ else {
1788
1810
  var slot='document-'+(++routedBodyScriptId);
1789
1811
  var setupName=generatedSetupName(text);
1790
1812
  if(setupName)incomingSetupName=setupName;
1791
- routedBodyScripts.push({text:text,runAlways:true,slot:slot,setupName:setupName,run:s.getAttribute('data-stx-run')||''});
1813
+ routedBodyScripts.push({text:text,runAlways:true,slot:slot,setupName:setupName,run:s.getAttribute('data-stx-run')||'',owner:s.getAttribute('data-stx-owner')||''});
1792
1814
  s.textContent='';
1793
1815
  s.setAttribute('type','application/stx-pending');
1794
1816
  s.setAttribute('data-stx-route-script',slot);
@@ -1857,8 +1879,8 @@ else {
1857
1879
  document.querySelectorAll('script[data-stx-page]').forEach(function(s){s.remove()});
1858
1880
 
1859
1881
  var scripts=routedBodyScripts.slice();
1860
- function addScript(text, runAlways, slot){
1861
- scripts.push({text:text,runAlways:!!runAlways,slot:slot||''});
1882
+ function addScript(text, runAlways, slot, owner){
1883
+ scripts.push({text:text,runAlways:!!runAlways,slot:slot||'',owner:owner||''});
1862
1884
  }
1863
1885
  if(isLayoutChange){
1864
1886
  // Also collect setup functions from <head>
@@ -1888,7 +1910,9 @@ else {
1888
1910
  var key=text.substring(0,80);
1889
1911
  if(seenSetups[key])return;
1890
1912
  seenSetups[key]=1;
1891
- addScript(text,true);
1913
+ // A layout component outside the container carries its owner, so
1914
+ // execScripts skips it when it stayed on the page (#1958).
1915
+ addScript(text,true,'',s.getAttribute('data-stx-owner')||'');
1892
1916
  });
1893
1917
  }
1894
1918
  // Component setup scripts also assign window.stx._latestSetup. Run the
@@ -1959,6 +1983,7 @@ else {
1959
1983
  scripts.forEach(function(entry){
1960
1984
  var text=typeof entry==='string'?entry:entry.text;
1961
1985
  var runAlways=typeof entry==='string'?false:entry.runAlways;
1986
+ if(typeof entry!=='string'&&ownerStays(entry.owner))return;
1962
1987
  // Skip scripts that were already executed (layout-level partials
1963
1988
  // like theme.stx). Their top-level const/function declarations
1964
1989
  // would throw "Identifier has already been declared" on re-execution.
package/dist/serve.js CHANGED
@@ -9685,7 +9685,7 @@ function __stxOverlay(errs){
9685
9685
  pageMiddlewarePatterns.length = 0;
9686
9686
  await Promise.all(files.map((f) => detectPageMiddleware(f)));
9687
9687
  try {
9688
- const { Router } = await import("./chunk-kn8qad4k.js");
9688
+ const { Router } = await import("./chunk-2qeayf8n.js");
9689
9689
  const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
9690
9690
  const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName() });
9691
9691
  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.287",
4
+ "version": "0.2.288",
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",