@takazudo/zfb-runtime 3.1.0 → 3.2.0
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.
- package/dist/client-router/prefetch.js.map +1 -1
- package/dist/client-router/router.js +3 -1
- package/dist/client-router/router.js.map +1 -1
- package/dist/client-router/swap-functions.d.ts +3 -1
- package/dist/client-router/swap-functions.js +14 -0
- package/dist/client-router/swap-functions.js.map +1 -1
- package/dist/client-router-component.js.map +1 -1
- package/dist/router.js +77 -3
- package/dist/router.js.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swap-functions.js","sourceRoot":"","sources":["../../src/client-router/swap-functions.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,oCAAoC;AACpC,+EAA+E;AAC/E,mFAAmF;AACnF,2FAA2F;AAC3F,mFAAmF;AACnF,8EAA8E;AAQ9E,MAAM,YAAY,GAAG,6BAA6B,CAAC;AAEnD,gFAAgF;AAChF,kEAAkE;AAClE,+EAA+E;AAC/E,gFAAgF;AAChF,uEAAuE;AACvE,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,8EAA8E;AAC9E,gFAAgF;AAChF,kFAAkF;AAClF,iEAAiE;AACjE,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAEtD,MAAM,yBAAyB,GAAG,CAAC,qBAAqB,EAAE,8BAA8B,CAAC,CAAC;AAE1F,6EAA6E;AAC7E,0DAA0D;AAC1D,yEAAyE;AACzE,oEAAoE;AACpE,iFAAiF;AACjF,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAE3D,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAA4B,CAAC;AAEjE,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;AAC5C,MAAM,UAAU,oBAAoB,CAAC,MAAyB;IAC5D,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,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AC,YAAY,CAAC,CAAC;AAC/E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,eAAe;IACf,kBAAkB;IAClB,gBAAgB;IAChB,eAAe;IACf,SAAS;CACV,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAa,EAAE,EAAE;IACpC,eAAe,CAAC,GAAG,CAAC,CAAC;IACrB,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACxB,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACtB,MAAM,oBAAoB,GAAG,SAAS,EAAE,CAAC;IACzC,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IACzC,oBAAoB,EAAE,CAAC;AACzB,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n/// <reference lib=\"dom.iterable\" />\n// Ported verbatim from Astro transitions/swap-functions.ts. Mechanical renames\n// applied per W1B §13.4 (data-astro-* → data-zfb-*, dataset.astro* → dataset.zfb*,\n// astro-island element-name branch → data-zfb-island marker per W1B §12.3 island-lifecycle\n// contract). vueScopedStyleId is intentionally KEPT verbatim per W2A §2.8 (the W3B\n// issue body's \"DELETE\" instruction is overridden by W2A's reclassification).\n\nexport type SavedFocus = {\n activeElement: HTMLElement | null;\n start?: number | null;\n end?: number | null;\n};\n\nconst PERSIST_ATTR = \"data-zfb-transition-persist\";\n\n// Cross-package island attributes must use the same literal strings here and in\n// @takazudo/zfb's runtime: PERSIST_ATTR is read by both packages;\n// ISLAND_REMOUNT_ATTR below is written here and consumed there; that runtime's\n// public ISLAND_MOUNTED_ATTR (\"data-zfb-island-mounted\") is preserved on lifted\n// islands and cleared/re-written there during a props-changed remount.\n//\n// ISLAND_REMOUNT_ATTR is written onto a persisted island whose props changed\n// across the swap. @takazudo/zfb's mountNewIslands consumes it — the island\n// mounted-map lives in that separate package, so a DOM attribute is the only\n// channel the two packages share. Namespaced under data-zfb-* like every other\n// zfb marker so it can't collide with a bare attribute a consumer sets on the\n// same island root. Replaces the opaque `ssr` attribute the original Astro port\n// set here but nothing consumed — zfb islands are marker divs, not <astro-island>\n// custom elements. See client-router/port-spec.md §12.3 / #1389.\nconst ISLAND_REMOUNT_ATTR = \"data-zfb-island-remount\";\n\nconst NON_OVERRIDABLE_ZFB_ATTRS = [\"data-zfb-transition\", \"data-zfb-transition-fallback\"];\n\n// Consumers extend the preserve-set via <meta name=\"zfb-preserve-html-attrs\"\n// content=\"data-theme data-sidebar-hidden …\">, emitted by\n// <ClientRouter preserveHtmlAttrs={[…]} />. Without it, a runtime <html>\n// attribute set from a persisted island is wiped on every swap. See\n// client-router/port-spec.md deviation #11 and Takazudo/zudo-front-builder#1103.\nconst PRESERVE_ATTRS_META_NAME = \"zfb-preserve-html-attrs\";\n\nconst knownVueScopedStyles = new Map<string, HTMLStyleElement>();\n\nconst scriptsAlreadyRan = new Set<string>();\nexport function detectScriptExecuted(script: HTMLScriptElement) {\n const key = script.src ? new URL(script.src, location.href).href : script.textContent!;\n if (scriptsAlreadyRan.has(key)) return true;\n scriptsAlreadyRan.add(key);\n return false;\n}\n\n/*\n * \tMark new scripts that should not execute\n */\nexport function deselectScripts(doc: Document) {\n for (const s2 of doc.scripts) {\n if (\n // Check if the script should be rerun regardless of it being the same\n !s2.hasAttribute(\"data-zfb-rerun\") &&\n // Check if the script has already been executed\n detectScriptExecuted(s2)\n ) {\n // the old script is in the new document and doesn't have the rerun attribute\n // we mark it as executed to prevent re-execution\n s2.dataset[\"zfbExec\"] = \"\";\n }\n }\n}\n\n/*\n * Read the consumer-configured preserve-list from the live document's\n * <meta name=\"zfb-preserve-html-attrs\"> tag. The list is a site-wide, static\n * contract (the tag is rendered on every page, so it is present on both the\n * current and incoming documents); reading the live document is sufficient.\n * Returns [] when the tag is absent.\n */\nfunction consumerPreservedAttrs(): string[] {\n const content = document\n .querySelector(`meta[name=\"${PRESERVE_ATTRS_META_NAME}\"]`)\n ?.getAttribute(\"content\");\n // Attribute names are ASCII-case-insensitive and the DOM exposes them\n // lowercased, so normalize the list to match (NON_OVERRIDABLE_ZFB_ATTRS is\n // already lowercase). Without this, a mixed-case entry would silently never\n // match the live attribute name.\n return content ? content.toLowerCase().split(/\\s+/).filter(Boolean) : [];\n}\n\nconst attrValueSelector = (attr: string, value: string): string =>\n value === \"\" ? `[${attr}=\"\"]` : `[${attr}=${CSS.escape(value)}]`;\n\nconst querySelectorWithAttrValue = (\n root: ParentNode,\n selectorPrefix: string,\n attr: string,\n value: string,\n): Element | null => {\n const escapedMatch = root.querySelector(`${selectorPrefix}${attrValueSelector(attr, value)}`);\n if (escapedMatch) return escapedMatch;\n return (\n Array.from(root.querySelectorAll(`${selectorPrefix}[${attr}]`)).find(\n (el) => el.getAttribute(attr) === value,\n ) ?? null\n );\n};\n\n/*\n * swap attributes of the html element\n * delete all attributes from the current document\n * insert all attributes from doc\n * reinsert all original attributes whose name is in the preserve-set:\n * NON_OVERRIDABLE_ZFB_ATTRS (transition-internal) ∪ the consumer preserve-list.\n * Preserved attributes are re-applied last, so a runtime value on the current\n * root wins over the incoming document's default (e.g. a localStorage-driven\n * data-theme). See client-router/port-spec.md deviation #11 / #1103.\n */\nexport function swapRootAttributes(newDoc: Document) {\n const currentRoot = document.documentElement;\n const preserve = new Set([...NON_OVERRIDABLE_ZFB_ATTRS, ...consumerPreservedAttrs()]);\n const preservedAttributes = [...currentRoot.attributes].filter(\n ({ name }) => (currentRoot.removeAttribute(name), preserve.has(name)),\n );\n [...newDoc.documentElement.attributes, ...preservedAttributes].forEach(({ name, value }) =>\n currentRoot.setAttribute(name, value),\n );\n}\n\n/*\n * make the old head look like the new one\n */\nexport function swapHeadElements(doc: Document) {\n for (const el of Array.from(document.head.children)) {\n const newEl = persistedHeadElement(el as HTMLElement, doc);\n // If the element exists in the document already, remove it\n // from the new document and leave the current node alone\n if (newEl) {\n newEl.remove();\n } else {\n if ((import.meta as any).env?.DEV && el instanceof HTMLStyleElement) {\n // In DEV mode, keep updated Vue scoped styles for later reuse\n const viteDevId = vueScopedStyleId(el);\n viteDevId && knownVueScopedStyles.set(viteDevId, el);\n }\n // If the element does not exist in the new document, remove the element from current the head.\n el.remove();\n }\n }\n\n // Everything left in the new head is new, append it all.\n if ((import.meta as any).env?.DEV) {\n // In DEV mode, replace known Vue scoped styles with the versions we remembered\n [...doc.head.children].forEach((child) => {\n document.head.append(knownVueScopedStyles.get((child as any).dataset?.viteDevId) || child);\n });\n } else {\n document.head.append(...doc.head.children);\n }\n}\n\nexport function swapBodyElement(newElement: Element, oldElement: Element) {\n // Lift persist elements to <html> before the body swap so they stay in the DOM\n // throughout replaceWith(). This prevents Safari from losing WebGL context on\n // <canvas> elements due to brief DOM detachment. Uses moveBefore() where available\n // (Chrome 133+) for zero-detachment atomic moves.\n const persistPairs: { old: Element; newTarget: Element; oldAncestors: Element[] }[] = [];\n const docEl = oldElement.ownerDocument.documentElement;\n\n // moveBefore() is not yet in TypeScript's DOM lib, feature-detect and wrap.\n const moveBefore: ((parent: Node, node: Node, child: Node | null) => void) | null =\n typeof (docEl as any).moveBefore === \"function\"\n ? (parent, node, child) => (parent as any).moveBefore(node, child)\n : null;\n\n // Snapshot matches and ancestry before moving anything. A nested old node can\n // have an incoming target outside its old parent (or inside another matched\n // target), so neither tree can be inspected reliably once lifting begins.\n for (const el of oldElement.querySelectorAll(`[${PERSIST_ATTR}]`)) {\n const id = el.getAttribute(PERSIST_ATTR);\n const newEl = id !== null ? querySelectorWithAttrValue(newElement, \"\", PERSIST_ATTR, id) : null;\n if (!newEl) continue; // no matching target — leave in old body to be discarded\n const oldAncestors: Element[] = [];\n for (let ancestor = el.parentElement; ancestor; ancestor = ancestor.parentElement) {\n oldAncestors.push(ancestor);\n }\n persistPairs.push({ old: el, newTarget: newEl, oldAncestors });\n }\n\n const matchedTargets = new Set(persistPairs.map(({ newTarget }) => newTarget));\n const liftedPairs = persistPairs.filter(({ newTarget }) => {\n for (\n let ancestor = newTarget.parentElement;\n ancestor && ancestor !== newElement;\n ancestor = ancestor.parentElement\n ) {\n if (matchedTargets.has(ancestor)) return false;\n }\n return true;\n });\n const liftedNodes = new Set(liftedPairs.map(({ old }) => old));\n const retainedPairs = persistPairs.filter(\n ({ old, oldAncestors }) =>\n liftedNodes.has(old) || oldAncestors.some((ancestor) => liftedNodes.has(ancestor)),\n );\n\n for (const { old: el } of liftedPairs) {\n if (moveBefore) {\n moveBefore(docEl, el, null);\n } else {\n docEl.appendChild(el);\n }\n }\n\n // this will reset scroll Position\n oldElement.replaceWith(newElement);\n\n // Move persist elements into the new body at the position of their targets\n for (const { old: el, newTarget } of liftedPairs) {\n if (moveBefore) {\n moveBefore(newTarget.parentNode!, el, newTarget);\n newTarget.remove();\n } else {\n newTarget.replaceWith(el);\n }\n }\n\n // Riding children are retained too: compare their incoming island metadata\n // even though their DOM nodes were not moved independently.\n for (const { old: el, newTarget } of retainedPairs) {\n const islandAttrs = [\n \"data-zfb-island\",\n \"data-zfb-island-skip-ssr\",\n \"data-zfb-transport\",\n \"data-zfb-protocol\",\n \"data-zfb-build\",\n ];\n const isIsland = islandAttrs\n .slice(0, 2)\n .some((attr) => el.hasAttribute(attr) || newTarget.hasAttribute(attr));\n if (isIsland) {\n const identityChanged = islandAttrs.some(\n (attr) => el.getAttribute(attr) !== newTarget.getAttribute(attr),\n );\n const copyProps = shouldCopyProps(el as HTMLElement);\n if (identityChanged || (copyProps && !isSameProps(el, newTarget))) {\n el.setAttribute(ISLAND_REMOUNT_ATTR, \"\");\n for (const attr of islandAttrs) {\n const value = newTarget.getAttribute(attr);\n if (value === null) el.removeAttribute(attr);\n else el.setAttribute(attr, value);\n }\n if (copyProps) {\n const props = newTarget.getAttribute(\"data-props\");\n if (props === null) el.removeAttribute(\"data-props\");\n else el.setAttribute(\"data-props\", props);\n }\n }\n }\n }\n\n // This will upgrade any Declarative Shadow DOM in the new body.\n attachShadowRoots(newElement);\n}\n\n/**\n * Attach Shadow DOM roots for templates with the declarative `shadowrootmode` attribute.\n * @see https://web.dev/articles/declarative-shadow-dom#polyfill\n * @param root DOM subtree to attach shadow roots within.\n */\nfunction attachShadowRoots(root: Element | ShadowRoot) {\n root.querySelectorAll<HTMLTemplateElement>(\"template[shadowrootmode]\").forEach((template) => {\n const mode = template.getAttribute(\"shadowrootmode\");\n const parent = template.parentNode;\n if ((mode === \"closed\" || mode === \"open\") && parent instanceof HTMLElement) {\n // Skip if shadow root already exists (e.g., from transition-persisted elements)\n if (parent.shadowRoot) {\n template.remove();\n return;\n }\n const shadowRoot = parent.attachShadow({ mode });\n shadowRoot.appendChild(template.content);\n template.remove();\n attachShadowRoots(shadowRoot);\n }\n });\n}\n\nexport const saveFocus = (): (() => void) => {\n const activeElement = document.activeElement as HTMLElement;\n // The element that currently has the focus is part of a DOM tree\n // that will survive the transition to the new document.\n // Save the element and the cursor position\n if (activeElement?.closest(`[${PERSIST_ATTR}]`)) {\n if (activeElement instanceof HTMLInputElement || activeElement instanceof HTMLTextAreaElement) {\n const start = activeElement.selectionStart;\n const end = activeElement.selectionEnd;\n return () => restoreFocus({ activeElement, start, end });\n }\n return () => restoreFocus({ activeElement });\n } else {\n return () => restoreFocus({ activeElement: null });\n }\n};\n\nexport const restoreFocus = ({ activeElement, start, end }: SavedFocus) => {\n if (activeElement) {\n activeElement.focus();\n if (activeElement instanceof HTMLInputElement || activeElement instanceof HTMLTextAreaElement) {\n if (typeof start === \"number\") activeElement.selectionStart = start;\n if (typeof end === \"number\") activeElement.selectionEnd = end;\n }\n }\n};\n\nexport const vueScopedStyleId = (el: HTMLStyleElement): string => {\n const viteDevId = el.dataset[\"viteDevId\"] || \"\";\n\n const url = new URL(viteDevId, location.href);\n return url.searchParams.get(\"vue\") !== null &&\n url.searchParams.get(\"type\") === \"style\" &&\n url.searchParams.has(\"scoped\")\n ? viteDevId\n : \"\";\n};\n\n// Check for a head element that should persist and returns it,\n// either because it has the data attribute or because replacing it would cause avoidable FOUC.\nconst persistedHeadElement = (el: HTMLElement, newDoc: Document): Element | null => {\n const id = el.getAttribute(PERSIST_ATTR);\n const newEl = id !== null ? querySelectorWithAttrValue(newDoc.head, \"\", PERSIST_ATTR, id) : null;\n if (newEl) {\n return newEl;\n }\n if (el.matches(\"link[rel=stylesheet]\")) {\n const href = el.getAttribute(\"href\");\n return href !== null\n ? querySelectorWithAttrValue(newDoc.head, \"link[rel=stylesheet]\", \"href\", href)\n : null;\n }\n // In dev mode, Vite injects <style data-vite-dev-id=\"...\"> elements whose\n // textContent may later be transformed (especially Vue's `:deep()` → `[data-v-xxx]`).\n // Match these by their stable dev ID so the already-transformed style is preserved\n // across ClientRouter soft navigations instead of being replaced by the raw version.\n // There are other ids that can't be preserved and need a refresh, like Uno's /__uno.css,\n // which keeps the same id, but with different contents.\n // To avoid enumerating all exceptions, we only apply the auto-persist logic to elements\n // that look like Vue's dev styles.\n if ((import.meta as any).env?.DEV && el instanceof HTMLStyleElement) {\n const viteDevId = vueScopedStyleId(el);\n if (viteDevId) {\n return querySelectorWithAttrValue(newDoc.head, \"style\", \"data-vite-dev-id\", viteDevId);\n }\n }\n // Preserve inline <style> elements with identical content across navigations.\n // This prevents unnecessary removal and re-insertion of styles (e.g. @font-face\n // declarations from <Font>), which would cause the browser to re-evaluate them\n // and trigger a flash of unstyled text (FOUT).\n if (el.tagName === \"STYLE\" && el.textContent) {\n const styles = newDoc.head.querySelectorAll(\"style\");\n for (const s of styles) {\n if (s.textContent === el.textContent) {\n return s;\n }\n }\n }\n // Preserve font preload links across navigations to avoid re-fetching cached fonts.\n if (el.matches(\"link[rel=preload][as=font]\")) {\n const href = el.getAttribute(\"href\");\n return href !== null\n ? querySelectorWithAttrValue(newDoc.head, \"link[rel=preload][as=font]\", \"href\", href)\n : null;\n }\n return null;\n};\n\nconst shouldCopyProps = (el: HTMLElement): boolean => {\n const persistProps = el.dataset[\"zfbTransitionPersistProps\"];\n return persistProps == null || persistProps === \"false\";\n};\n\nconst isSameProps = (oldEl: Element, newEl: Element) => {\n // zfb island wrapper writes SSR props to data-props, not props (different attribute, not just renamed).\n return oldEl.getAttribute(\"data-props\") === newEl.getAttribute(\"data-props\");\n};\n\nexport const swapFunctions = {\n deselectScripts,\n swapRootAttributes,\n swapHeadElements,\n swapBodyElement,\n saveFocus,\n};\n\nexport const swap = (doc: Document) => {\n deselectScripts(doc);\n swapRootAttributes(doc);\n swapHeadElements(doc);\n const restoreFocusFunction = saveFocus();\n swapBodyElement(doc.body, document.body);\n restoreFocusFunction();\n};\n"]}
|
|
1
|
+
{"version":3,"file":"swap-functions.js","sourceRoot":"","sources":["../../src/client-router/swap-functions.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,oCAAoC;AACpC,+EAA+E;AAC/E,mFAAmF;AACnF,2FAA2F;AAC3F,mFAAmF;AACnF,8EAA8E;AAQ9E,MAAM,YAAY,GAAG,6BAA6B,CAAC;AAEnD,oFAAoF;AACpF,MAAM,UAAU,uBAAuB,CAAC,IAAgB,EAAE,KAAa;IACrE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;QACjE,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC,YAAY,CAAE,CAAC;QAChD,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YACf,MAAM,IAAI,SAAS,CACjB,0BAA0B,KAAK,gDAAgD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CACrG,CAAC;QACJ,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,kEAAkE;AAClE,+EAA+E;AAC/E,gFAAgF;AAChF,uEAAuE;AACvE,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,8EAA8E;AAC9E,gFAAgF;AAChF,kFAAkF;AAClF,iEAAiE;AACjE,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AC,MAAM,CAAC,IAAI,EAAE,4BAA4B,EAAE,MAAM,EAAE,IAAI,CAAC;YACrF,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,EAAe,EAAW,EAAE;IACnD,MAAM,YAAY,GAAG,EAAE,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAC7D,OAAO,YAAY,IAAI,IAAI,IAAI,YAAY,KAAK,OAAO,CAAC;AAC1D,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,KAAc,EAAE,KAAc,EAAE,EAAE;IACrD,wGAAwG;IACxG,OAAO,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,KAAK,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;AAC/E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,eAAe;IACf,kBAAkB;IAClB,gBAAgB;IAChB,eAAe;IACf,SAAS;CACV,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAa,EAAE,EAAE;IACpC,uBAAuB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC7C,uBAAuB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACzC,eAAe,CAAC,GAAG,CAAC,CAAC;IACrB,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACxB,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACtB,MAAM,oBAAoB,GAAG,SAAS,EAAE,CAAC;IACzC,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IACzC,oBAAoB,EAAE,CAAC;AACzB,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n/// <reference lib=\"dom.iterable\" />\n// Ported verbatim from Astro transitions/swap-functions.ts. Mechanical renames\n// applied per W1B §13.4 (data-astro-* → data-zfb-*, dataset.astro* → dataset.zfb*,\n// astro-island element-name branch → data-zfb-island marker per W1B §12.3 island-lifecycle\n// contract). vueScopedStyleId is intentionally KEPT verbatim per W2A §2.8 (the W3B\n// issue body's \"DELETE\" instruction is overridden by W2A's reclassification).\n\nexport type SavedFocus = {\n activeElement: HTMLElement | null;\n start?: number | null;\n end?: number | null;\n};\n\nconst PERSIST_ATTR = \"data-zfb-transition-persist\";\n\n/** Validate before teardown: ambiguous keys must never choose an arbitrary node. */\nexport function assertUniquePersistKeys(root: ParentNode, label: string): void {\n const seen = new Set<string>();\n for (const element of root.querySelectorAll(`[${PERSIST_ATTR}]`)) {\n const key = element.getAttribute(PERSIST_ATTR)!;\n if (seen.has(key))\n throw new TypeError(\n `ZFB_PERSIST_DUPLICATE: ${label} document contains duplicate persistence key ${JSON.stringify(key)}`,\n );\n seen.add(key);\n }\n}\n\n// Cross-package island attributes must use the same literal strings here and in\n// @takazudo/zfb's runtime: PERSIST_ATTR is read by both packages;\n// ISLAND_REMOUNT_ATTR below is written here and consumed there; that runtime's\n// public ISLAND_MOUNTED_ATTR (\"data-zfb-island-mounted\") is preserved on lifted\n// islands and cleared/re-written there during a props-changed remount.\n//\n// ISLAND_REMOUNT_ATTR is written onto a persisted island whose props changed\n// across the swap. @takazudo/zfb's mountNewIslands consumes it — the island\n// mounted-map lives in that separate package, so a DOM attribute is the only\n// channel the two packages share. Namespaced under data-zfb-* like every other\n// zfb marker so it can't collide with a bare attribute a consumer sets on the\n// same island root. Replaces the opaque `ssr` attribute the original Astro port\n// set here but nothing consumed — zfb islands are marker divs, not <astro-island>\n// custom elements. See client-router/port-spec.md §12.3 / #1389.\nconst ISLAND_REMOUNT_ATTR = \"data-zfb-island-remount\";\n\nconst NON_OVERRIDABLE_ZFB_ATTRS = [\"data-zfb-transition\", \"data-zfb-transition-fallback\"];\n\n// Consumers extend the preserve-set via <meta name=\"zfb-preserve-html-attrs\"\n// content=\"data-theme data-sidebar-hidden …\">, emitted by\n// <ClientRouter preserveHtmlAttrs={[…]} />. Without it, a runtime <html>\n// attribute set from a persisted island is wiped on every swap. See\n// client-router/port-spec.md deviation #11 and Takazudo/zudo-front-builder#1103.\nconst PRESERVE_ATTRS_META_NAME = \"zfb-preserve-html-attrs\";\n\nconst knownVueScopedStyles = new Map<string, HTMLStyleElement>();\n\nconst scriptsAlreadyRan = new Set<string>();\nexport function detectScriptExecuted(script: HTMLScriptElement) {\n const key = script.src ? new URL(script.src, location.href).href : script.textContent!;\n if (scriptsAlreadyRan.has(key)) return true;\n scriptsAlreadyRan.add(key);\n return false;\n}\n\n/*\n * \tMark new scripts that should not execute\n */\nexport function deselectScripts(doc: Document) {\n for (const s2 of doc.scripts) {\n if (\n // Check if the script should be rerun regardless of it being the same\n !s2.hasAttribute(\"data-zfb-rerun\") &&\n // Check if the script has already been executed\n detectScriptExecuted(s2)\n ) {\n // the old script is in the new document and doesn't have the rerun attribute\n // we mark it as executed to prevent re-execution\n s2.dataset[\"zfbExec\"] = \"\";\n }\n }\n}\n\n/*\n * Read the consumer-configured preserve-list from the live document's\n * <meta name=\"zfb-preserve-html-attrs\"> tag. The list is a site-wide, static\n * contract (the tag is rendered on every page, so it is present on both the\n * current and incoming documents); reading the live document is sufficient.\n * Returns [] when the tag is absent.\n */\nfunction consumerPreservedAttrs(): string[] {\n const content = document\n .querySelector(`meta[name=\"${PRESERVE_ATTRS_META_NAME}\"]`)\n ?.getAttribute(\"content\");\n // Attribute names are ASCII-case-insensitive and the DOM exposes them\n // lowercased, so normalize the list to match (NON_OVERRIDABLE_ZFB_ATTRS is\n // already lowercase). Without this, a mixed-case entry would silently never\n // match the live attribute name.\n return content ? content.toLowerCase().split(/\\s+/).filter(Boolean) : [];\n}\n\nconst attrValueSelector = (attr: string, value: string): string =>\n value === \"\" ? `[${attr}=\"\"]` : `[${attr}=${CSS.escape(value)}]`;\n\nconst querySelectorWithAttrValue = (\n root: ParentNode,\n selectorPrefix: string,\n attr: string,\n value: string,\n): Element | null => {\n const escapedMatch = root.querySelector(`${selectorPrefix}${attrValueSelector(attr, value)}`);\n if (escapedMatch) return escapedMatch;\n return (\n Array.from(root.querySelectorAll(`${selectorPrefix}[${attr}]`)).find(\n (el) => el.getAttribute(attr) === value,\n ) ?? null\n );\n};\n\n/*\n * swap attributes of the html element\n * delete all attributes from the current document\n * insert all attributes from doc\n * reinsert all original attributes whose name is in the preserve-set:\n * NON_OVERRIDABLE_ZFB_ATTRS (transition-internal) ∪ the consumer preserve-list.\n * Preserved attributes are re-applied last, so a runtime value on the current\n * root wins over the incoming document's default (e.g. a localStorage-driven\n * data-theme). See client-router/port-spec.md deviation #11 / #1103.\n */\nexport function swapRootAttributes(newDoc: Document) {\n const currentRoot = document.documentElement;\n const preserve = new Set([...NON_OVERRIDABLE_ZFB_ATTRS, ...consumerPreservedAttrs()]);\n const preservedAttributes = [...currentRoot.attributes].filter(\n ({ name }) => (currentRoot.removeAttribute(name), preserve.has(name)),\n );\n [...newDoc.documentElement.attributes, ...preservedAttributes].forEach(({ name, value }) =>\n currentRoot.setAttribute(name, value),\n );\n}\n\n/*\n * make the old head look like the new one\n */\nexport function swapHeadElements(doc: Document) {\n for (const el of Array.from(document.head.children)) {\n const newEl = persistedHeadElement(el as HTMLElement, doc);\n // If the element exists in the document already, remove it\n // from the new document and leave the current node alone\n if (newEl) {\n newEl.remove();\n } else {\n if ((import.meta as any).env?.DEV && el instanceof HTMLStyleElement) {\n // In DEV mode, keep updated Vue scoped styles for later reuse\n const viteDevId = vueScopedStyleId(el);\n viteDevId && knownVueScopedStyles.set(viteDevId, el);\n }\n // If the element does not exist in the new document, remove the element from current the head.\n el.remove();\n }\n }\n\n // Everything left in the new head is new, append it all.\n if ((import.meta as any).env?.DEV) {\n // In DEV mode, replace known Vue scoped styles with the versions we remembered\n [...doc.head.children].forEach((child) => {\n document.head.append(knownVueScopedStyles.get((child as any).dataset?.viteDevId) || child);\n });\n } else {\n document.head.append(...doc.head.children);\n }\n}\n\nexport function swapBodyElement(newElement: Element, oldElement: Element) {\n assertUniquePersistKeys(oldElement, \"current\");\n assertUniquePersistKeys(newElement, \"incoming\");\n // Lift persist elements to <html> before the body swap so they stay in the DOM\n // throughout replaceWith(). This prevents Safari from losing WebGL context on\n // <canvas> elements due to brief DOM detachment. Uses moveBefore() where available\n // (Chrome 133+) for zero-detachment atomic moves.\n const persistPairs: { old: Element; newTarget: Element; oldAncestors: Element[] }[] = [];\n const docEl = oldElement.ownerDocument.documentElement;\n\n // moveBefore() is not yet in TypeScript's DOM lib, feature-detect and wrap.\n const moveBefore: ((parent: Node, node: Node, child: Node | null) => void) | null =\n typeof (docEl as any).moveBefore === \"function\"\n ? (parent, node, child) => (parent as any).moveBefore(node, child)\n : null;\n\n // Snapshot matches and ancestry before moving anything. A nested old node can\n // have an incoming target outside its old parent (or inside another matched\n // target), so neither tree can be inspected reliably once lifting begins.\n for (const el of oldElement.querySelectorAll(`[${PERSIST_ATTR}]`)) {\n const id = el.getAttribute(PERSIST_ATTR);\n const newEl = id !== null ? querySelectorWithAttrValue(newElement, \"\", PERSIST_ATTR, id) : null;\n if (!newEl) continue; // no matching target — leave in old body to be discarded\n const oldAncestors: Element[] = [];\n for (let ancestor = el.parentElement; ancestor; ancestor = ancestor.parentElement) {\n oldAncestors.push(ancestor);\n }\n persistPairs.push({ old: el, newTarget: newEl, oldAncestors });\n }\n\n const matchedTargets = new Set(persistPairs.map(({ newTarget }) => newTarget));\n const liftedPairs = persistPairs.filter(({ newTarget }) => {\n for (\n let ancestor = newTarget.parentElement;\n ancestor && ancestor !== newElement;\n ancestor = ancestor.parentElement\n ) {\n if (matchedTargets.has(ancestor)) return false;\n }\n return true;\n });\n const liftedNodes = new Set(liftedPairs.map(({ old }) => old));\n const retainedPairs = persistPairs.filter(\n ({ old, oldAncestors }) =>\n liftedNodes.has(old) || oldAncestors.some((ancestor) => liftedNodes.has(ancestor)),\n );\n\n for (const { old: el } of liftedPairs) {\n if (moveBefore) {\n moveBefore(docEl, el, null);\n } else {\n docEl.appendChild(el);\n }\n }\n\n // this will reset scroll Position\n oldElement.replaceWith(newElement);\n\n // Move persist elements into the new body at the position of their targets\n for (const { old: el, newTarget } of liftedPairs) {\n if (moveBefore) {\n moveBefore(newTarget.parentNode!, el, newTarget);\n newTarget.remove();\n } else {\n newTarget.replaceWith(el);\n }\n }\n\n // Riding children are retained too: compare their incoming island metadata\n // even though their DOM nodes were not moved independently.\n for (const { old: el, newTarget } of retainedPairs) {\n const islandAttrs = [\n \"data-zfb-island\",\n \"data-zfb-island-skip-ssr\",\n \"data-zfb-transport\",\n \"data-zfb-protocol\",\n \"data-zfb-build\",\n ];\n const isIsland = islandAttrs\n .slice(0, 2)\n .some((attr) => el.hasAttribute(attr) || newTarget.hasAttribute(attr));\n if (isIsland) {\n const identityChanged = islandAttrs.some(\n (attr) => el.getAttribute(attr) !== newTarget.getAttribute(attr),\n );\n const copyProps = shouldCopyProps(el as HTMLElement);\n if (identityChanged || (copyProps && !isSameProps(el, newTarget))) {\n el.setAttribute(ISLAND_REMOUNT_ATTR, \"\");\n for (const attr of islandAttrs) {\n const value = newTarget.getAttribute(attr);\n if (value === null) el.removeAttribute(attr);\n else el.setAttribute(attr, value);\n }\n if (copyProps) {\n const props = newTarget.getAttribute(\"data-props\");\n if (props === null) el.removeAttribute(\"data-props\");\n else el.setAttribute(\"data-props\", props);\n }\n }\n }\n }\n\n // This will upgrade any Declarative Shadow DOM in the new body.\n attachShadowRoots(newElement);\n}\n\n/**\n * Attach Shadow DOM roots for templates with the declarative `shadowrootmode` attribute.\n * @see https://web.dev/articles/declarative-shadow-dom#polyfill\n * @param root DOM subtree to attach shadow roots within.\n */\nfunction attachShadowRoots(root: Element | ShadowRoot) {\n root.querySelectorAll<HTMLTemplateElement>(\"template[shadowrootmode]\").forEach((template) => {\n const mode = template.getAttribute(\"shadowrootmode\");\n const parent = template.parentNode;\n if ((mode === \"closed\" || mode === \"open\") && parent instanceof HTMLElement) {\n // Skip if shadow root already exists (e.g., from transition-persisted elements)\n if (parent.shadowRoot) {\n template.remove();\n return;\n }\n const shadowRoot = parent.attachShadow({ mode });\n shadowRoot.appendChild(template.content);\n template.remove();\n attachShadowRoots(shadowRoot);\n }\n });\n}\n\nexport const saveFocus = (): (() => void) => {\n const activeElement = document.activeElement as HTMLElement;\n // The element that currently has the focus is part of a DOM tree\n // that will survive the transition to the new document.\n // Save the element and the cursor position\n if (activeElement?.closest(`[${PERSIST_ATTR}]`)) {\n if (activeElement instanceof HTMLInputElement || activeElement instanceof HTMLTextAreaElement) {\n const start = activeElement.selectionStart;\n const end = activeElement.selectionEnd;\n return () => restoreFocus({ activeElement, start, end });\n }\n return () => restoreFocus({ activeElement });\n } else {\n return () => restoreFocus({ activeElement: null });\n }\n};\n\nexport const restoreFocus = ({ activeElement, start, end }: SavedFocus) => {\n if (activeElement) {\n activeElement.focus();\n if (activeElement instanceof HTMLInputElement || activeElement instanceof HTMLTextAreaElement) {\n if (typeof start === \"number\") activeElement.selectionStart = start;\n if (typeof end === \"number\") activeElement.selectionEnd = end;\n }\n }\n};\n\nexport const vueScopedStyleId = (el: HTMLStyleElement): string => {\n const viteDevId = el.dataset[\"viteDevId\"] || \"\";\n\n const url = new URL(viteDevId, location.href);\n return url.searchParams.get(\"vue\") !== null &&\n url.searchParams.get(\"type\") === \"style\" &&\n url.searchParams.has(\"scoped\")\n ? viteDevId\n : \"\";\n};\n\n// Check for a head element that should persist and returns it,\n// either because it has the data attribute or because replacing it would cause avoidable FOUC.\nconst persistedHeadElement = (el: HTMLElement, newDoc: Document): Element | null => {\n const id = el.getAttribute(PERSIST_ATTR);\n const newEl = id !== null ? querySelectorWithAttrValue(newDoc.head, \"\", PERSIST_ATTR, id) : null;\n if (newEl) {\n return newEl;\n }\n if (el.matches(\"link[rel=stylesheet]\")) {\n const href = el.getAttribute(\"href\");\n return href !== null\n ? querySelectorWithAttrValue(newDoc.head, \"link[rel=stylesheet]\", \"href\", href)\n : null;\n }\n // In dev mode, Vite injects <style data-vite-dev-id=\"...\"> elements whose\n // textContent may later be transformed (especially Vue's `:deep()` → `[data-v-xxx]`).\n // Match these by their stable dev ID so the already-transformed style is preserved\n // across ClientRouter soft navigations instead of being replaced by the raw version.\n // There are other ids that can't be preserved and need a refresh, like Uno's /__uno.css,\n // which keeps the same id, but with different contents.\n // To avoid enumerating all exceptions, we only apply the auto-persist logic to elements\n // that look like Vue's dev styles.\n if ((import.meta as any).env?.DEV && el instanceof HTMLStyleElement) {\n const viteDevId = vueScopedStyleId(el);\n if (viteDevId) {\n return querySelectorWithAttrValue(newDoc.head, \"style\", \"data-vite-dev-id\", viteDevId);\n }\n }\n // Preserve inline <style> elements with identical content across navigations.\n // This prevents unnecessary removal and re-insertion of styles (e.g. @font-face\n // declarations from <Font>), which would cause the browser to re-evaluate them\n // and trigger a flash of unstyled text (FOUT).\n if (el.tagName === \"STYLE\" && el.textContent) {\n const styles = newDoc.head.querySelectorAll(\"style\");\n for (const s of styles) {\n if (s.textContent === el.textContent) {\n return s;\n }\n }\n }\n // Preserve font preload links across navigations to avoid re-fetching cached fonts.\n if (el.matches(\"link[rel=preload][as=font]\")) {\n const href = el.getAttribute(\"href\");\n return href !== null\n ? querySelectorWithAttrValue(newDoc.head, \"link[rel=preload][as=font]\", \"href\", href)\n : null;\n }\n return null;\n};\n\nconst shouldCopyProps = (el: HTMLElement): boolean => {\n const persistProps = el.dataset[\"zfbTransitionPersistProps\"];\n return persistProps == null || persistProps === \"false\";\n};\n\nconst isSameProps = (oldEl: Element, newEl: Element) => {\n // zfb island wrapper writes SSR props to data-props, not props (different attribute, not just renamed).\n return oldEl.getAttribute(\"data-props\") === newEl.getAttribute(\"data-props\");\n};\n\nexport const swapFunctions = {\n deselectScripts,\n swapRootAttributes,\n swapHeadElements,\n swapBodyElement,\n saveFocus,\n};\n\nexport const swap = (doc: Document) => {\n assertUniquePersistKeys(document, \"current\");\n assertUniquePersistKeys(doc, \"incoming\");\n deselectScripts(doc);\n swapRootAttributes(doc);\n swapHeadElements(doc);\n const restoreFocusFunction = saveFocus();\n swapBodyElement(doc.body, document.body);\n restoreFocusFunction();\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-router-component.js","sourceRoot":"","sources":["../src/client-router-component.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,EAAE;AACF,wDAAwD;AACxD,uDAAuD;AACvD,yEAAyE;AACzE,EAAE;AACF,2DAA2D;AAC3D,2EAA2E;AAC3E,6EAA6E;AAC7E,2EAA2E;AAC3E,+EAA+E;AAC/E,yEAAyE;AACzE,EAAE;AACF,yEAAyE;AACzE,yEAAyE;AACzE,mEAAmE;AAEnE,OAAO,EAAE,GAAG,EAAE,MAAM,sCAAsC,CAAC;AAG3D,OAAO,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEnE,8EAA8E;AAC9E,kFAAkF;AAClF,IAAI,oBAAoB,GAAG,KAAK,CAAC;AAoDjC,+EAA+E;AAC/E,SAAS,SAAS,CAAC,IAAY,EAAE,KAA8B,EAAE,GAAW;IAC1E,yEAAyE;IACzE,OAAO,GAAG,CAAC,IAAiC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AAC5D,CAAC;AAED,oEAAoE;AACpE,0EAA0E;AAC1E,gEAAgE;AAChE,uEAAuE;AACvE,mEAAmE;AACnE,MAAM,YAAY,GAAG;;;;;;;;;;;;CAYpB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,QAAQ,GAAG,SAAS,EACpB,WAAW,EAAE,eAAe,GAAG,KAAK,EACpC,iBAAiB,GAAG,EAAE,EACtB,eAAe,GAAG,KAAK,MACF,EAAE;IACvB,0EAA0E;IAC1E,4EAA4E;IAC5E,4DAA4D;IAC5D,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,eAAe,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAChF,oBAAoB,GAAG,IAAI,CAAC;QAC5B,YAAY,CAAC,EAAE,WAAW,EAAE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AA4E;IAC5E,sEAAsE;IACtE,4EAA4E;IAC5E,6EAA6E;IAC7E,IAAI,eAAe,EAAE,CAAC;QACpB,KAAK,CAAC,IAAI,CACR,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,sBAAsB,CAAC,CAC7F,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// `@takazudo/zfb-runtime` — `<ClientRouter />` component (pure module).\n//\n// Ported from Astro's `ClientRouter.astro` (155 lines).\n// Source: packages/astro/components/ClientRouter.astro\n// Issue: zudolab/zudo-doc#1519 (W3D), parent epic zudolab/zudo-doc#1510.\n//\n// Named-cause deviation — inline script split (W1B §13.6):\n// Astro's <script> block is processed by Vite at build time as a bundled\n// module with virtual-module imports (`astro:transitions/client`). The zfb\n// port emits meta tags + global styles from the JSX component, while the\n// click/form intercepts live in `client-router/router.ts` and are registered\n// via `init()`. No inline <script> dangerouslySetInnerHTML is emitted.\n//\n// Component/activation split (#2437): this pure module imports the owned\n// JSX factory and prefetch helpers without activating the client router.\n// The router activation shim remains at the client-router subpath.\n\nimport { jsx } from \"@takazudo/zfb/zudo-react/jsx-runtime\";\nimport type { Description } from \"@takazudo/zfb/zudo-react\";\n\nimport { init as prefetchInit } from \"./client-router/prefetch.js\";\n\n// Module-level guard: prefetch bootstrap is triggered at most once per module\n// lifetime even if <ClientRouter prefetchAll /> is mounted multiple times (#276).\nlet prefetchBootstrapped = false;\n\nexport interface ClientRouterProps {\n /** Fallback animation strategy when native View Transitions are not supported. */\n fallback?: \"none\" | \"animate\" | \"swap\";\n /**\n * When true, opts every same-origin link into the default prefetch strategy\n * (hover) by calling prefetchInit({ prefetchAll: true }) once on the client.\n */\n prefetchAll?: boolean;\n /**\n * Extra `<html>` attribute names to preserve across SPA swaps. By default the\n * client router copies the incoming server-rendered document's `<html>`\n * attributes onto the live root, dropping any current attribute that isn't\n * internal to the transition machinery — so a *runtime* attribute a consumer\n * sets from a persisted island (e.g. `data-theme` or `data-sidebar-hidden`\n * driven from `localStorage`) is lost on every navigation. List those names\n * here and the router re-applies their current value after each swap. Emitted\n * as a `<meta name=\"zfb-preserve-html-attrs\">` tag that `swapRootAttributes`\n * reads at swap time.\n *\n * Mount with the **same list on every page** that participates in SPA\n * navigation: the preserve-list is read from the *current* (outgoing) page's\n * meta at swap time, so a page that omits an entry drops that attribute when\n * navigating away from it. Names are matched case-insensitively (DOM attribute\n * names are lowercased). For dynamic/computed cases, mutate\n * `event.newDocument.documentElement` in a `zfb:before-swap` listener instead.\n * @see https://github.com/Takazudo/zudo-front-builder/issues/1103\n */\n preserveHtmlAttrs?: string[];\n /**\n * Opt this page OUT of the same-page traverse fast-path (default `false` —\n * fast-path ON). By default a Back/Forward traversal between two history\n * entries sharing the same `pathname + search` is served instantly from the\n * live DOM — no re-fetch, no re-swap, so island/client state is preserved.\n *\n * Set this on a **per-request SSR page** (`prerender = false`) whose\n * server-rendered content can legitimately differ between two visits to the\n * same URL: with the fast-path skipped such a traverse would pin the stale\n * first-render content. Emitted as\n * `<meta name=\"zfb-traverse-refetch\" content=\"true\">`, which the router reads\n * on the current (target) page to force the fetch back on. Mount with the\n * **same value on every page** that participates in SPA navigation, mirroring\n * the `preserveHtmlAttrs` guidance.\n * @see https://github.com/Takazudo/zudo-front-builder/issues/1376\n */\n traverseRefetch?: boolean;\n}\n\n/** Head descriptions returned by ClientRouter. */\nexport type ClientRouterElement = Description;\n\n/** Mint a keyed owned head description without JSX syntax in this .ts file. */\nfunction makeVNode(type: string, props: Record<string, unknown>, key: string): ClientRouterElement {\n // The static tag choices below are passed through this string parameter.\n return jsx(type as Parameters<typeof jsx>[0], props, key);\n}\n\n// CSS for the route-announcer element. Ported verbatim from Astro's\n// `<style is:global>` block in ClientRouter.astro (lines 11–23), renaming\n// `.astro-route-announcer` → `.zfb-route-announcer` per W1B §5.\n// This is a global (non-scoped) <style> because the announcer <div> is\n// appended to document.body at runtime, outside the rendered head.\nconst announcerCss = `\n.zfb-route-announcer {\n\tposition: absolute;\n\tleft: 0;\n\ttop: 0;\n\tclip: rect(0 0 0 0);\n\tclip-path: inset(50%);\n\toverflow: hidden;\n\twhite-space: nowrap;\n\twidth: 1px;\n\theight: 1px;\n}\n`;\n\n/**\n * `<ClientRouter />` — SPA soft-swap navigation with View Transition animations.\n *\n * Mount once in your page `<head>`. Emits the opt-in meta tags and the global\n * `.zfb-route-announcer` stylesheet that the route-announcer ARIA div needs.\n * Importing this module performs no side effects — click/form-submit\n * intercepts are wired only when `./client-router.js` (the activation shim,\n * imported directly or via the `@takazudo/zfb-runtime/client-router` subpath)\n * is evaluated.\n *\n * @example\n * ```tsx\n * import { ClientRouter } from \"@takazudo/zfb-runtime\";\n * // In your page <head>:\n * <ClientRouter fallback=\"animate\" />\n * ```\n */\nexport function ClientRouter({\n fallback = \"animate\",\n prefetchAll: prefetchAllProp = false,\n preserveHtmlAttrs = [],\n traverseRefetch = false,\n}: ClientRouterProps = {}): readonly ClientRouterElement[] {\n // Bootstrap prefetch exactly once on the client when prefetchAll is true.\n // The initialized flag inside prefetchInit() provides a second safety layer\n // in case of concurrent hydration or manual callers (#276).\n if (typeof document !== \"undefined\" && prefetchAllProp && !prefetchBootstrapped) {\n prefetchBootstrapped = true;\n prefetchInit({ prefetchAll: true });\n }\n\n const nodes: ClientRouterElement[] = [\n // Global styles for the ARIA route-announcer div injected into <body>.\n makeVNode(\"style\", { rawHtml: announcerCss }, \"zfb-vt-style\"),\n // Opt-in meta tag: router checks for this to decide whether to intercept navigations.\n makeVNode(\"meta\", { name: \"zfb-view-transitions-enabled\", content: \"true\" }, \"zfb-vt-enabled\"),\n // Fallback strategy meta tag: read by getFallback() in router.ts.\n makeVNode(\n \"meta\",\n { name: \"zfb-view-transitions-fallback\", content: fallback },\n \"zfb-vt-fallback\",\n ),\n ];\n\n // Prefetch-disabled meta tag (#277): emitted when the bundler set\n // `globalThis.__zfb.prefetchDisabled = true` (from `zfb.config.ts`\n // `prefetch: { disabled: true }`). The sibling prefetch-core module reads\n // `document.querySelector('meta[name=\"zfb-prefetch-disabled\"][content=\"true\"]')`\n // at `init()` time and short-circuits if found.\n //\n // The flag is site-wide and static — set once at bundle-emit time, never\n // per-page. This meta tag appears on every page that mounts `<ClientRouter />`\n // or not at all.\n //\n // Pin the contract verbatim — the attribute names and content value are\n // shared with the sibling prefetch-core sub-issue (#276).\n if ((globalThis as { __zfb?: { prefetchDisabled?: boolean } }).__zfb?.prefetchDisabled === true) {\n nodes.push(\n makeVNode(\n \"meta\",\n { name: \"zfb-prefetch-disabled\", content: \"true\" },\n \"zfb-prefetch-disabled\",\n ),\n );\n }\n\n // Consumer-extensible <html> attribute preserve-list (#1103). swapRootAttributes\n // reads this meta and re-applies the listed attributes' runtime values after each\n // swap, so persisted-island state on <html> (data-theme, data-sidebar-hidden, …)\n // survives navigation. Emitted only when non-empty, so non-opt-in output stays\n // byte-identical. Same conditional-emission shape as the prefetch-disabled meta.\n const preserveList = preserveHtmlAttrs.filter(Boolean);\n if (preserveList.length > 0) {\n nodes.push(\n makeVNode(\n \"meta\",\n { name: \"zfb-preserve-html-attrs\", content: preserveList.join(\" \") },\n \"zfb-preserve-html-attrs\",\n ),\n );\n }\n\n // Traverse-refetch opt-out meta (#1376). A same-page Back/Forward traversal\n // skips the re-fetch/re-swap by default (the router's traverse fast-path);\n // this meta opts a per-request SSR page (`prerender = false`) back INTO the\n // fetch, since skipping it would pin stale server-rendered content. Emitted\n // only when opted in, so non-opt-in output stays byte-identical. Same\n // conditional-emission shape as the prefetch-disabled / preserve-html-attrs\n // metas; the router reads meta[name=\"zfb-traverse-refetch\"][content=\"true\"].\n if (traverseRefetch) {\n nodes.push(\n makeVNode(\"meta\", { name: \"zfb-traverse-refetch\", content: \"true\" }, \"zfb-traverse-refetch\"),\n );\n }\n\n return nodes;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"client-router-component.js","sourceRoot":"","sources":["../src/client-router-component.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AC,MAAM,EAAE,EAAE,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,sBAAsB,CAAC,CAC7F,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// `@takazudo/zfb-runtime` — `<ClientRouter />` component (pure module).\n//\n// Ported from Astro's `ClientRouter.astro` (155 lines).\n// Source: packages/astro/components/ClientRouter.astro\n// Issue: zudolab/zudo-doc#1519 (W3D), parent epic zudolab/zudo-doc#1510.\n//\n// Named-cause deviation — inline script split (W1B §13.6):\n// Astro's <script> block is processed by Vite at build time as a bundled\n// module with virtual-module imports (`astro:transitions/client`). The zfb\n// port emits meta tags + global styles from the JSX component, while the\n// click/form intercepts live in `client-router/router.ts` and are registered\n// via `init()`. No inline <script> dangerouslySetInnerHTML is emitted.\n//\n// Component/activation split (#2437): this pure module imports the owned\n// JSX factory and prefetch helpers without activating the client router.\n// The router activation shim remains at the client-router subpath.\n\nimport { jsx } from \"@takazudo/zfb/zudo-react/jsx-runtime\";\nimport type { Description } from \"@takazudo/zfb/zudo-react\";\n\nimport { init as prefetchInit } from \"./client-router/prefetch.js\";\n\n// Module-level guard: prefetch bootstrap is triggered at most once per module\n// lifetime even if <ClientRouter prefetchAll /> is mounted multiple times (#276).\nlet prefetchBootstrapped = false;\n\nexport interface ClientRouterProps {\n /** Fallback animation strategy when native View Transitions are not supported. */\n fallback?: \"none\" | \"animate\" | \"swap\";\n /**\n * When true, opts every same-origin link into the default prefetch strategy\n * (hover) by calling prefetchInit({ prefetchAll: true }) once on the client.\n */\n prefetchAll?: boolean;\n /**\n * Extra `<html>` attribute names to preserve across SPA swaps. By default the\n * client router copies the incoming server-rendered document's `<html>`\n * attributes onto the live root, dropping any current attribute that isn't\n * internal to the transition machinery — so a *runtime* attribute a consumer\n * sets from a persisted island (e.g. `data-theme` or `data-sidebar-hidden`\n * driven from `localStorage`) is lost on every navigation. List those names\n * here and the router re-applies their current value after each swap. Emitted\n * as a `<meta name=\"zfb-preserve-html-attrs\">` tag that `swapRootAttributes`\n * reads at swap time.\n *\n * Mount with the **same list on every page** that participates in SPA\n * navigation: the preserve-list is read from the *current* (outgoing) page's\n * meta at swap time, so a page that omits an entry drops that attribute when\n * navigating away from it. Names are matched case-insensitively (DOM attribute\n * names are lowercased). For dynamic/computed cases, mutate\n * `event.newDocument.documentElement` in a `zfb:before-swap` listener instead.\n * @see https://github.com/Takazudo/zudo-front-builder/issues/1103\n */\n preserveHtmlAttrs?: string[];\n /**\n * Opt this page OUT of the same-page traverse fast-path (default `false` —\n * fast-path ON). By default a Back/Forward traversal between two history\n * entries sharing the same `pathname + search` is served instantly from the\n * live DOM — no re-fetch, no re-swap, so island/client state is preserved.\n *\n * Set this on a **per-request SSR page** (`prerender = false`) whose\n * server-rendered content can legitimately differ between two visits to the\n * same URL: with the fast-path skipped such a traverse would pin the stale\n * first-render content. Emitted as\n * `<meta name=\"zfb-traverse-refetch\" content=\"true\">`, which the router reads\n * on the current (target) page to force the fetch back on. Mount with the\n * **same value on every page** that participates in SPA navigation, mirroring\n * the `preserveHtmlAttrs` guidance.\n * @see https://github.com/Takazudo/zudo-front-builder/issues/1376\n */\n traverseRefetch?: boolean;\n}\n\n/** Head descriptions returned by ClientRouter. */\nexport type ClientRouterElement = Description;\n\n/** Mint a keyed owned head description without JSX syntax in this .ts file. */\nfunction makeVNode(type: string, props: Record<string, unknown>, key: string): ClientRouterElement {\n // The static tag choices below are passed through this string parameter.\n return jsx(type as Parameters<typeof jsx>[0], props, key);\n}\n\n// CSS for the route-announcer element. Ported verbatim from Astro's\n// `<style is:global>` block in ClientRouter.astro (lines 11–23), renaming\n// `.astro-route-announcer` → `.zfb-route-announcer` per W1B §5.\n// This is a global (non-scoped) <style> because the announcer <div> is\n// appended to document.body at runtime, outside the rendered head.\nconst announcerCss = `\n.zfb-route-announcer {\n\tposition: absolute;\n\tleft: 0;\n\ttop: 0;\n\tclip: rect(0 0 0 0);\n\tclip-path: inset(50%);\n\toverflow: hidden;\n\twhite-space: nowrap;\n\twidth: 1px;\n\theight: 1px;\n}\n`;\n\n/**\n * `<ClientRouter />` — SPA soft-swap navigation with View Transition animations.\n *\n * Mount once in your page `<head>`. Emits the opt-in meta tags and the global\n * `.zfb-route-announcer` stylesheet that the route-announcer ARIA div needs.\n * Importing this module performs no side effects — click/form-submit\n * intercepts are wired only when `./client-router.js` (the activation shim,\n * imported directly or via the `@takazudo/zfb-runtime/client-router` subpath)\n * is evaluated.\n *\n * @example\n * ```tsx\n * import { ClientRouter } from \"@takazudo/zfb-runtime\";\n * // In your page <head>:\n * <ClientRouter fallback=\"animate\" />\n * ```\n */\nexport function ClientRouter({\n fallback = \"animate\",\n prefetchAll: prefetchAllProp = false,\n preserveHtmlAttrs = [],\n traverseRefetch = false,\n}: ClientRouterProps = {}): readonly ClientRouterElement[] {\n // Bootstrap prefetch exactly once on the client when prefetchAll is true.\n // The initialized flag inside prefetchInit() provides a second safety layer\n // in case of concurrent hydration or manual callers (#276).\n if (typeof document !== \"undefined\" && prefetchAllProp && !prefetchBootstrapped) {\n prefetchBootstrapped = true;\n prefetchInit({ prefetchAll: true });\n }\n\n const nodes: ClientRouterElement[] = [\n // Global styles for the ARIA route-announcer div injected into <body>.\n makeVNode(\"style\", { rawHtml: announcerCss }, \"zfb-vt-style\"),\n // Opt-in meta tag: router checks for this to decide whether to intercept navigations.\n makeVNode(\"meta\", { name: \"zfb-view-transitions-enabled\", content: \"true\" }, \"zfb-vt-enabled\"),\n // Fallback strategy meta tag: read by getFallback() in router.ts.\n makeVNode(\n \"meta\",\n { name: \"zfb-view-transitions-fallback\", content: fallback },\n \"zfb-vt-fallback\",\n ),\n ];\n\n // Prefetch-disabled meta tag (#277): emitted when the bundler set\n // `globalThis.__zfb.prefetchDisabled = true` (from `zfb.config.ts`\n // `prefetch: { disabled: true }`). The sibling prefetch-core module reads\n // `document.querySelector('meta[name=\"zfb-prefetch-disabled\"][content=\"true\"]')`\n // at `init()` time and short-circuits if found.\n //\n // The flag is site-wide and static — set once at bundle-emit time, never\n // per-page. This meta tag appears on every page that mounts `<ClientRouter />`\n // or not at all.\n //\n // Pin the contract verbatim — the attribute names and content value are\n // shared with the sibling prefetch-core sub-issue (#276).\n if ((globalThis as { __zfb?: { prefetchDisabled?: boolean } }).__zfb?.prefetchDisabled === true) {\n nodes.push(\n makeVNode(\n \"meta\",\n { name: \"zfb-prefetch-disabled\", content: \"true\" },\n \"zfb-prefetch-disabled\",\n ),\n );\n }\n\n // Consumer-extensible <html> attribute preserve-list (#1103). swapRootAttributes\n // reads this meta and re-applies the listed attributes' runtime values after each\n // swap, so persisted-island state on <html> (data-theme, data-sidebar-hidden, …)\n // survives navigation. Emitted only when non-empty, so non-opt-in output stays\n // byte-identical. Same conditional-emission shape as the prefetch-disabled meta.\n const preserveList = preserveHtmlAttrs.filter(Boolean);\n if (preserveList.length > 0) {\n nodes.push(\n makeVNode(\n \"meta\",\n { name: \"zfb-preserve-html-attrs\", content: preserveList.join(\" \") },\n \"zfb-preserve-html-attrs\",\n ),\n );\n }\n\n // Traverse-refetch opt-out meta (#1376). A same-page Back/Forward traversal\n // skips the re-fetch/re-swap by default (the router's traverse fast-path);\n // this meta opts a per-request SSR page (`prerender = false`) back INTO the\n // fetch, since skipping it would pin stale server-rendered content. Emitted\n // only when opted in, so non-opt-in output stays byte-identical. Same\n // conditional-emission shape as the prefetch-disabled / preserve-html-attrs\n // metas; the router reads meta[name=\"zfb-traverse-refetch\"][content=\"true\"].\n if (traverseRefetch) {\n nodes.push(\n makeVNode(\"meta\", { name: \"zfb-traverse-refetch\", content: \"true\" }, \"zfb-traverse-refetch\"),\n );\n }\n\n return nodes;\n}\n"]}
|
package/dist/router.js
CHANGED
|
@@ -372,6 +372,12 @@ export function createPageRouter(opts) {
|
|
|
372
372
|
// or by renderToString surfaces as a descriptive 500 rather than
|
|
373
373
|
// escaping to Hono's generic error handler (which discards the real
|
|
374
374
|
// message). Mirrors the getStaticProps catch above.
|
|
375
|
+
const renderPage = async () => {
|
|
376
|
+
const result = await mod.default(componentInput);
|
|
377
|
+
if (result instanceof Response || typeof result === "string")
|
|
378
|
+
return result;
|
|
379
|
+
return renderToString(result);
|
|
380
|
+
};
|
|
375
381
|
try {
|
|
376
382
|
const result = await mod.default(componentInput);
|
|
377
383
|
// API route short-circuit: a page module that returns a Response
|
|
@@ -401,9 +407,11 @@ export function createPageRouter(opts) {
|
|
|
401
407
|
const includeStack = opts.includeErrorStack ??
|
|
402
408
|
globalThis.__zfb?.ssrDebug === true;
|
|
403
409
|
const stack = includeStack && err instanceof Error && err.stack ? `\n${err.stack}` : "";
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
410
|
+
const diagnostic = includeStack ? await locateRenderFailure(err, renderPage) : undefined;
|
|
411
|
+
const structured = diagnostic
|
|
412
|
+
? `\n${RENDER_DIAGNOSTIC_PREFIX}${JSON.stringify(diagnostic)}`
|
|
413
|
+
: "";
|
|
414
|
+
return c.body(`[zfb-runtime] render threw for "${page.route}": ${msg}${stack}${structured}`, 500, { "Content-Type": "text/plain; charset=utf-8" });
|
|
407
415
|
}
|
|
408
416
|
});
|
|
409
417
|
}
|
|
@@ -414,6 +422,72 @@ export function createPageRouter(opts) {
|
|
|
414
422
|
// promise instead of escaping the caller's `await`.
|
|
415
423
|
return async (request) => await app.fetch(request);
|
|
416
424
|
}
|
|
425
|
+
// zfb-build's renderer reads this line back out of the 500 body (renderer.rs).
|
|
426
|
+
const RENDER_DIAGNOSTIC_PREFIX = "[zfb-render-diagnostic] ";
|
|
427
|
+
// Shared with zudo-react's description.ts, which records jsx() call sites while it is set.
|
|
428
|
+
const SITE_CAPTURE = Symbol.for("@takazudo/zfb/zudo-react/site-capture-v1");
|
|
429
|
+
function renderDiagnostic(err) {
|
|
430
|
+
if (!(err instanceof Error) || !("diagnostic" in err))
|
|
431
|
+
return undefined;
|
|
432
|
+
const value = err.diagnostic;
|
|
433
|
+
if (typeof value !== "object" ||
|
|
434
|
+
value === null ||
|
|
435
|
+
typeof value.code !== "string" ||
|
|
436
|
+
typeof value.path !== "string" ||
|
|
437
|
+
typeof value.component !== "string")
|
|
438
|
+
return undefined;
|
|
439
|
+
const { code, path, component, spelling, site } = value;
|
|
440
|
+
return {
|
|
441
|
+
code,
|
|
442
|
+
path,
|
|
443
|
+
component,
|
|
444
|
+
...(spelling &&
|
|
445
|
+
typeof spelling.name === "string" && {
|
|
446
|
+
spelling: {
|
|
447
|
+
name: spelling.name,
|
|
448
|
+
...(typeof spelling.suggestion === "string" && { suggestion: spelling.suggestion }),
|
|
449
|
+
},
|
|
450
|
+
}),
|
|
451
|
+
...(site && { site: pickSite(site) }),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
function pickSite(site) {
|
|
455
|
+
const picked = {};
|
|
456
|
+
for (const key of ["kind", "file", "specifier", "line", "column"])
|
|
457
|
+
if (typeof site[key] === "string" || typeof site[key] === "number")
|
|
458
|
+
picked[key] = site[key];
|
|
459
|
+
return picked;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Production descriptions carry no call sites. When a render diagnostic has
|
|
463
|
+
* none, render the page once more with call-site capture enabled so the
|
|
464
|
+
* failing element's generated position can be source-mapped by the build host.
|
|
465
|
+
* The replay is accepted only when it fails with the identical message.
|
|
466
|
+
*/
|
|
467
|
+
async function locateRenderFailure(err, render) {
|
|
468
|
+
const first = renderDiagnostic(err);
|
|
469
|
+
if (!first || first.site)
|
|
470
|
+
return first;
|
|
471
|
+
const flags = globalThis;
|
|
472
|
+
// A count, not a flag: overlapping dev replays must not switch capture off for each other.
|
|
473
|
+
flags[SITE_CAPTURE] = (flags[SITE_CAPTURE] ?? 0) + 1;
|
|
474
|
+
try {
|
|
475
|
+
await render();
|
|
476
|
+
}
|
|
477
|
+
catch (again) {
|
|
478
|
+
const located = renderDiagnostic(again);
|
|
479
|
+
if (located?.site && again instanceof Error && err.message === again.message)
|
|
480
|
+
return located;
|
|
481
|
+
}
|
|
482
|
+
finally {
|
|
483
|
+
const remaining = flags[SITE_CAPTURE] - 1;
|
|
484
|
+
if (remaining > 0)
|
|
485
|
+
flags[SITE_CAPTURE] = remaining;
|
|
486
|
+
else
|
|
487
|
+
delete flags[SITE_CAPTURE];
|
|
488
|
+
}
|
|
489
|
+
return first;
|
|
490
|
+
}
|
|
417
491
|
/**
|
|
418
492
|
* Type guard for one `paths()` entry. Mirrors the strictness of the
|
|
419
493
|
* Rust pipeline's `paths()` resolver — every entry must be a non-null
|
package/dist/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,EAAE;AACF,wEAAwE;AACxE,mCAAmC;AACnC,EAAE;AACF,oDAAoD;AACpD,0DAA0D;AAC1D,8EAA8E;AAC9E,qDAAqD;AACrD,uCAAuC;AACvC,EAAE;AACF,qEAAqE;AACrE,0EAA0E;AAC1E,uEAAuE;AACvE,uEAAuE;AACvE,4DAA4D;AAC5D,EAAE;AACF,qEAAqE;AACrE,kEAAkE;AAClE,oEAAoE;AACpE,+DAA+D;AAC/D,EAAE;AACF,oCAAoC;AACpC,EAAE;AACF,0EAA0E;AAC1E,qFAAqF;AACrF,qEAAqE;AACrE,+BAA+B;AAC/B,EAAE;AACF,+CAA+C;AAC/C,EAAE;AACF,4EAA4E;AAC5E,yEAAyE;AACzE,0EAA0E;AAC1E,2EAA2E;AAC3E,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,4DAA4D;AAE5D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAwGjE,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AA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AI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,IAAI,GAAG,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC9D,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,yBAAyB,CAAC,KAAa;IAC9C,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtD,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAK,WAAW,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAChG,CAAC","sourcesContent":["// `@takazudo/zfb-runtime` — Hono-based page router.\n//\n// `createPageRouter` is the JS-side entry point for ADR-007's SSG-first\n// architecture. The pipeline goes:\n//\n// user pages/ + content/ + layouts/ + components/\n// → esbuild bundle (T3) // single ESM file\n// → embedded V8 host (T6) // same WinterCG surface as CF Workers\n// → createPageRouter({ pages, contentSnapshot })\n// → (request) => Promise<Response>\n//\n// The bundle's Worker entry point shape is documented in the package\n// README. The contract is intentionally minimal: one factory call returns\n// one fetch handler. Hono is an implementation detail — callers should\n// not depend on the Hono types leaking through. The exposed surface is\n// the four types here plus the `createPageRouter` function.\n//\n// Side effect on init: registers the supplied `ContentSnapshot` with\n// `zfb/content`'s module-level snapshot bridge so any page module\n// importing `getCollection(\"...\")` resolves from memory rather than\n// touching the Node `fs` API (the Worker runtime has no `fs`).\n//\n// ## Synthetic `__paths__` endpoint\n//\n// The Rust build pipeline needs to evaluate non-literal `paths()` exports\n// (e.g. those that `await import(\"@takazudo/zfb/content\")` and call `getCollection`)\n// at runtime against the running embedded host. The router exposes a\n// synthetic internal endpoint:\n//\n// GET /__paths__/<percent-encoded-route-key>\n//\n// When a page registered at `route` has a `paths` export, the handler calls\n// it and returns the JSON-serialized array as `application/json`. If the\n// `paths` export is missing or throws, the response is a descriptive 500.\n// This endpoint is only meant for the build pipeline — it is safe to leave\n// registered in production. During build/check/dev route scans, `zfb-router`\n// rejects `pages/__paths__/<...>` with `RouterError::ReservedRoutePrefix`.\n// The warning below remains as belt-and-braces for `createPageRouter` callers\n// that hand-build `pages` and therefore bypass the scanner.\n\nimport { Hono } from \"hono\";\nimport { setContentSnapshot } from \"@takazudo/zfb/content\";\n\nimport { renderToString } from \"@takazudo/zfb/zudo-react/server\";\nimport type { ContentSnapshot } from \"./snapshot.js\";\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\n/**\n * Heading metadata emitted by the MDX `headings` export (T4). Cross-ref:\n * `crates/zfb-content/src/mdx_jsx_emit.rs`. Optional on the page-module\n * shape — non-MDX pages won't carry it.\n */\nexport interface PageHeading {\n readonly depth: number;\n readonly slug: string;\n readonly text: string;\n}\n\n/**\n * The shape every page module must export.\n *\n * - `default`: the JSX page component. Called with the props returned by\n * `getStaticProps` (if exported) or the `props` from the matching\n * `paths()` entry (for dynamic routes). The return value is fed straight\n * to the owned server renderer's `renderToString`. A dynamic route with no\n * `paths()` export is called with `{ params: urlParams }` instead of\n * `{}` — see `createPageRouter`'s JSDoc for the full componentInput\n * derivation table.\n * - `prerender`: literal `false` opts a route OUT of build-time SSG (T5\n * contract). The page router still serves it under the embedded V8 host\n * so dev mode behaves identically; SSG callers filter the route list before\n * driving the renderer.\n * - `contentType`: optional override for non-HTML routes (e.g.\n * `application/xml` for `rss.xml.tsx`). Default is\n * `text/html; charset=utf-8`. Cross-ref shipped #49.\n * - `headings`: optional list emitted by MDX (T4).\n * - `paths`: optional dynamic-route enumerator. Called at build time by\n * the `__paths__` synthetic endpoint to produce the concrete URL list\n * for this route template. May be async. Returns an array of\n * `{ params, props? }` objects identical in shape to the Astro/zfb\n * `paths()` contract.\n * **Evaluated once per router instance** — the result is memoised and\n * shared across the `/__paths__` handler and all per-page render\n * requests. This matches the build-time-enumerator contract: every\n * entry rendered within a single build sees the same paths() snapshot.\n * Dev mode is safe because each file-save triggers a fresh bundle,\n * which creates a new router instance with a clean memo.\n * - `getStaticProps`: optional async function for static routes that need\n * to fetch data at build/render time. Called once per request (before\n * `default`). Must return `{ props: Record<string, unknown> }`. The\n * returned `props` are spread into the `default` component's props.\n */\nexport interface PageModule {\n readonly default: (props: Record<string, unknown>) => unknown;\n readonly prerender?: boolean;\n readonly contentType?: string;\n readonly headings?: readonly PageHeading[];\n readonly paths?: () => unknown[] | Promise<unknown[]>;\n readonly getStaticProps?: () => Promise<{ props: Record<string, unknown> }>;\n}\n\n/**\n * One page registered with the router.\n *\n * `route` is a Hono path pattern (e.g. `/`, `/blog/:slug`,\n * `/blog/page/:page`). `module` is a thunk so the bundle can use code\n * splitting if it wants to — today the bundler emits everything as one\n * ESM file and the thunk simply returns the already-loaded module.\n */\nexport interface PageDefinition {\n readonly route: string;\n readonly module: () => Promise<PageModule>;\n}\n\n/** Options accepted by [`createPageRouter`]. */\nexport interface CreatePageRouterOptions {\n /** Pages to register. Order does not affect routing — Hono dispatches by path. */\n readonly pages: readonly PageDefinition[];\n /**\n * In-memory content snapshot. Embedded into the bundle by T3; the\n * router hands it to `zfb/content` so user pages reading content via\n * `getCollection(...)` resolve synchronously from memory.\n */\n readonly contentSnapshot: ContentSnapshot;\n /**\n * When `true`, the 500 body for render errors includes the full JS stack\n * trace. When `false`, only the message + route are included. When\n * omitted, the runtime checks `globalThis.__zfb.ssrDebug` at request time:\n * that flag is set by the embedded V8 build/dev host (`globals_shim.js`)\n * and is absent on the production Cloudflare Workers runtime.\n *\n * Default is effectively OFF for production (no flag ⇒ message + route only).\n * Useful for explicit injection in unit tests without global mutation.\n */\n readonly includeErrorStack?: boolean;\n}\n\n/**\n * Fetch-handler shape returned by [`createPageRouter`]. Shaped as a plain\n * function (not a Hono `app`) so the consumer's contract is exactly\n * \"Worker-style fetch handler\" with no leaked renderer types.\n */\nexport type PageRouter = (request: Request) => Promise<Response>;\n\n// ---------------------------------------------------------------------------\n// Implementation\n// ---------------------------------------------------------------------------\n\n/**\n * Default content-type when a page module does not override.\n *\n * Aligned with #49's per-page `contentType` convention: the default\n * served for HTML pages is `text/html; charset=utf-8`. Tests pin this\n * verbatim because the embedded V8 host does NOT auto-set a charset.\n */\nconst DEFAULT_CONTENT_TYPE = \"text/html; charset=utf-8\";\n\n/**\n * Issue #530: prepend `<!doctype html>\\n` to SSR-rendered HTML bodies that\n * lack a doctype declaration, mirroring the guard in\n * `crates/zfb-build/src/renderer.rs::render_one_inner` (issue #524).\n *\n * Gate conditions (all must hold to prepend):\n * 1. `contentType` media-type (before `;`) is `text/html` (case-insensitive).\n * 2. The body, after stripping an optional UTF-8 BOM (U+FEFF) and leading\n * ASCII whitespace, starts with `<html` (case-insensitive) — i.e. it is\n * an `<html>`-rooted document, not XML / JSON / a fragment.\n * 3. The body (same stripped prefix) does NOT already begin with `<!doctype`\n * (case-insensitive).\n *\n * Deliberately NOT shared with the Rust side — duplication of a 5-line guard\n * is the right call rather than introducing a new cross-language boundary.\n */\nfunction ensureHtml5Doctype(body: string, contentType: string): string {\n const mediaType = contentType.split(\";\")[0]?.trim().toLowerCase();\n if (mediaType !== \"text/html\") return body;\n // Strip optional BOM and leading whitespace to inspect the root element.\n const stripped = body.replace(/^/, \"\").trimStart();\n if (!stripped.toLowerCase().startsWith(\"<!doctype\")) {\n if (stripped.toLowerCase().startsWith(\"<html\")) {\n return `<!doctype html>\\n${body}`;\n }\n }\n return body;\n}\n\n/**\n * Evaluate `pathsFn` once per `routeKey`, sharing the result across all\n * concurrent and subsequent callers via a Promise stored in `memo`.\n *\n * Rejections are evicted from the memo so that a transient paths() failure\n * does not permanently poison the cache — the next request retries.\n */\nasync function getOrEvalPaths(\n memo: Map<string, Promise<unknown[]>>,\n routeKey: string,\n pathsFn: () => unknown[] | Promise<unknown[]>,\n): Promise<unknown[]> {\n const existing = memo.get(routeKey);\n if (existing !== undefined) {\n return existing;\n }\n const promise = Promise.resolve(pathsFn()).then(\n (v) => v as unknown[],\n (err) => {\n // Evict on rejection so the next request retries.\n memo.delete(routeKey);\n return Promise.reject(err) as Promise<unknown[]>;\n },\n );\n memo.set(routeKey, promise);\n return promise;\n}\n\n/**\n * Build a page router for the SSG-first architecture (ADR-005).\n *\n * Side effects:\n * 1. Registers `opts.contentSnapshot` with the `zfb/content` module so\n * `getCollection(name)` resolves from memory. Idempotent across\n * calls — the latest snapshot wins (matches the documented dev-mode\n * live-reload contract).\n * 2. Constructs an internal Hono app and registers an **all-methods**\n * handler (`app.all`, not `app.get`) per `pages[i].route`, so an SSR\n * route that dispatches on `request.method` — e.g. a POST endpoint\n * under `pages/api/` — actually reaches its handler instead of being\n * 404'd by the inner router. See the comment at the `app.all` call\n * site below. The handler imports the page module, calls\n * `renderToString(module.default(componentInput))`, and\n * returns the string in a `Response` with the appropriate\n * `Content-Type`. (`componentInput` is the page's props object — see\n * the derivation table below; it is never the incoming `Request`.)\n *\n * Per-route `componentInput` (the object passed to `module.default(...)`) is\n * derived from the route pattern and the page module's exports:\n * - Dynamic route + `paths()` export: match the URL params against the\n * `paths()` entries and pass `{ params, ...props }` (404 on no match).\n * - Static route + `getStaticProps()` export: pass the returned `props`.\n * - Dynamic route with NO `paths()` export (e.g. a per-request SSR page\n * whose slugs can't be enumerated ahead of time): pass `{ params:\n * urlParams }` so the component still knows which URL params it is\n * serving, rather than being invoked with `{}`.\n * - Anything else (static route, no `getStaticProps`): pass `{}`.\n *\n * The returned function is a plain `(request) => Promise<Response>` so a\n * Worker entry point can `export default { fetch: createPageRouter(...) }`\n * directly.\n */\nexport function createPageRouter(opts: CreatePageRouterOptions): PageRouter {\n setContentSnapshot(opts.contentSnapshot);\n\n const app = new Hono();\n\n // Build a lookup map: Hono route pattern → PageDefinition, for the\n // `__paths__` synthetic endpoint below. The map is keyed on the `route`\n // string exactly as the caller supplied it (e.g. \"/blog/:slug\").\n const pagesByRoute = new Map<string, PageDefinition>();\n for (const page of opts.pages) {\n pagesByRoute.set(page.route, page);\n }\n\n // Per-router-instance memo for paths() results.\n //\n // Keyed on page.route (e.g. \"/blog/:slug\"). Stores the in-flight or\n // settled Promise so that concurrent requests share one evaluation.\n // Rejections are NOT cached: if paths() throws the Promise is removed\n // from the map so the next request retries rather than re-propagating\n // the same error indefinitely.\n //\n // Production SSR isolates evaluate paths() once per isolate, which\n // matches the documented build-time-enumerator contract. Dev mode is\n // safe because each re-bundle creates a fresh router instance\n // (dev.rs reload_renderer), so stale paths() results never persist\n // across a file-save cycle. Watch-time invalidation is explicitly\n // out of scope per issue #507.\n const pathsMemo = new Map<string, Promise<unknown[]>>();\n\n // Sanity check: a user-authored route under `/__paths__/...` has its\n // GET/HEAD responses hidden by the synthetic endpoint registered below.\n // We register `/__paths__/:routeKey{.+}` first (see directly below), and\n // Hono dispatches by registration order, so it wins those requests.\n for (const page of opts.pages) {\n if (routeShadowsPathsEndpoint(page.route)) {\n // Use console.warn so the message reaches the host's tail logs\n // without bringing down the worker. The build pipeline's\n // /__paths__ requests resolve through the synthetic handler, which\n // is registered first and wins GET/HEAD requests.\n console.warn(\n `[zfb-runtime] route \"${page.route}\" is hidden by the synthetic /__paths__ endpoint for GET/HEAD requests (it is registered first and wins); rename the page or use a more specific pattern`,\n );\n }\n }\n\n // -------------------------------------------------------------------------\n // Synthetic `/__paths__/<encoded-route-key>` endpoint.\n //\n // Called by the Rust build pipeline (crates/zfb/src/render_pipeline.rs)\n // to evaluate non-literal `paths()` exports at runtime. The route key is\n // the Hono pattern for the page (e.g. `/blog/:slug`) percent-encoded so\n // it survives in the URL path segment. The response is a JSON array of\n // `{ params, props? }` objects identical to the `paths()` contract.\n //\n // Pattern: `/__paths__/:routeKey{.+}` — the `{.+}` quantifier (Hono's\n // regex-segment syntax) allows slashes inside the route key so\n // `/blog/:slug` decodes correctly from `/__paths__/%2Fblog%2F%3Aslug`.\n //\n // IMPORTANT: this handler is registered BEFORE user routes so a\n // user-authored top-level catchall (e.g. `/:wildcard{.+}`) cannot\n // shadow it — Hono dispatches in registration order.\n // -------------------------------------------------------------------------\n app.get(\"/__paths__/:routeKey{.+}\", async (c) => {\n // Hono's `c.req.param(\"routeKey\")` already URL-decodes the captured\n // segment when it contains a `%`, so a single decode is correct\n // here — no explicit `decodeURIComponent` (that would be a\n // double-decode and break literal `%` characters in route keys).\n const routeKey = c.req.param(\"routeKey\");\n\n const page = pagesByRoute.get(routeKey);\n if (!page) {\n return c.body(\n `[zfb-runtime] /__paths__: no page registered for route key \"${routeKey}\"`,\n 404,\n { \"Content-Type\": \"text/plain; charset=utf-8\" },\n );\n }\n\n const mod = await page.module();\n if (typeof mod.paths !== \"function\") {\n return c.body(\n `[zfb-runtime] /__paths__: page module for \"${routeKey}\" has no paths() export`,\n 404,\n { \"Content-Type\": \"text/plain; charset=utf-8\" },\n );\n }\n\n let result: unknown[];\n try {\n result = await getOrEvalPaths(pathsMemo, routeKey, mod.paths);\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n return c.body(`[zfb-runtime] /__paths__: paths() threw for \"${routeKey}\": ${msg}`, 500, {\n \"Content-Type\": \"text/plain; charset=utf-8\",\n });\n }\n\n return c.body(JSON.stringify(result), 200, {\n \"Content-Type\": \"application/json; charset=utf-8\",\n });\n });\n\n for (const page of opts.pages) {\n // `app.all` (vs `app.get`) so SSR routes whose page handler dispatches\n // by `request.method` (e.g. POST API endpoints like\n // `pages/api/*.tsx`) actually reach the handler. The handler is then\n // responsible for returning a method-appropriate status (e.g. 405 for\n // an unsupported verb). With `app.get` the inner router would 404\n // before the handler ever ran, leaving e.g. `POST /api/foo` looking\n // identical to a missing route.\n app.all(page.route, async (c) => {\n const mod = await page.module();\n if (typeof mod.default !== \"function\") {\n // Surface as a 500 with a well-known message rather than letting\n // Hono swallow the error into a generic body. T6's embedded V8\n // host log-tail / source-map plumbing is what eventually projects\n // page-side errors back to the user's TSX line; until then the\n // pinned message is the contract this layer ships.\n return c.body(\n `[zfb-runtime] page module for \"${page.route}\" did not export a default component`,\n 500,\n { \"Content-Type\": \"text/plain; charset=utf-8\" },\n );\n }\n\n // For dynamic routes that export `paths()`, look up the concrete\n // entry for this URL by matching the URL params against the\n // paths() results. This implements the ADR-002 contract:\n // paths() → [{ params, props? }]\n // render(url) → find matching entry → pass { params, props } to default()\n //\n // For static routes (no `paths()` export, no URL params), we pass\n // an empty object — the component signature has no required props.\n // For dynamic routes whose URL params do not match any paths()\n // entry, we return a 404 rather than rendering with empty props.\n //\n // Whether the route is dynamic is derived from the ROUTE PATTERN,\n // not from the captured params: for an optional catchall\n // (`/docs/:slug{.+}?`), Hono matches the bare `/docs` with NO\n // params captured at all, so `Object.keys(c.req.param())` would\n // be empty and the old gate skipped paths() entirely — rendering\n // with `{}` instead of the entry whose `slug` is `[]`.\n const declaredParams = routeParamSpecs(page.route);\n const rawUrlParams = c.req.param() ?? {};\n const urlParams: Record<string, string> = {};\n for (const [k, v] of Object.entries(rawUrlParams)) {\n // Unmatched optional params may surface as undefined — drop them\n // so \"param absent\" is represented uniformly.\n if (typeof v === \"string\") urlParams[k] = v;\n }\n const isDynamicRoute = declaredParams.length > 0;\n\n let componentInput: Record<string, unknown> = {};\n\n if (isDynamicRoute && typeof mod.paths === \"function\") {\n let pathsResult: unknown;\n try {\n pathsResult = await getOrEvalPaths(pathsMemo, page.route, mod.paths);\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n return c.body(`[zfb-runtime] paths() threw for \"${page.route}\": ${msg}`, 500, {\n \"Content-Type\": \"text/plain; charset=utf-8\",\n });\n }\n\n if (!Array.isArray(pathsResult)) {\n return c.body(`[zfb-runtime] paths() for \"${page.route}\" did not return an array`, 500, {\n \"Content-Type\": \"text/plain; charset=utf-8\",\n });\n }\n\n // Validate each entry's shape per-entry rather than using a bare\n // cast — matches the strictness the Rust pipeline applies on the\n // same wire format. Any malformed entry surfaces as a 500.\n for (const entry of pathsResult) {\n if (!isPathsEntry(entry)) {\n return c.body(\n `[zfb-runtime] paths() for \"${page.route}\" returned an entry without a valid params object`,\n 500,\n { \"Content-Type\": \"text/plain; charset=utf-8\" },\n );\n }\n }\n\n // Find the entry whose params match the URL params for this\n // request. For catchall params (e.g. slug for\n // /docs/[...slug]), Hono returns a slash-joined string (e.g.\n // \"guides/install\"), so we compare against the paths() entry's\n // params.slug joined with \"/\".\n //\n // Matching iterates the params DECLARED by the route pattern so\n // the zero-segment optional-catchall case is covered: when Hono\n // matched `/docs` for `/docs/:slug{.+}?` no `slug` param exists\n // in the URL, and the matching entry is the one whose param is\n // the explicit empty array (`{ slug: [] }`).\n const match = (pathsResult as PathsEntry[]).find((entry) => {\n return declaredParams.every(({ name, optionalCatchall }) => {\n const urlVal = urlParams[name];\n const paramVal = entry.params[name];\n if (urlVal === undefined) {\n // Param absent from the URL: only valid for an optional\n // catchall, and only against the explicit `[]` entry.\n return optionalCatchall && Array.isArray(paramVal) && paramVal.length === 0;\n }\n if (Array.isArray(paramVal)) {\n // catchall: paths() emits slug as string[] but Hono\n // provides it as a \"/\"-joined string\n return paramVal.join(\"/\") === urlVal;\n }\n return String(paramVal) === urlVal;\n });\n });\n\n if (!match) {\n // The URL params do not correspond to any paths() entry —\n // this is the dev-mode equivalent of a build-time miss.\n // Hono's `c.notFound()` returns Hono's default 404,\n // which is cleaner than fabricating an empty-props render.\n return c.notFound();\n }\n\n // Pass the paths() entry's props directly as component props\n // (spread to top level, matching the Astro/zfb convention).\n // Also include `params` so components can access URL params if\n // needed, but individual prop keys from `props` win on collision.\n componentInput = {\n params: match.params,\n ...(match.props ?? {}),\n };\n } else if (isDynamicRoute) {\n // Dynamic route with no `paths()` export: the natural shape for a\n // per-request SSR page whose slugs can't be enumerated ahead of\n // time. Neither branch above applies (no paths() to match against,\n // and getStaticProps only fires for static routes), so without this\n // the component would be invoked with `{}` — no params, no\n // diagnostic, and no way to know which slug it is serving. Pass the\n // URL params through directly instead.\n componentInput = { params: urlParams };\n } else if (!isDynamicRoute && typeof mod.getStaticProps === \"function\") {\n // Static route with `getStaticProps`: call it to fetch build-time\n // data and pass the returned props to the default component. This\n // supports the `export async function getStaticProps()` pattern\n // used by static pages that need to query content collections (e.g.\n // a homepage listing all blog posts via `getCollection(\"blog\")`).\n let staticPropsResult: unknown;\n try {\n staticPropsResult = await mod.getStaticProps();\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n return c.body(`[zfb-runtime] getStaticProps() threw for \"${page.route}\": ${msg}`, 500, {\n \"Content-Type\": \"text/plain; charset=utf-8\",\n });\n }\n if (\n typeof staticPropsResult !== \"object\" ||\n staticPropsResult === null ||\n !(\"props\" in staticPropsResult)\n ) {\n return c.body(\n `[zfb-runtime] getStaticProps() for \"${page.route}\" must return { props: {...} }`,\n 500,\n { \"Content-Type\": \"text/plain; charset=utf-8\" },\n );\n }\n componentInput = (staticPropsResult as { props: Record<string, unknown> }).props;\n }\n\n // `await` so async page modules (e.g. API routes typed as\n // `(): Promise<Response>`) resolve before we inspect the value.\n // For sync pages that return a VNode/string the await is a no-op.\n //\n // Wrapped in a try/catch so that any error thrown by the component\n // or by renderToString surfaces as a descriptive 500 rather than\n // escaping to Hono's generic error handler (which discards the real\n // message). Mirrors the getStaticProps catch above.\n try {\n const result = await mod.default(componentInput);\n // API route short-circuit: a page module that returns a Response\n // directly (e.g. `pages/api/*.tsx` handlers that use Web Fetch\n // primitives instead of returning JSX) is responsible for its own\n // status, headers, and body — return it as-is rather than running\n // it through the owned SSR renderer. A `return` from inside a\n // `try` does not trigger the `catch`, so this passes through\n // correctly without special-casing.\n if (result instanceof Response) {\n return result;\n }\n // Non-HTML routes (e.g. `sitemap.xml.tsx`, `feed.xml.tsx`) commonly\n // return their body as a pre-serialised `string` instead of a\n // VNode. Routing those through `renderToString` would\n // HTML-escape the angle brackets and ampersands, producing\n // garbage XML. Pass strings through verbatim; only wrap actual\n // VNodes.\n const html = typeof result === \"string\" ? result : renderToString(result as never);\n const contentType = mod.contentType ?? DEFAULT_CONTENT_TYPE;\n return c.body(ensureHtml5Doctype(html, contentType), 200, { \"Content-Type\": contentType });\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n // __zfb.ssrDebug is set only by the embedded V8 build/dev host\n // (globals_shim.js), never by the production Workers runtime.\n const includeStack =\n opts.includeErrorStack ??\n (globalThis as { __zfb?: { ssrDebug?: boolean } }).__zfb?.ssrDebug === true;\n const stack = includeStack && err instanceof Error && err.stack ? `\\n${err.stack}` : \"\";\n return c.body(`[zfb-runtime] render threw for \"${page.route}\": ${msg}${stack}`, 500, {\n \"Content-Type\": \"text/plain; charset=utf-8\",\n });\n }\n });\n }\n\n // Hono's `app.fetch` returns `Response | Promise<Response>`. The\n // public router contract is unconditionally async; using an `async`\n // wrapper (rather than `Promise.resolve(...)`) ensures any\n // synchronous throw inside `app.fetch` is converted to a rejected\n // promise instead of escaping the caller's `await`.\n return async (request) => await app.fetch(request);\n}\n\n/**\n * Shape of one entry produced by a page's `paths()` export. The\n * `params` object is required (every entry needs to identify the URL\n * it represents); `props` is optional (the page may render purely from\n * the URL params).\n */\ninterface PathsEntry {\n readonly params: Record<string, unknown>;\n readonly props?: Record<string, unknown>;\n}\n\n/**\n * Type guard for one `paths()` entry. Mirrors the strictness of the\n * Rust pipeline's `paths()` resolver — every entry must be a non-null\n * object whose `params` is itself a non-null object.\n */\nfunction isPathsEntry(x: unknown): x is PathsEntry {\n if (typeof x !== \"object\" || x === null) return false;\n const params = (x as { params?: unknown }).params;\n return typeof params === \"object\" && params !== null;\n}\n\n/**\n * One param declared by a Hono route pattern. `optionalCatchall` is\n * `true` for the `:name{.+}?` form (file-system `[[...name]]`), whose\n * zero-segment match captures no param at all.\n */\ninterface RouteParamSpec {\n readonly name: string;\n readonly optionalCatchall: boolean;\n}\n\n/**\n * Parse the params declared by a Hono route pattern (the `route` string\n * the build pipeline registers, e.g. `/blog/:slug`, `/docs/:slug{.+}`,\n * `/docs/:slug{.+}?`). Static routes return an empty list.\n *\n * Only the pattern shapes emitted by `bracket_to_hono` (zfb-build) are\n * recognised — `:name`, `:name{.+}`, `:name{.+}?` — which is the entire\n * grammar the file router produces.\n */\nfunction routeParamSpecs(route: string): RouteParamSpec[] {\n const specs: RouteParamSpec[] = [];\n for (const seg of route.split(\"/\")) {\n if (!seg.startsWith(\":\")) continue;\n const optionalCatchall = seg.endsWith(\"?\");\n const body = optionalCatchall ? seg.slice(1, -1) : seg.slice(1);\n const braceIdx = body.indexOf(\"{\");\n const name = braceIdx === -1 ? body : body.slice(0, braceIdx);\n if (name.length > 0) {\n specs.push({ name, optionalCatchall });\n }\n }\n return specs;\n}\n\n/**\n * Check whether a user-authored route is hidden by the synthetic\n * `/__paths__/<encoded-route-key>` endpoint.\n *\n * Returns true only when the first route segment is the literal\n * `__paths__` and at least one later segment is non-empty. Those are\n * the routes matched by the synthetic endpoint's `:routeKey{.+}` pattern.\n */\nfunction routeShadowsPathsEndpoint(route: string): boolean {\n const segments = route.replace(/^\\/+/, \"\").split(\"/\");\n return segments[0] === \"__paths__\" && segments.slice(1).some((segment) => segment.length > 0);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,EAAE;AACF,wEAAwE;AACxE,mCAAmC;AACnC,EAAE;AACF,oDAAoD;AACpD,0DAA0D;AAC1D,8EAA8E;AAC9E,qDAAqD;AACrD,uCAAuC;AACvC,EAAE;AACF,qEAAqE;AACrE,0EAA0E;AAC1E,uEAAuE;AACvE,uEAAuE;AACvE,4DAA4D;AAC5D,EAAE;AACF,qEAAqE;AACrE,kEAAkE;AAClE,oEA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EAAE,gBAAgB,EAAE,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,yBAAyB,CAAC,KAAa;IAC9C,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtD,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAK,WAAW,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAChG,CAAC","sourcesContent":["// `@takazudo/zfb-runtime` — Hono-based page router.\n//\n// `createPageRouter` is the JS-side entry point for ADR-007's SSG-first\n// architecture. The pipeline goes:\n//\n// user pages/ + content/ + layouts/ + components/\n// → esbuild bundle (T3) // single ESM file\n// → embedded V8 host (T6) // same WinterCG surface as CF Workers\n// → createPageRouter({ pages, contentSnapshot })\n// → (request) => Promise<Response>\n//\n// The bundle's Worker entry point shape is documented in the package\n// README. The contract is intentionally minimal: one factory call returns\n// one fetch handler. Hono is an implementation detail — callers should\n// not depend on the Hono types leaking through. The exposed surface is\n// the four types here plus the `createPageRouter` function.\n//\n// Side effect on init: registers the supplied `ContentSnapshot` with\n// `zfb/content`'s module-level snapshot bridge so any page module\n// importing `getCollection(\"...\")` resolves from memory rather than\n// touching the Node `fs` API (the Worker runtime has no `fs`).\n//\n// ## Synthetic `__paths__` endpoint\n//\n// The Rust build pipeline needs to evaluate non-literal `paths()` exports\n// (e.g. those that `await import(\"@takazudo/zfb/content\")` and call `getCollection`)\n// at runtime against the running embedded host. The router exposes a\n// synthetic internal endpoint:\n//\n// GET /__paths__/<percent-encoded-route-key>\n//\n// When a page registered at `route` has a `paths` export, the handler calls\n// it and returns the JSON-serialized array as `application/json`. If the\n// `paths` export is missing or throws, the response is a descriptive 500.\n// This endpoint is only meant for the build pipeline — it is safe to leave\n// registered in production. During build/check/dev route scans, `zfb-router`\n// rejects `pages/__paths__/<...>` with `RouterError::ReservedRoutePrefix`.\n// The warning below remains as belt-and-braces for `createPageRouter` callers\n// that hand-build `pages` and therefore bypass the scanner.\n\nimport { Hono } from \"hono\";\nimport { setContentSnapshot } from \"@takazudo/zfb/content\";\n\nimport { renderToString } from \"@takazudo/zfb/zudo-react/server\";\nimport type { ContentSnapshot } from \"./snapshot.js\";\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\n/**\n * Heading metadata emitted by the MDX `headings` export (T4). Cross-ref:\n * `crates/zfb-content/src/mdx_jsx_emit.rs`. Optional on the page-module\n * shape — non-MDX pages won't carry it.\n */\nexport interface PageHeading {\n readonly depth: number;\n readonly slug: string;\n readonly text: string;\n}\n\n/**\n * The shape every page module must export.\n *\n * - `default`: the JSX page component. Called with the props returned by\n * `getStaticProps` (if exported) or the `props` from the matching\n * `paths()` entry (for dynamic routes). The return value is fed straight\n * to the owned server renderer's `renderToString`. A dynamic route with no\n * `paths()` export is called with `{ params: urlParams }` instead of\n * `{}` — see `createPageRouter`'s JSDoc for the full componentInput\n * derivation table.\n * - `prerender`: literal `false` opts a route OUT of build-time SSG (T5\n * contract). The page router still serves it under the embedded V8 host\n * so dev mode behaves identically; SSG callers filter the route list before\n * driving the renderer.\n * - `contentType`: optional override for non-HTML routes (e.g.\n * `application/xml` for `rss.xml.tsx`). Default is\n * `text/html; charset=utf-8`. Cross-ref shipped #49.\n * - `headings`: optional list emitted by MDX (T4).\n * - `paths`: optional dynamic-route enumerator. Called at build time by\n * the `__paths__` synthetic endpoint to produce the concrete URL list\n * for this route template. May be async. Returns an array of\n * `{ params, props? }` objects identical in shape to the Astro/zfb\n * `paths()` contract.\n * **Evaluated once per router instance** — the result is memoised and\n * shared across the `/__paths__` handler and all per-page render\n * requests. This matches the build-time-enumerator contract: every\n * entry rendered within a single build sees the same paths() snapshot.\n * Dev mode is safe because each file-save triggers a fresh bundle,\n * which creates a new router instance with a clean memo.\n * - `getStaticProps`: optional async function for static routes that need\n * to fetch data at build/render time. Called once per request (before\n * `default`). Must return `{ props: Record<string, unknown> }`. The\n * returned `props` are spread into the `default` component's props.\n */\nexport interface PageModule {\n readonly default: (props: Record<string, unknown>) => unknown;\n readonly prerender?: boolean;\n readonly contentType?: string;\n readonly headings?: readonly PageHeading[];\n readonly paths?: () => unknown[] | Promise<unknown[]>;\n readonly getStaticProps?: () => Promise<{ props: Record<string, unknown> }>;\n}\n\n/**\n * One page registered with the router.\n *\n * `route` is a Hono path pattern (e.g. `/`, `/blog/:slug`,\n * `/blog/page/:page`). `module` is a thunk so the bundle can use code\n * splitting if it wants to — today the bundler emits everything as one\n * ESM file and the thunk simply returns the already-loaded module.\n */\nexport interface PageDefinition {\n readonly route: string;\n readonly module: () => Promise<PageModule>;\n}\n\n/** Options accepted by [`createPageRouter`]. */\nexport interface CreatePageRouterOptions {\n /** Pages to register. Order does not affect routing — Hono dispatches by path. */\n readonly pages: readonly PageDefinition[];\n /**\n * In-memory content snapshot. Embedded into the bundle by T3; the\n * router hands it to `zfb/content` so user pages reading content via\n * `getCollection(...)` resolve synchronously from memory.\n */\n readonly contentSnapshot: ContentSnapshot;\n /**\n * When `true`, the 500 body for render errors includes the full JS stack\n * trace. When `false`, only the message + route are included. When\n * omitted, the runtime checks `globalThis.__zfb.ssrDebug` at request time:\n * that flag is set by the embedded V8 build/dev host (`globals_shim.js`)\n * and is absent on the production Cloudflare Workers runtime.\n *\n * Default is effectively OFF for production (no flag ⇒ message + route only).\n * Useful for explicit injection in unit tests without global mutation.\n */\n readonly includeErrorStack?: boolean;\n}\n\n/**\n * Fetch-handler shape returned by [`createPageRouter`]. Shaped as a plain\n * function (not a Hono `app`) so the consumer's contract is exactly\n * \"Worker-style fetch handler\" with no leaked renderer types.\n */\nexport type PageRouter = (request: Request) => Promise<Response>;\n\n// ---------------------------------------------------------------------------\n// Implementation\n// ---------------------------------------------------------------------------\n\n/**\n * Default content-type when a page module does not override.\n *\n * Aligned with #49's per-page `contentType` convention: the default\n * served for HTML pages is `text/html; charset=utf-8`. Tests pin this\n * verbatim because the embedded V8 host does NOT auto-set a charset.\n */\nconst DEFAULT_CONTENT_TYPE = \"text/html; charset=utf-8\";\n\n/**\n * Issue #530: prepend `<!doctype html>\\n` to SSR-rendered HTML bodies that\n * lack a doctype declaration, mirroring the guard in\n * `crates/zfb-build/src/renderer.rs::render_one_inner` (issue #524).\n *\n * Gate conditions (all must hold to prepend):\n * 1. `contentType` media-type (before `;`) is `text/html` (case-insensitive).\n * 2. The body, after stripping an optional UTF-8 BOM (U+FEFF) and leading\n * ASCII whitespace, starts with `<html` (case-insensitive) — i.e. it is\n * an `<html>`-rooted document, not XML / JSON / a fragment.\n * 3. The body (same stripped prefix) does NOT already begin with `<!doctype`\n * (case-insensitive).\n *\n * Deliberately NOT shared with the Rust side — duplication of a 5-line guard\n * is the right call rather than introducing a new cross-language boundary.\n */\nfunction ensureHtml5Doctype(body: string, contentType: string): string {\n const mediaType = contentType.split(\";\")[0]?.trim().toLowerCase();\n if (mediaType !== \"text/html\") return body;\n // Strip optional BOM and leading whitespace to inspect the root element.\n const stripped = body.replace(/^/, \"\").trimStart();\n if (!stripped.toLowerCase().startsWith(\"<!doctype\")) {\n if (stripped.toLowerCase().startsWith(\"<html\")) {\n return `<!doctype html>\\n${body}`;\n }\n }\n return body;\n}\n\n/**\n * Evaluate `pathsFn` once per `routeKey`, sharing the result across all\n * concurrent and subsequent callers via a Promise stored in `memo`.\n *\n * Rejections are evicted from the memo so that a transient paths() failure\n * does not permanently poison the cache — the next request retries.\n */\nasync function getOrEvalPaths(\n memo: Map<string, Promise<unknown[]>>,\n routeKey: string,\n pathsFn: () => unknown[] | Promise<unknown[]>,\n): Promise<unknown[]> {\n const existing = memo.get(routeKey);\n if (existing !== undefined) {\n return existing;\n }\n const promise = Promise.resolve(pathsFn()).then(\n (v) => v as unknown[],\n (err) => {\n // Evict on rejection so the next request retries.\n memo.delete(routeKey);\n return Promise.reject(err) as Promise<unknown[]>;\n },\n );\n memo.set(routeKey, promise);\n return promise;\n}\n\n/**\n * Build a page router for the SSG-first architecture (ADR-005).\n *\n * Side effects:\n * 1. Registers `opts.contentSnapshot` with the `zfb/content` module so\n * `getCollection(name)` resolves from memory. Idempotent across\n * calls — the latest snapshot wins (matches the documented dev-mode\n * live-reload contract).\n * 2. Constructs an internal Hono app and registers an **all-methods**\n * handler (`app.all`, not `app.get`) per `pages[i].route`, so an SSR\n * route that dispatches on `request.method` — e.g. a POST endpoint\n * under `pages/api/` — actually reaches its handler instead of being\n * 404'd by the inner router. See the comment at the `app.all` call\n * site below. The handler imports the page module, calls\n * `renderToString(module.default(componentInput))`, and\n * returns the string in a `Response` with the appropriate\n * `Content-Type`. (`componentInput` is the page's props object — see\n * the derivation table below; it is never the incoming `Request`.)\n *\n * Per-route `componentInput` (the object passed to `module.default(...)`) is\n * derived from the route pattern and the page module's exports:\n * - Dynamic route + `paths()` export: match the URL params against the\n * `paths()` entries and pass `{ params, ...props }` (404 on no match).\n * - Static route + `getStaticProps()` export: pass the returned `props`.\n * - Dynamic route with NO `paths()` export (e.g. a per-request SSR page\n * whose slugs can't be enumerated ahead of time): pass `{ params:\n * urlParams }` so the component still knows which URL params it is\n * serving, rather than being invoked with `{}`.\n * - Anything else (static route, no `getStaticProps`): pass `{}`.\n *\n * The returned function is a plain `(request) => Promise<Response>` so a\n * Worker entry point can `export default { fetch: createPageRouter(...) }`\n * directly.\n */\nexport function createPageRouter(opts: CreatePageRouterOptions): PageRouter {\n setContentSnapshot(opts.contentSnapshot);\n\n const app = new Hono();\n\n // Build a lookup map: Hono route pattern → PageDefinition, for the\n // `__paths__` synthetic endpoint below. The map is keyed on the `route`\n // string exactly as the caller supplied it (e.g. \"/blog/:slug\").\n const pagesByRoute = new Map<string, PageDefinition>();\n for (const page of opts.pages) {\n pagesByRoute.set(page.route, page);\n }\n\n // Per-router-instance memo for paths() results.\n //\n // Keyed on page.route (e.g. \"/blog/:slug\"). Stores the in-flight or\n // settled Promise so that concurrent requests share one evaluation.\n // Rejections are NOT cached: if paths() throws the Promise is removed\n // from the map so the next request retries rather than re-propagating\n // the same error indefinitely.\n //\n // Production SSR isolates evaluate paths() once per isolate, which\n // matches the documented build-time-enumerator contract. Dev mode is\n // safe because each re-bundle creates a fresh router instance\n // (dev.rs reload_renderer), so stale paths() results never persist\n // across a file-save cycle. Watch-time invalidation is explicitly\n // out of scope per issue #507.\n const pathsMemo = new Map<string, Promise<unknown[]>>();\n\n // Sanity check: a user-authored route under `/__paths__/...` has its\n // GET/HEAD responses hidden by the synthetic endpoint registered below.\n // We register `/__paths__/:routeKey{.+}` first (see directly below), and\n // Hono dispatches by registration order, so it wins those requests.\n for (const page of opts.pages) {\n if (routeShadowsPathsEndpoint(page.route)) {\n // Use console.warn so the message reaches the host's tail logs\n // without bringing down the worker. The build pipeline's\n // /__paths__ requests resolve through the synthetic handler, which\n // is registered first and wins GET/HEAD requests.\n console.warn(\n `[zfb-runtime] route \"${page.route}\" is hidden by the synthetic /__paths__ endpoint for GET/HEAD requests (it is registered first and wins); rename the page or use a more specific pattern`,\n );\n }\n }\n\n // -------------------------------------------------------------------------\n // Synthetic `/__paths__/<encoded-route-key>` endpoint.\n //\n // Called by the Rust build pipeline (crates/zfb/src/render_pipeline.rs)\n // to evaluate non-literal `paths()` exports at runtime. The route key is\n // the Hono pattern for the page (e.g. `/blog/:slug`) percent-encoded so\n // it survives in the URL path segment. The response is a JSON array of\n // `{ params, props? }` objects identical to the `paths()` contract.\n //\n // Pattern: `/__paths__/:routeKey{.+}` — the `{.+}` quantifier (Hono's\n // regex-segment syntax) allows slashes inside the route key so\n // `/blog/:slug` decodes correctly from `/__paths__/%2Fblog%2F%3Aslug`.\n //\n // IMPORTANT: this handler is registered BEFORE user routes so a\n // user-authored top-level catchall (e.g. `/:wildcard{.+}`) cannot\n // shadow it — Hono dispatches in registration order.\n // -------------------------------------------------------------------------\n app.get(\"/__paths__/:routeKey{.+}\", async (c) => {\n // Hono's `c.req.param(\"routeKey\")` already URL-decodes the captured\n // segment when it contains a `%`, so a single decode is correct\n // here — no explicit `decodeURIComponent` (that would be a\n // double-decode and break literal `%` characters in route keys).\n const routeKey = c.req.param(\"routeKey\");\n\n const page = pagesByRoute.get(routeKey);\n if (!page) {\n return c.body(\n `[zfb-runtime] /__paths__: no page registered for route key \"${routeKey}\"`,\n 404,\n { \"Content-Type\": \"text/plain; charset=utf-8\" },\n );\n }\n\n const mod = await page.module();\n if (typeof mod.paths !== \"function\") {\n return c.body(\n `[zfb-runtime] /__paths__: page module for \"${routeKey}\" has no paths() export`,\n 404,\n { \"Content-Type\": \"text/plain; charset=utf-8\" },\n );\n }\n\n let result: unknown[];\n try {\n result = await getOrEvalPaths(pathsMemo, routeKey, mod.paths);\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n return c.body(`[zfb-runtime] /__paths__: paths() threw for \"${routeKey}\": ${msg}`, 500, {\n \"Content-Type\": \"text/plain; charset=utf-8\",\n });\n }\n\n return c.body(JSON.stringify(result), 200, {\n \"Content-Type\": \"application/json; charset=utf-8\",\n });\n });\n\n for (const page of opts.pages) {\n // `app.all` (vs `app.get`) so SSR routes whose page handler dispatches\n // by `request.method` (e.g. POST API endpoints like\n // `pages/api/*.tsx`) actually reach the handler. The handler is then\n // responsible for returning a method-appropriate status (e.g. 405 for\n // an unsupported verb). With `app.get` the inner router would 404\n // before the handler ever ran, leaving e.g. `POST /api/foo` looking\n // identical to a missing route.\n app.all(page.route, async (c) => {\n const mod = await page.module();\n if (typeof mod.default !== \"function\") {\n // Surface as a 500 with a well-known message rather than letting\n // Hono swallow the error into a generic body. T6's embedded V8\n // host log-tail / source-map plumbing is what eventually projects\n // page-side errors back to the user's TSX line; until then the\n // pinned message is the contract this layer ships.\n return c.body(\n `[zfb-runtime] page module for \"${page.route}\" did not export a default component`,\n 500,\n { \"Content-Type\": \"text/plain; charset=utf-8\" },\n );\n }\n\n // For dynamic routes that export `paths()`, look up the concrete\n // entry for this URL by matching the URL params against the\n // paths() results. This implements the ADR-002 contract:\n // paths() → [{ params, props? }]\n // render(url) → find matching entry → pass { params, props } to default()\n //\n // For static routes (no `paths()` export, no URL params), we pass\n // an empty object — the component signature has no required props.\n // For dynamic routes whose URL params do not match any paths()\n // entry, we return a 404 rather than rendering with empty props.\n //\n // Whether the route is dynamic is derived from the ROUTE PATTERN,\n // not from the captured params: for an optional catchall\n // (`/docs/:slug{.+}?`), Hono matches the bare `/docs` with NO\n // params captured at all, so `Object.keys(c.req.param())` would\n // be empty and the old gate skipped paths() entirely — rendering\n // with `{}` instead of the entry whose `slug` is `[]`.\n const declaredParams = routeParamSpecs(page.route);\n const rawUrlParams = c.req.param() ?? {};\n const urlParams: Record<string, string> = {};\n for (const [k, v] of Object.entries(rawUrlParams)) {\n // Unmatched optional params may surface as undefined — drop them\n // so \"param absent\" is represented uniformly.\n if (typeof v === \"string\") urlParams[k] = v;\n }\n const isDynamicRoute = declaredParams.length > 0;\n\n let componentInput: Record<string, unknown> = {};\n\n if (isDynamicRoute && typeof mod.paths === \"function\") {\n let pathsResult: unknown;\n try {\n pathsResult = await getOrEvalPaths(pathsMemo, page.route, mod.paths);\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n return c.body(`[zfb-runtime] paths() threw for \"${page.route}\": ${msg}`, 500, {\n \"Content-Type\": \"text/plain; charset=utf-8\",\n });\n }\n\n if (!Array.isArray(pathsResult)) {\n return c.body(`[zfb-runtime] paths() for \"${page.route}\" did not return an array`, 500, {\n \"Content-Type\": \"text/plain; charset=utf-8\",\n });\n }\n\n // Validate each entry's shape per-entry rather than using a bare\n // cast — matches the strictness the Rust pipeline applies on the\n // same wire format. Any malformed entry surfaces as a 500.\n for (const entry of pathsResult) {\n if (!isPathsEntry(entry)) {\n return c.body(\n `[zfb-runtime] paths() for \"${page.route}\" returned an entry without a valid params object`,\n 500,\n { \"Content-Type\": \"text/plain; charset=utf-8\" },\n );\n }\n }\n\n // Find the entry whose params match the URL params for this\n // request. For catchall params (e.g. slug for\n // /docs/[...slug]), Hono returns a slash-joined string (e.g.\n // \"guides/install\"), so we compare against the paths() entry's\n // params.slug joined with \"/\".\n //\n // Matching iterates the params DECLARED by the route pattern so\n // the zero-segment optional-catchall case is covered: when Hono\n // matched `/docs` for `/docs/:slug{.+}?` no `slug` param exists\n // in the URL, and the matching entry is the one whose param is\n // the explicit empty array (`{ slug: [] }`).\n const match = (pathsResult as PathsEntry[]).find((entry) => {\n return declaredParams.every(({ name, optionalCatchall }) => {\n const urlVal = urlParams[name];\n const paramVal = entry.params[name];\n if (urlVal === undefined) {\n // Param absent from the URL: only valid for an optional\n // catchall, and only against the explicit `[]` entry.\n return optionalCatchall && Array.isArray(paramVal) && paramVal.length === 0;\n }\n if (Array.isArray(paramVal)) {\n // catchall: paths() emits slug as string[] but Hono\n // provides it as a \"/\"-joined string\n return paramVal.join(\"/\") === urlVal;\n }\n return String(paramVal) === urlVal;\n });\n });\n\n if (!match) {\n // The URL params do not correspond to any paths() entry —\n // this is the dev-mode equivalent of a build-time miss.\n // Hono's `c.notFound()` returns Hono's default 404,\n // which is cleaner than fabricating an empty-props render.\n return c.notFound();\n }\n\n // Pass the paths() entry's props directly as component props\n // (spread to top level, matching the Astro/zfb convention).\n // Also include `params` so components can access URL params if\n // needed, but individual prop keys from `props` win on collision.\n componentInput = {\n params: match.params,\n ...(match.props ?? {}),\n };\n } else if (isDynamicRoute) {\n // Dynamic route with no `paths()` export: the natural shape for a\n // per-request SSR page whose slugs can't be enumerated ahead of\n // time. Neither branch above applies (no paths() to match against,\n // and getStaticProps only fires for static routes), so without this\n // the component would be invoked with `{}` — no params, no\n // diagnostic, and no way to know which slug it is serving. Pass the\n // URL params through directly instead.\n componentInput = { params: urlParams };\n } else if (!isDynamicRoute && typeof mod.getStaticProps === \"function\") {\n // Static route with `getStaticProps`: call it to fetch build-time\n // data and pass the returned props to the default component. This\n // supports the `export async function getStaticProps()` pattern\n // used by static pages that need to query content collections (e.g.\n // a homepage listing all blog posts via `getCollection(\"blog\")`).\n let staticPropsResult: unknown;\n try {\n staticPropsResult = await mod.getStaticProps();\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n return c.body(`[zfb-runtime] getStaticProps() threw for \"${page.route}\": ${msg}`, 500, {\n \"Content-Type\": \"text/plain; charset=utf-8\",\n });\n }\n if (\n typeof staticPropsResult !== \"object\" ||\n staticPropsResult === null ||\n !(\"props\" in staticPropsResult)\n ) {\n return c.body(\n `[zfb-runtime] getStaticProps() for \"${page.route}\" must return { props: {...} }`,\n 500,\n { \"Content-Type\": \"text/plain; charset=utf-8\" },\n );\n }\n componentInput = (staticPropsResult as { props: Record<string, unknown> }).props;\n }\n\n // `await` so async page modules (e.g. API routes typed as\n // `(): Promise<Response>`) resolve before we inspect the value.\n // For sync pages that return a VNode/string the await is a no-op.\n //\n // Wrapped in a try/catch so that any error thrown by the component\n // or by renderToString surfaces as a descriptive 500 rather than\n // escaping to Hono's generic error handler (which discards the real\n // message). Mirrors the getStaticProps catch above.\n const renderPage = async (): Promise<Response | string> => {\n const result = await mod.default(componentInput);\n if (result instanceof Response || typeof result === \"string\") return result;\n return renderToString(result as never);\n };\n try {\n const result = await mod.default(componentInput);\n // API route short-circuit: a page module that returns a Response\n // directly (e.g. `pages/api/*.tsx` handlers that use Web Fetch\n // primitives instead of returning JSX) is responsible for its own\n // status, headers, and body — return it as-is rather than running\n // it through the owned SSR renderer. A `return` from inside a\n // `try` does not trigger the `catch`, so this passes through\n // correctly without special-casing.\n if (result instanceof Response) {\n return result;\n }\n // Non-HTML routes (e.g. `sitemap.xml.tsx`, `feed.xml.tsx`) commonly\n // return their body as a pre-serialised `string` instead of a\n // VNode. Routing those through `renderToString` would\n // HTML-escape the angle brackets and ampersands, producing\n // garbage XML. Pass strings through verbatim; only wrap actual\n // VNodes.\n const html = typeof result === \"string\" ? result : renderToString(result as never);\n const contentType = mod.contentType ?? DEFAULT_CONTENT_TYPE;\n return c.body(ensureHtml5Doctype(html, contentType), 200, { \"Content-Type\": contentType });\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n // __zfb.ssrDebug is set only by the embedded V8 build/dev host\n // (globals_shim.js), never by the production Workers runtime.\n const includeStack =\n opts.includeErrorStack ??\n (globalThis as { __zfb?: { ssrDebug?: boolean } }).__zfb?.ssrDebug === true;\n const stack = includeStack && err instanceof Error && err.stack ? `\\n${err.stack}` : \"\";\n const diagnostic = includeStack ? await locateRenderFailure(err, renderPage) : undefined;\n const structured = diagnostic\n ? `\\n${RENDER_DIAGNOSTIC_PREFIX}${JSON.stringify(diagnostic)}`\n : \"\";\n return c.body(\n `[zfb-runtime] render threw for \"${page.route}\": ${msg}${stack}${structured}`,\n 500,\n { \"Content-Type\": \"text/plain; charset=utf-8\" },\n );\n }\n });\n }\n\n // Hono's `app.fetch` returns `Response | Promise<Response>`. The\n // public router contract is unconditionally async; using an `async`\n // wrapper (rather than `Promise.resolve(...)`) ensures any\n // synchronous throw inside `app.fetch` is converted to a rejected\n // promise instead of escaping the caller's `await`.\n return async (request) => await app.fetch(request);\n}\n\n// zfb-build's renderer reads this line back out of the 500 body (renderer.rs).\nconst RENDER_DIAGNOSTIC_PREFIX = \"[zfb-render-diagnostic] \";\n// Shared with zudo-react's description.ts, which records jsx() call sites while it is set.\nconst SITE_CAPTURE = Symbol.for(\"@takazudo/zfb/zudo-react/site-capture-v1\");\n\ninterface RenderDiagnostic {\n readonly code: string;\n readonly path: string;\n readonly component: string;\n readonly spelling?: { readonly name: string; readonly suggestion?: string };\n readonly site?: Readonly<Record<string, string | number>>;\n}\n\nfunction renderDiagnostic(err: unknown): RenderDiagnostic | undefined {\n if (!(err instanceof Error) || !(\"diagnostic\" in err)) return undefined;\n const value = err.diagnostic as Partial<RenderDiagnostic> | null;\n if (\n typeof value !== \"object\" ||\n value === null ||\n typeof value.code !== \"string\" ||\n typeof value.path !== \"string\" ||\n typeof value.component !== \"string\"\n )\n return undefined;\n const { code, path, component, spelling, site } = value;\n return {\n code,\n path,\n component,\n ...(spelling &&\n typeof spelling.name === \"string\" && {\n spelling: {\n name: spelling.name,\n ...(typeof spelling.suggestion === \"string\" && { suggestion: spelling.suggestion }),\n },\n }),\n ...(site && { site: pickSite(site) }),\n };\n}\n\nfunction pickSite(site: Readonly<Record<string, unknown>>): Record<string, string | number> {\n const picked: Record<string, string | number> = {};\n for (const key of [\"kind\", \"file\", \"specifier\", \"line\", \"column\"])\n if (typeof site[key] === \"string\" || typeof site[key] === \"number\")\n picked[key] = site[key] as string | number;\n return picked;\n}\n\n/**\n * Production descriptions carry no call sites. When a render diagnostic has\n * none, render the page once more with call-site capture enabled so the\n * failing element's generated position can be source-mapped by the build host.\n * The replay is accepted only when it fails with the identical message.\n */\nasync function locateRenderFailure(\n err: unknown,\n render: () => Promise<unknown>,\n): Promise<RenderDiagnostic | undefined> {\n const first = renderDiagnostic(err);\n if (!first || first.site) return first;\n const flags = globalThis as Record<symbol, unknown>;\n // A count, not a flag: overlapping dev replays must not switch capture off for each other.\n flags[SITE_CAPTURE] = ((flags[SITE_CAPTURE] as number | undefined) ?? 0) + 1;\n try {\n await render();\n } catch (again) {\n const located = renderDiagnostic(again);\n if (located?.site && again instanceof Error && (err as Error).message === again.message)\n return located;\n } finally {\n const remaining = (flags[SITE_CAPTURE] as number) - 1;\n if (remaining > 0) flags[SITE_CAPTURE] = remaining;\n else delete flags[SITE_CAPTURE];\n }\n return first;\n}\n\n/**\n * Shape of one entry produced by a page's `paths()` export. The\n * `params` object is required (every entry needs to identify the URL\n * it represents); `props` is optional (the page may render purely from\n * the URL params).\n */\ninterface PathsEntry {\n readonly params: Record<string, unknown>;\n readonly props?: Record<string, unknown>;\n}\n\n/**\n * Type guard for one `paths()` entry. Mirrors the strictness of the\n * Rust pipeline's `paths()` resolver — every entry must be a non-null\n * object whose `params` is itself a non-null object.\n */\nfunction isPathsEntry(x: unknown): x is PathsEntry {\n if (typeof x !== \"object\" || x === null) return false;\n const params = (x as { params?: unknown }).params;\n return typeof params === \"object\" && params !== null;\n}\n\n/**\n * One param declared by a Hono route pattern. `optionalCatchall` is\n * `true` for the `:name{.+}?` form (file-system `[[...name]]`), whose\n * zero-segment match captures no param at all.\n */\ninterface RouteParamSpec {\n readonly name: string;\n readonly optionalCatchall: boolean;\n}\n\n/**\n * Parse the params declared by a Hono route pattern (the `route` string\n * the build pipeline registers, e.g. `/blog/:slug`, `/docs/:slug{.+}`,\n * `/docs/:slug{.+}?`). Static routes return an empty list.\n *\n * Only the pattern shapes emitted by `bracket_to_hono` (zfb-build) are\n * recognised — `:name`, `:name{.+}`, `:name{.+}?` — which is the entire\n * grammar the file router produces.\n */\nfunction routeParamSpecs(route: string): RouteParamSpec[] {\n const specs: RouteParamSpec[] = [];\n for (const seg of route.split(\"/\")) {\n if (!seg.startsWith(\":\")) continue;\n const optionalCatchall = seg.endsWith(\"?\");\n const body = optionalCatchall ? seg.slice(1, -1) : seg.slice(1);\n const braceIdx = body.indexOf(\"{\");\n const name = braceIdx === -1 ? body : body.slice(0, braceIdx);\n if (name.length > 0) {\n specs.push({ name, optionalCatchall });\n }\n }\n return specs;\n}\n\n/**\n * Check whether a user-authored route is hidden by the synthetic\n * `/__paths__/<encoded-route-key>` endpoint.\n *\n * Returns true only when the first route segment is the literal\n * `__paths__` and at least one later segment is non-empty. Those are\n * the routes matched by the synthetic endpoint's `:routeKey{.+}` pattern.\n */\nfunction routeShadowsPathsEndpoint(route: string): boolean {\n const segments = route.replace(/^\\/+/, \"\").split(\"/\");\n return segments[0] === \"__paths__\" && segments.slice(1).some((segment) => segment.length > 0);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takazudo/zfb-runtime",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "JavaScript runtime for zfb static sites — Hono-backed page router, content snapshots, and client-side hydration.",
|
|
@@ -72,19 +72,19 @@
|
|
|
72
72
|
"hono": "^4.12.25"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"@takazudo/zfb": "3.
|
|
75
|
+
"@takazudo/zfb": "3.2.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
+
"@takazudo/zfb": "3.2.0",
|
|
78
79
|
"@types/node": "^22.0.0",
|
|
79
80
|
"happy-dom": "^15.7.4",
|
|
80
|
-
"typescript": "
|
|
81
|
-
"
|
|
82
|
-
"@takazudo/zfb": "3.1.0"
|
|
81
|
+
"typescript": "7.0.2",
|
|
82
|
+
"vite-plus": "1.0.0"
|
|
83
83
|
},
|
|
84
84
|
"scripts": {
|
|
85
85
|
"build": "tsc",
|
|
86
|
-
"test": "
|
|
87
|
-
"test:watch": "
|
|
86
|
+
"test": "vp test run",
|
|
87
|
+
"test:watch": "vp test",
|
|
88
88
|
"typecheck": "tsc --noEmit"
|
|
89
89
|
}
|
|
90
90
|
}
|