@stacksjs/stx 0.2.113 → 0.2.114

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.
@@ -49,7 +49,7 @@ export declare function stripDocumentWrapper(html: string, options?: { preserveH
49
49
  export declare function isSpaNavigation(request: Request): boolean;
50
50
  /**
51
51
  * Extract the inner content of the router container element from a full HTML
52
- * document, preserving any `<style>` tags found in `<head>`.
52
+ * document, preserving page styles and route state found in `<head>`.
53
53
  *
54
54
  * This is what fragment files should contain — NOT the whole body. The SPA
55
55
  * router injects fragments directly into the container element via innerHTML,
package/dist/app-shell.js CHANGED
@@ -161,12 +161,15 @@ export function isSpaNavigation(request) {
161
161
  return request.headers.get("X-STX-Router") === "true";
162
162
  }
163
163
  export function extractContainerContent(html, containerSelector = "main") {
164
- const trimmed = html.trim(), headStyles = [], headMatch = trimmed.match(/<head\b[^>]*>([\s\S]*?)<\/head>/i);
164
+ const trimmed = html.trim(), headStyles = [], headScripts = [], headMatch = trimmed.match(/<head\b[^>]*>([\s\S]*?)<\/head>/i);
165
165
  if (headMatch) {
166
166
  const headContent = headMatch[1], styleRegex = /<style\b[^>]*>[\s\S]*?<\/style>/gi;
167
167
  let m;
168
168
  while ((m = styleRegex.exec(headContent)) !== null)
169
169
  headStyles.push(m[0]);
170
+ const routeParamsRegex = /<script\b[^>]*data-stx-route-params[^>]*>[\s\S]*?<\/script>/gi;
171
+ while ((m = routeParamsRegex.exec(headContent)) !== null)
172
+ headScripts.push(m[0]);
170
173
  }
171
174
  const tag = containerSelector.replace(/^[.#]/, "").toLowerCase(), openRe = new RegExp(`<${tag}\\b[^>]*>`, "i"), openMatch = trimmed.match(openRe);
172
175
  if (!openMatch || openMatch.index === void 0)
@@ -210,6 +213,9 @@ export function extractContainerContent(html, containerSelector = "main") {
210
213
  const parts = [];
211
214
  if (headStyles.length > 0)
212
215
  parts.push(headStyles.join(`
216
+ `));
217
+ if (headScripts.length > 0)
218
+ parts.push(headScripts.join(`
213
219
  `));
214
220
  if (bodyScripts.length > 0)
215
221
  parts.push(bodyScripts.join(`
package/dist/caching.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- import { fileExists } from "./utils.js";
3
+ import { clearComponentCache, fileExists } from "./utils.js";
4
4
  export const templateCache = new Map;
5
5
  const fileContentCache = new Map;
6
6
  export async function readFileCached(filePath) {
@@ -53,6 +53,7 @@ export async function getCachedRouterScript() {
53
53
  }
54
54
  export function clearDevCaches() {
55
55
  fileContentCache.clear();
56
+ clearComponentCache();
56
57
  _cachedSignalsRuntime = null;
57
58
  _cachedSignalsRuntimeDev = null;
58
59
  _cachedRouterScript = null;