bun-plugin-stx 0.2.289 → 0.2.291

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.
@@ -1821,6 +1821,13 @@ else {
1821
1821
  log('[router] full body swap for layout change');
1822
1822
  // Replace entire body content \u2014 layout chrome and all
1823
1823
  var bodyHTML=newBody.innerHTML;
1824
+ // The outgoing chrome's components are destroyed with it (#1958).
1825
+ // They are no longer re-run on every navigation, so they live as long
1826
+ // as their layout does, and _cleanupContainer above only covered the
1827
+ // container: their onDestroy and their scopes waited for the next
1828
+ // navigation's orphan sweep, and their effects were never disposed.
1829
+ // Before the swap, while the old markup is still here to walk.
1830
+ if(window.stx&&window.stx._cleanupContainer)window.stx._cleanupContainer(document.body);
1824
1831
  document.body.innerHTML=bodyHTML;
1825
1832
  // Copy body attributes (class, data-stx, etc.)
1826
1833
  Array.from(newBody.attributes).forEach(function(attr){document.body.setAttribute(attr.name,attr.value)});
@@ -1906,6 +1913,18 @@ else {
1906
1913
  if(isSignalsRuntimeScript(s,text))return;
1907
1914
  if(text.indexOf('__stxRouter')!==-1)return;
1908
1915
  if(newContent.contains(s))return;
1916
+ // Code only, as prepareRoutedBodyScripts takes it. A layout island's
1917
+ // type="stx/island" script is hydrated by its own trigger, and one
1918
+ // collected here was set up on every navigation, the trigger or not.
1919
+ var scriptType=(s.getAttribute('type')||'').trim().toLowerCase();
1920
+ if(scriptType&&scriptType!=='text/javascript'&&scriptType!=='application/javascript'&&scriptType!=='module')return;
1921
+ // A component with no scope root has no root for the owner check,
1922
+ // so its script is marked data-stx-instance instead. Out here it
1923
+ // belongs to the layout chrome, which this swap leaves in place with
1924
+ // its instance running; running it again set up a second one, and a
1925
+ // stx.mount wrapper re-run from here mounted onto the container, the
1926
+ // incoming page's content (#1958). Fragments leave these out.
1927
+ if(s.hasAttribute('data-stx-instance'))return;
1909
1928
  if(text.indexOf('__stx_setup_')===-1&&!s.hasAttribute('data-stx-scoped')&&!s.hasAttribute('data-stx-page')&&!s.hasAttribute('data-stx-route-params'))return;
1910
1929
  var key=text.substring(0,80);
1911
1930
  if(seenSetups[key])return;
package/dist/serve.d.ts CHANGED
@@ -226,6 +226,7 @@ export declare interface ServeOptions {
226
226
  renderCacheVary?: 'request' | 'source'
227
227
  cssCacheLimit?: number
228
228
  prewarmRenderCache?: boolean | number
229
+ imageWarmupGraceMs?: number
229
230
  publicDir?: string
230
231
  quiet?: boolean
231
232
  autoIncrementPort?: boolean | number
package/dist/serve.js CHANGED
@@ -8805,6 +8805,7 @@ async function runPageMiddleware(options) {
8805
8805
  }
8806
8806
 
8807
8807
  // src/serve.ts
8808
+ var INSTANCE_SCRIPT_OPEN_TAG = /^<script\b[^>]*\sdata-stx-(?:owner|instance)(?=[\s=/>])/i;
8808
8809
  var ENGINE_PACKAGE_ENTRIES = [
8809
8810
  ["@stacksjs", "ts-css", "dist", "engine", "index.js"],
8810
8811
  ["@stacksjs", "ts-css", "src", "engine", "index.ts"]
@@ -9204,6 +9205,20 @@ async function serve(options) {
9204
9205
  const placeholdersReady = new Promise((resolve13) => {
9205
9206
  markPlaceholdersReady = resolve13;
9206
9207
  });
9208
+ let placeholdersAreReady = false;
9209
+ const imageWarmupGraceMs = Math.max(0, options.imageWarmupGraceMs ?? 1000);
9210
+ function awaitImageWarmup() {
9211
+ if (placeholdersAreReady || imageWarmupGraceMs === 0)
9212
+ return;
9213
+ return new Promise((resolve13) => {
9214
+ const timer = setTimeout(resolve13, imageWarmupGraceMs);
9215
+ timer.unref?.();
9216
+ placeholdersReady.then(() => {
9217
+ clearTimeout(timer);
9218
+ resolve13();
9219
+ });
9220
+ });
9221
+ }
9207
9222
  const stxModule = options.stxModule ? Promise.resolve(options.stxModule) : defaultStxModule;
9208
9223
  const imageDeliveryOutputDir = stateDir(process19.cwd(), "image-delivery");
9209
9224
  const imageDeliveryRoot = nodePath.join(imageDeliveryOutputDir, "_stx", "images");
@@ -9685,7 +9700,7 @@ function __stxOverlay(errs){
9685
9700
  pageMiddlewarePatterns.length = 0;
9686
9701
  await Promise.all(files.map((f) => detectPageMiddleware(f)));
9687
9702
  try {
9688
- const { Router } = await import("./chunk-2qeayf8n.js");
9703
+ const { Router } = await import("./chunk-hzb7bk1k.js");
9689
9704
  const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
9690
9705
  const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName() });
9691
9706
  if (!options.quiet)
@@ -9971,7 +9986,7 @@ function __stxOverlay(errs){
9971
9986
  } else {
9972
9987
  output = output.replace(/<template[^>]*>/gi, "").replace(/<\/template>/gi, "");
9973
9988
  }
9974
- if (ENABLE_HTML_CACHE && !context.__stx_skip_cache && !skipCacheHint && !isMutating && isRenderableCacheCandidate(output)) {
9989
+ if (ENABLE_HTML_CACHE && !context.__stx_skip_cache && !skipCacheHint && !isMutating && isRenderableCacheCandidate(output) && placeholdersAreReady) {
9975
9990
  const signature = await buildTemplateSignature(filePath, dependencies);
9976
9991
  htmlCache.set(htmlCacheKey(filePath, reqCtx), { html: output, signature, status: reqCtx?.responseStatus ?? 200, headers: reqCtx?.responseHeaders });
9977
9992
  }
@@ -10273,7 +10288,9 @@ ${block}`;
10273
10288
  reusePort: options.reusePort ?? false,
10274
10289
  idleTimeout: production ? 30 : 0,
10275
10290
  async fetch(req, server) {
10276
- await placeholdersReady;
10291
+ const warmup = awaitImageWarmup();
10292
+ if (warmup)
10293
+ await warmup;
10277
10294
  return compressResponse(req, await (async () => {
10278
10295
  const url = new URL(req.url);
10279
10296
  let path = url.pathname;
@@ -10697,6 +10714,8 @@ ${block}`;
10697
10714
  const insideMain = mainContentStart !== -1 && offset >= mainContentStart && offset < mainContentEnd;
10698
10715
  if (insideMain || pageSetupScriptOffsets.has(offset))
10699
10716
  return;
10717
+ if (mainContentStart !== -1 && INSTANCE_SCRIPT_OPEN_TAG.test(match[0]))
10718
+ return;
10700
10719
  pageSetupScriptOffsets.add(offset);
10701
10720
  pageSetupScripts.push(match[0]);
10702
10721
  };
@@ -10989,6 +11008,7 @@ ${trailingPageScripts.join(`
10989
11008
  if (deliveryResult.status === "fulfilled" && deliveryResult.value.count > 0 && !production)
10990
11009
  console.log(`[stx] optimized ${deliveryResult.value.count} image(s) for responsive delivery`);
10991
11010
  } catch {} finally {
11011
+ placeholdersAreReady = true;
10992
11012
  markPlaceholdersReady();
10993
11013
  }
10994
11014
  })();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.289",
4
+ "version": "0.2.291",
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",