reroute-js 0.46.0 → 1.0.0-alpha.1

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.
Files changed (215) hide show
  1. package/README.md +2 -4
  2. package/_/store/package.json +1 -3
  3. package/_/store/src/client/components/Header.tsx +8 -20
  4. package/_/store/src/client/components/ProductCard.tsx +9 -16
  5. package/_/store/src/client/index.css +1118 -0
  6. package/_/store/src/client/routes/[404].tsx +20 -31
  7. package/_/store/src/client/routes/categories/[category].tsx +23 -28
  8. package/_/store/src/client/routes/categories/index.tsx +19 -27
  9. package/_/store/src/client/routes/index.tsx +27 -37
  10. package/_/store/src/client/routes/products/[id].tsx +35 -48
  11. package/_/store/src/client/routes/products/index.tsx +20 -50
  12. package/cli/bin.d.ts +1 -1
  13. package/cli/bin.js +87 -185
  14. package/cli/bin.js.map +11 -11
  15. package/cli/index.d.ts +1 -1
  16. package/cli/index.js +19 -114
  17. package/cli/index.js.map +5 -5
  18. package/cli/src/cli.d.ts +1 -1
  19. package/cli/src/commands/analyze.d.ts +1 -1
  20. package/cli/src/commands/build.d.ts +1 -1
  21. package/cli/src/commands/dev.d.ts +1 -1
  22. package/cli/src/commands/gen.d.ts +1 -1
  23. package/cli/src/commands/gen.d.ts.map +1 -1
  24. package/cli/src/commands/index.d.ts +1 -1
  25. package/cli/src/commands/init.d.ts +1 -1
  26. package/cli/src/commands/lib/assets.d.ts +1 -1
  27. package/cli/src/commands/lib/bundler.d.ts +1 -1
  28. package/cli/src/commands/lib/command.d.ts +1 -1
  29. package/cli/src/commands/lib/env.d.ts +1 -1
  30. package/cli/src/commands/lib/index.d.ts +2 -2
  31. package/cli/src/commands/lib/index.d.ts.map +1 -1
  32. package/cli/src/commands/lib/log.d.ts +1 -1
  33. package/cli/src/commands/lib/markdown/availability.d.ts +1 -1
  34. package/cli/src/commands/lib/markdown/index.d.ts +1 -1
  35. package/cli/src/commands/lib/markdown/processor.d.ts +1 -1
  36. package/cli/src/commands/lib/production.d.ts +1 -1
  37. package/cli/src/commands/lib/server.d.ts +1 -1
  38. package/cli/src/commands/lib/streaming/analyzer.d.ts +1 -1
  39. package/cli/src/commands/lib/streaming/suspense.d.ts +1 -1
  40. package/cli/src/commands/lib/terminal-ui.d.ts +1 -1
  41. package/cli/src/commands/lib/theme.d.ts +20 -0
  42. package/cli/src/commands/lib/theme.d.ts.map +1 -0
  43. package/cli/src/commands/lib/version.d.ts +1 -1
  44. package/cli/src/commands/og.d.ts +1 -1
  45. package/cli/src/commands/start.d.ts +1 -1
  46. package/cli/src/index.d.ts +1 -1
  47. package/core/index.d.ts +1 -1
  48. package/core/index.js +16 -16
  49. package/core/index.js.map +6 -6
  50. package/core/src/bundler/hash.d.ts +1 -1
  51. package/core/src/bundler/index.d.ts +1 -1
  52. package/core/src/config.d.ts +1 -1
  53. package/core/src/content/discovery.d.ts +1 -1
  54. package/core/src/content/index.d.ts +1 -1
  55. package/core/src/content/metadata.d.ts +1 -1
  56. package/core/src/i18n/catalog.d.ts +1 -1
  57. package/core/src/i18n/discover.d.ts +1 -1
  58. package/core/src/i18n/index.d.ts +1 -1
  59. package/core/src/i18n/messages.d.ts +1 -1
  60. package/core/src/i18n/negotiate.d.ts +1 -1
  61. package/core/src/i18n/pathname.d.ts +1 -1
  62. package/core/src/i18n/resolve.d.ts +1 -1
  63. package/core/src/i18n/types.d.ts +1 -1
  64. package/core/src/index.d.ts +1 -1
  65. package/core/src/llms/extractor.d.ts +1 -1
  66. package/core/src/llms/formatter.d.ts +1 -1
  67. package/core/src/llms/full-generator.d.ts +1 -1
  68. package/core/src/llms/index-generator.d.ts +1 -1
  69. package/core/src/llms/index.d.ts +1 -1
  70. package/core/src/og/discovery.d.ts +1 -1
  71. package/core/src/og/index.d.ts +1 -1
  72. package/core/src/og/meta.d.ts +1 -1
  73. package/core/src/og/render.d.ts +1 -1
  74. package/core/src/og/types.d.ts +1 -1
  75. package/core/src/robots/discovery.d.ts +1 -1
  76. package/core/src/robots/generator.d.ts +1 -1
  77. package/core/src/robots/index.d.ts +1 -1
  78. package/core/src/robots/policies.d.ts +1 -1
  79. package/core/src/rss/discovery.d.ts +1 -1
  80. package/core/src/rss/generator.d.ts +1 -1
  81. package/core/src/rss/index.d.ts +1 -1
  82. package/core/src/sitemap/discovery.d.ts +1 -1
  83. package/core/src/sitemap/generator.d.ts +1 -1
  84. package/core/src/sitemap/index.d.ts +1 -1
  85. package/core/src/ssr/index.d.ts +1 -1
  86. package/core/src/ssr/lib/cache.d.ts +1 -1
  87. package/core/src/ssr/lib/cleanup.d.ts +1 -1
  88. package/core/src/ssr/lib/collections.d.ts +1 -1
  89. package/core/src/ssr/lib/compression.d.ts +1 -1
  90. package/core/src/ssr/lib/compute/content.d.ts +1 -1
  91. package/core/src/ssr/lib/compute/index.d.ts +1 -1
  92. package/core/src/ssr/lib/compute/layouts.d.ts +1 -1
  93. package/core/src/ssr/lib/compute/routes.d.ts +1 -1
  94. package/core/src/ssr/lib/content-path.d.ts +1 -1
  95. package/core/src/ssr/lib/data.d.ts +1 -1
  96. package/core/src/ssr/lib/html.d.ts +1 -1
  97. package/core/src/ssr/lib/imports.d.ts +1 -1
  98. package/core/src/ssr/lib/index.d.ts +1 -1
  99. package/core/src/ssr/lib/layouts.d.ts +1 -1
  100. package/core/src/ssr/lib/metadata.d.ts +1 -1
  101. package/core/src/ssr/lib/mime.d.ts +1 -1
  102. package/core/src/ssr/lib/modules.d.ts +1 -1
  103. package/core/src/ssr/lib/path.d.ts +1 -1
  104. package/core/src/ssr/lib/preload.d.ts +1 -1
  105. package/core/src/ssr/lib/route-match.d.ts +1 -1
  106. package/core/src/ssr/lib/scripts/collections.d.ts +1 -1
  107. package/core/src/ssr/lib/scripts/data.d.ts +1 -1
  108. package/core/src/ssr/lib/scripts/escape.d.ts +1 -1
  109. package/core/src/ssr/lib/scripts/feeds.d.ts +1 -1
  110. package/core/src/ssr/lib/scripts/index.d.ts +1 -1
  111. package/core/src/ssr/lib/seed.d.ts +1 -1
  112. package/core/src/ssr/lib/serialize.d.ts +1 -1
  113. package/core/src/ssr/lib/setup.d.ts +2 -2
  114. package/core/src/ssr/lib/setup.d.ts.map +1 -1
  115. package/core/src/ssr/lib/styles.d.ts +3 -3
  116. package/core/src/ssr/lib/styles.d.ts.map +1 -1
  117. package/core/src/ssr/lib/template.d.ts +1 -1
  118. package/core/src/ssr/lib/types.d.ts +1 -1
  119. package/core/src/ssr/render.d.ts +2 -2
  120. package/core/src/ssr/render.d.ts.map +1 -1
  121. package/core/src/ssr/stream.d.ts +2 -2
  122. package/core/src/ssr/stream.d.ts.map +1 -1
  123. package/elysia/index.d.ts +1 -1
  124. package/elysia/index.js +27 -27
  125. package/elysia/index.js.map +9 -9
  126. package/elysia/src/index.d.ts +1 -1
  127. package/elysia/src/libs/assets.d.ts +1 -1
  128. package/elysia/src/libs/cache.d.ts +1 -1
  129. package/elysia/src/libs/caching.d.ts +1 -1
  130. package/elysia/src/libs/http.d.ts +1 -1
  131. package/elysia/src/libs/i18n.d.ts +1 -1
  132. package/elysia/src/libs/image.d.ts +1 -1
  133. package/elysia/src/libs/index.d.ts +1 -1
  134. package/elysia/src/libs/llms.d.ts +1 -1
  135. package/elysia/src/libs/response.d.ts +1 -1
  136. package/elysia/src/libs/serving.d.ts +1 -1
  137. package/elysia/src/plugin.d.ts +1 -1
  138. package/elysia/src/routes/artifacts.d.ts +1 -1
  139. package/elysia/src/routes/content.d.ts +1 -1
  140. package/elysia/src/routes/image.d.ts +1 -1
  141. package/elysia/src/routes/index.d.ts +1 -1
  142. package/elysia/src/routes/internal.d.ts +1 -1
  143. package/elysia/src/routes/llms.d.ts +1 -1
  144. package/elysia/src/routes/og.d.ts +1 -1
  145. package/elysia/src/routes/redirects.d.ts +1 -1
  146. package/elysia/src/routes/robots.d.ts +1 -1
  147. package/elysia/src/routes/rss.d.ts +1 -1
  148. package/elysia/src/routes/search.d.ts +1 -1
  149. package/elysia/src/routes/sitemap.d.ts +1 -1
  150. package/elysia/src/routes/ssr.d.ts +2 -2
  151. package/elysia/src/routes/ssr.d.ts.map +1 -1
  152. package/elysia/src/routes/static.d.ts +1 -1
  153. package/elysia/src/types.d.ts +1 -1
  154. package/package.json +2 -5
  155. package/react/index.d.ts +1 -1
  156. package/react/index.js +2 -2
  157. package/react/index.js.map +1 -1
  158. package/react/src/components/ClientOnly.d.ts +1 -1
  159. package/react/src/components/ContentRoute.d.ts +1 -1
  160. package/react/src/components/Image.d.ts +1 -1
  161. package/react/src/components/LazyRoute.d.ts +1 -1
  162. package/react/src/components/Link.d.ts +1 -1
  163. package/react/src/components/Markdown.d.ts +1 -1
  164. package/react/src/components/Outlet.d.ts +1 -1
  165. package/react/src/components/index.d.ts +1 -1
  166. package/react/src/hooks/index.d.ts +1 -1
  167. package/react/src/hooks/useContent.d.ts +1 -1
  168. package/react/src/hooks/useData.d.ts +1 -1
  169. package/react/src/hooks/useFeed.d.ts +1 -1
  170. package/react/src/hooks/useLayoutData.d.ts +1 -1
  171. package/react/src/hooks/useLlms.d.ts +1 -1
  172. package/react/src/hooks/useNavigate.d.ts +1 -1
  173. package/react/src/hooks/useParams.d.ts +1 -1
  174. package/react/src/hooks/useRouter.d.ts +1 -1
  175. package/react/src/hooks/useSearch.d.ts +1 -1
  176. package/react/src/hooks/useSearchParams.d.ts +1 -1
  177. package/react/src/hooks/useToc.d.ts +1 -1
  178. package/react/src/i18n/LocaleProvider.d.ts +1 -1
  179. package/react/src/i18n/helpers.d.ts +1 -1
  180. package/react/src/i18n/index.d.ts +1 -1
  181. package/react/src/index.d.ts +1 -1
  182. package/react/src/lib/collection.d.ts +1 -1
  183. package/react/src/lib/content.d.ts +1 -1
  184. package/react/src/lib/head.d.ts +1 -1
  185. package/react/src/lib/index.d.ts +1 -1
  186. package/react/src/lib/lazy-route.d.ts +1 -1
  187. package/react/src/lib/route-loader.d.ts +1 -1
  188. package/react/src/providers/ContentProvider.d.ts +1 -1
  189. package/react/src/providers/RerouteProvider.d.ts +1 -1
  190. package/react/src/providers/RouterProvider.d.ts +1 -1
  191. package/react/src/providers/index.d.ts +1 -1
  192. package/react/src/types/any.d.ts +1 -1
  193. package/react/src/types/index.d.ts +1 -1
  194. package/react/src/types/router.d.ts +1 -1
  195. package/telemetry/react.d.ts +1 -1
  196. package/telemetry/react.js +2 -2
  197. package/telemetry/react.js.map +1 -1
  198. package/telemetry/server.d.ts +1 -1
  199. package/telemetry/server.js +2 -2
  200. package/telemetry/server.js.map +4 -4
  201. package/telemetry/src/react/api.d.ts +1 -1
  202. package/telemetry/src/react/context.d.ts +1 -1
  203. package/telemetry/src/react/index.d.ts +1 -1
  204. package/telemetry/src/react/telemetry.d.ts +1 -1
  205. package/telemetry/src/server/context.d.ts +1 -1
  206. package/telemetry/src/server/headers/extractor.d.ts +1 -1
  207. package/telemetry/src/server/headers/index.d.ts +1 -1
  208. package/telemetry/src/server/headers/presets.d.ts +1 -1
  209. package/telemetry/src/server/index.d.ts +1 -1
  210. package/telemetry/src/server/instrumentation.d.ts +1 -1
  211. package/telemetry/src/server/plugin.d.ts +1 -1
  212. package/telemetry/src/server/sourcemap.d.ts +1 -1
  213. package/_/store/src/client/theme.css +0 -306
  214. package/cli/src/commands/lib/tailwind.d.ts +0 -20
  215. package/cli/src/commands/lib/tailwind.d.ts.map +0 -1
@@ -27,9 +27,9 @@
27
27
  "import { readdir, stat } from 'node:fs/promises';\nimport { dynamicImport } from './imports';\nimport { join } from './path';\nimport type { Doc, PreloadResult } from './types';\n\n/**\n * Handle content module preloading for content pages\n */\nexport async function preloadContentModule(\n\tpathname: string,\n\tclientDir: string,\n\tcwd: string,\n\tisWatchMode: boolean,\n): Promise<PreloadResult> {\n\tlet extraHead = '';\n\tlet hydrationScript = '';\n\tlet statusOverride: number | undefined;\n\n\ttry {\n\t\tconst { resolveContentPathParts } = await import('./content-path');\n\t\tconst resolved = resolveContentPathParts(pathname);\n\n\t\tif (!resolved) {\n\t\t\treturn { extraHead, hydrationScript };\n\t\t}\n\n\t\tconst { collection, name, key, locale } = resolved;\n\n\t\t// Check if this is a content collection\n\t\tif (!(await isContentCollection(clientDir, collection))) {\n\t\t\treturn { extraHead, hydrationScript };\n\t\t}\n\n\t\t// Try to find module path\n\t\tconst modulePath = await findContentModulePath(\n\t\t\tcollection,\n\t\t\tname,\n\t\t\tclientDir,\n\t\t\tcwd,\n\t\t\tisWatchMode,\n\t\t\tlocale,\n\t\t);\n\n\t\tif (!modulePath) {\n\t\t\tstatusOverride = 404;\n\t\t\treturn { extraHead, hydrationScript, statusOverride };\n\t\t}\n\t\textraHead += `\\n<link rel=\"modulepreload\" href=\"${modulePath}\" />`;\n\n\t\t// Store the module path and key for the inline loader\n\t\t// The actual loading happens via a blocking mechanism in the data script\n\t\t// Mark that this content module needs to be preloaded in the hydration script\n\t\thydrationScript += `<script>\n(globalThis.__REROUTE_CONTENT_PRELOAD__ ||= []).push({src:'${modulePath}',key:'${key}'});\n</script>`;\n\t} catch {\n\t\t// Return empty result on error\n\t}\n\n\treturn { extraHead, hydrationScript, statusOverride };\n}\n\nasync function isContentCollection(\n\tclientDir: string,\n\tcollection: string,\n): Promise<boolean> {\n\ttry {\n\t\t// In production (clientDir = .reroute), check for collection files instead of source dirs\n\t\tconst isProduction = clientDir.endsWith('.reroute');\n\n\t\tif (isProduction) {\n\t\t\t// Check if collection file exists in .reroute/collections/\n\t\t\tconst collectionFile = join(clientDir, 'collections', `${collection}.js`);\n\t\t\ttry {\n\t\t\t\tconst s = await stat(collectionFile);\n\t\t\t\treturn s?.isFile() ?? false;\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\t// In development, check for content directory\n\t\tconst maybeDir = join(clientDir, 'routes', collection, 'content');\n\t\tconst s = await stat(maybeDir);\n\t\treturn typeof s?.isDirectory === 'function' ? s.isDirectory() : true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function findLatestCandidate(\n\tchunkDir: string,\n\tcandidates: string[],\n): Promise<string> {\n\tlet latest = candidates[0];\n\tlet latestM = 0;\n\n\tfor (const candidateName of candidates) {\n\t\ttry {\n\t\t\tconst s = await stat(join(chunkDir, candidateName));\n\t\t\tif (s.mtimeMs >= latestM) {\n\t\t\t\tlatestM = s.mtimeMs;\n\t\t\t\tlatest = candidateName;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Skip inaccessible files\n\t\t}\n\t}\n\n\treturn latest;\n}\n\nasync function findContentModulePath(\n\tcollection: string,\n\tname: string,\n\tclientDir: string,\n\tcwd: string,\n\tisWatchMode: boolean,\n\tlocale?: string,\n): Promise<string | null> {\n\t// 1. Try registry mapping\n\ttry {\n\t\tconst registryPath = join(cwd, '.reroute', 'content.ts');\n\t\tconst reg = await dynamicImport(registryPath, isWatchMode);\n\t\tconst get = reg?.getContentEntry as\n\t\t\t| ((c: string, n: string, l?: string) => { module?: string } | undefined)\n\t\t\t| undefined;\n\t\tconst entry =\n\t\t\ttypeof get === 'function' ? get(collection, name, locale) : undefined;\n\t\tconst moduleUrl = (entry as Doc)?.module as string | undefined;\n\n\t\tif (moduleUrl?.endsWith('.js')) {\n\t\t\treturn moduleUrl;\n\t\t}\n\t} catch {\n\t\t// Registry unavailable\n\t}\n\n\t// 2. Try newest chunk\n\ttry {\n\t\tconst chunkDir = join(cwd, '.reroute', 'chunks', collection);\n\t\tconst files = await readdir(chunkDir);\n\t\tconst candidates = files.filter(\n\t\t\t(n) => n.startsWith(`${name}.`) && n.endsWith('.js'),\n\t\t);\n\n\t\tif (candidates.length) {\n\t\t\tconst latest = await findLatestCandidate(chunkDir, candidates);\n\t\t\treturn `/${join('.reroute', 'chunks', collection, latest).replace(/\\\\+/g, '/')}`;\n\t\t}\n\t} catch {\n\t\t// Chunk directory unavailable\n\t}\n\n\t// 3. Try source files (locale subdir first when present)\n\ttry {\n\t\tconst contentRoot = join(clientDir, 'routes', collection, 'content');\n\t\tconst candidates = locale\n\t\t\t? [\n\t\t\t\t\tjoin(contentRoot, locale, `${name}.tsx`),\n\t\t\t\t\tjoin(contentRoot, locale, `${name}.ts`),\n\t\t\t\t\tjoin(contentRoot, `${name}.tsx`),\n\t\t\t\t\tjoin(contentRoot, `${name}.ts`),\n\t\t\t\t]\n\t\t\t: [join(contentRoot, `${name}.tsx`), join(contentRoot, `${name}.ts`)];\n\n\t\tfor (const abs of candidates) {\n\t\t\tif (await Bun.file(abs).exists()) {\n\t\t\t\tconst rel = abs.startsWith(clientDir)\n\t\t\t\t\t? abs.slice(clientDir.length).replace(/^[/\\\\]/, '')\n\t\t\t\t\t: join('routes', collection, 'content', `${name}.tsx`);\n\t\t\t\treturn `/${rel.replace(/\\\\+/g, '/')}`;\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Source files unavailable\n\t}\n\n\treturn null;\n}\n\n/**\n * Reset SSR access tracking for a new request\n */\nexport function resetSSRAccessTracking(): void {\n\ttry {\n\t\t(globalThis as Doc).__REROUTE_SSR_ACCESSED__ = {};\n\t} catch {\n\t\t// Ignore errors in restricted environments\n\t}\n}\n\n/**\n * Create bundle preload link\n */\nexport function createBundlePreload(bundleUrl: string): string {\n\ttry {\n\t\tif (typeof bundleUrl === 'string' && bundleUrl.endsWith('.js')) {\n\t\t\treturn `\\n<link rel=\"modulepreload\" href=\"${bundleUrl}\" />`;\n\t\t}\n\t} catch {\n\t\t// Return empty on error\n\t}\n\treturn '';\n}\n",
28
28
  "import { resolveContentPathParts } from '../content-path';\nimport { escapeJsonForScript } from './escape';\n\n/**\n * Duplicate SSR data for query param routes.\n * Stores at both /path?query and /path so useData() can find it.\n */\nexport function duplicateQueryParamData(\n\tssrData: Record<string, unknown>,\n): Record<string, unknown> {\n\tconst duplicated: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(ssrData)) {\n\t\tduplicated[key] = value;\n\t\tconst pathnameOnly = key.split('?')[0];\n\t\tif (pathnameOnly !== key) {\n\t\t\tduplicated[pathnameOnly] = value;\n\t\t}\n\t}\n\treturn duplicated;\n}\n\n/**\n * Get the content key from a pathname (e.g., /blog/my-post -> blog:my-post,\n * /blog/pt-BR/my-post -> blog:my-post:pt-BR)\n */\nfunction getContentKeyFromPathname(pathname: string): string | null {\n\treturn resolveContentPathParts(pathname)?.key ?? null;\n}\n\n/**\n * Create inline script for i18n hydration.\n */\nfunction createI18nScript(i18n?: Record<string, unknown>): string {\n\tif (!i18n?.enabled) return '';\n\ttry {\n\t\tconst json = escapeJsonForScript(JSON.stringify(i18n));\n\t\treturn `<script>(function(){try{var w=(typeof window!=='undefined'?window:globalThis);w.__REROUTE_I18N__=${json};}catch(e){}})();</script>`;\n\t} catch (error) {\n\t\tconsole.error('[reroute] Failed to serialize i18n hydration:', error);\n\t\treturn '';\n\t}\n}\n\n/**\n * Create inline script that captures DOM content HTML BEFORE React hydrates.\n * This eliminates the need to duplicate HTML in the response - we just read it from the DOM.\n * Must be placed BEFORE the React bundle script.\n *\n * Also sets __REROUTE_INITIAL_HYDRATION__ flag to true so components know this is\n * the first render and should not replace SSR'd content.\n */\nexport function createContentCaptureScript(): string {\n\t// This script:\n\t// 1. Sets initial hydration flag so components know not to replace content\n\t// 2. Finds all [data-reroute-key] elements and captures their innerHTML\n\t// into __REROUTE_CONTENT_HTML__ before React runs and potentially modifies them\n\t// 3. Finds the [data-reroute-route=\"ssr\"] element and captures its innerHTML\n\t// into __REROUTE_ROUTE_HTML__ for LazyRoute hydration\n\treturn `<script>(function(){try{var w=window;w.__REROUTE_INITIAL_HYDRATION__=true;var h={};document.querySelectorAll('[data-reroute-key]').forEach(function(el){var k=el.getAttribute('data-reroute-key');if(k)h[k]=el.innerHTML;});w.__REROUTE_CONTENT_HTML__=h;var r=document.querySelector('[data-reroute-route=\"ssr\"]');if(r)w.__REROUTE_ROUTE_HTML__=r.innerHTML;}catch(e){}})();</script>`;\n}\n\n/**\n * Create inline script for SSR exports hydration (includes toc, meta, etc.)\n * This ensures hooks like useToc have access to server-side data during hydration\n * Only includes data for the current pathname to avoid cross-request pollution\n */\nexport function createSSRExportsScript(pathname: string): string {\n\ttry {\n\t\t// biome-ignore lint/suspicious/noExplicitAny: dynamic global access\n\t\tconst g = globalThis as any;\n\t\tconst ssrExports = g.__REROUTE_SSR_EXPORTS__;\n\n\t\tif (!ssrExports || typeof ssrExports !== 'object') {\n\t\t\treturn '';\n\t\t}\n\n\t\t// Only serialize the current page's exports, not all accumulated exports\n\t\tconst currentKey = getContentKeyFromPathname(pathname);\n\t\tif (!currentKey) {\n\t\t\treturn '';\n\t\t}\n\n\t\tconst currentExports = ssrExports[currentKey];\n\t\tif (!currentExports) {\n\t\t\treturn '';\n\t\t}\n\n\t\tconst filteredExports = { [currentKey]: currentExports };\n\t\tconst exportsJson = escapeJsonForScript(JSON.stringify(filteredExports));\n\n\t\treturn `<script>(function(){try{var w=(typeof window!=='undefined'?window:globalThis);w.__REROUTE_SSR_EXPORTS__=${exportsJson};}catch(e){}})();</script>`;\n\t} catch (error) {\n\t\tconsole.error('[reroute] Failed to create SSR exports script:', error);\n\t\treturn '';\n\t}\n}\n\n/**\n * Create inline script for browser telemetry config hydration\n * Injects telemetry.browser config so TelemetryProvider can use it\n */\nfunction createTelemetryConfigScript(\n\tbrowserTelemetryConfig?: Record<string, unknown>,\n): string {\n\tif (\n\t\t!browserTelemetryConfig ||\n\t\tObject.keys(browserTelemetryConfig).length === 0\n\t) {\n\t\treturn '';\n\t}\n\n\ttry {\n\t\tconst configJson = escapeJsonForScript(\n\t\t\tJSON.stringify(browserTelemetryConfig),\n\t\t);\n\t\treturn `<script>(function(){try{var w=(typeof window!=='undefined'?window:globalThis);w.__REROUTE_TELEMETRY_BROWSER__=${configJson};}catch(e){}})();</script>`;\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t'[reroute] Failed to serialize browser telemetry config:',\n\t\t\terror,\n\t\t);\n\t\treturn '';\n\t}\n}\n\n/**\n * Create inline script for trace context injection\n * Injects W3C Trace Context so browser spans can link to server spans\n */\nfunction createTraceContextScript(traceContext?: {\n\ttraceparent?: string;\n\ttracestate?: string;\n}): string {\n\tif (\n\t\t!traceContext?.traceparent ||\n\t\ttypeof traceContext.traceparent !== 'string'\n\t) {\n\t\treturn '';\n\t}\n\n\ttry {\n\t\tconst contextJson = escapeJsonForScript(JSON.stringify(traceContext));\n\t\treturn `<script>(function(){try{var w=(typeof window!=='undefined'?window:globalThis);w.__REROUTE_TRACE_CONTEXT__=${contextJson};}catch(e){}})();</script>`;\n\t} catch (error) {\n\t\tconsole.error('[reroute] Failed to serialize trace context:', error);\n\t\treturn '';\n\t}\n}\n\n/**\n * Create inline script for title suffix hydration\n * Injects titleSuffix so client-side navigation maintains the suffix\n */\nfunction createTitleSuffixScript(titleSuffix?: string): string {\n\tif (!titleSuffix) {\n\t\treturn '';\n\t}\n\n\ttry {\n\t\tconst suffixJson = escapeJsonForScript(JSON.stringify(titleSuffix));\n\t\treturn `<script>(function(){try{var w=(typeof window!=='undefined'?window:globalThis);w.__REROUTE_TITLE_SUFFIX__=${suffixJson};}catch(e){}})();</script>`;\n\t} catch (error) {\n\t\tconsole.error('[reroute] Failed to serialize title suffix:', error);\n\t\treturn '';\n\t}\n}\n\n/**\n * Create inline script for SSR pathname hydration\n * Tells the client which pathname was SSR'd so components can skip re-rendering\n * on the initial hydration pass.\n */\nfunction createSSRPathnameScript(pathname?: string): string {\n\tif (!pathname) {\n\t\treturn '';\n\t}\n\n\ttry {\n\t\tconst pathnameJson = escapeJsonForScript(JSON.stringify(pathname));\n\t\treturn `<script>(function(){try{var w=(typeof window!=='undefined'?window:globalThis);w.__REROUTE_SSR_PATHNAME__=${pathnameJson};}catch(e){}})();</script>`;\n\t} catch (error) {\n\t\tconsole.error('[reroute] Failed to serialize SSR pathname:', error);\n\t\treturn '';\n\t}\n}\n\n/**\n * Create inline script for SSR data hydration\n */\nexport function createDataScript(\n\tssrData: Record<string, unknown>,\n\terrorMsg?: string,\n\tpathname?: string,\n\tbrowserTelemetryConfig?: Record<string, unknown>,\n\ttraceContext?: { traceparent?: string; tracestate?: string },\n\ttitleSuffix?: string,\n\ti18n?: Record<string, unknown>,\n): string {\n\tlet script = '';\n\n\t// Capture DOM content HTML before React hydrates (reads from DOM, no duplication)\n\tscript += createContentCaptureScript();\n\n\t// Add SSR pathname script (tells client which route was SSR'd)\n\tscript += createSSRPathnameScript(pathname);\n\n\t// Add SSR exports script (for useToc, etc.) - scoped to current pathname\n\tif (pathname) {\n\t\tscript += createSSRExportsScript(pathname);\n\t}\n\n\t// Inject i18n hydration (locale + catalogs)\n\tscript += createI18nScript(i18n);\n\n\t// Inject browser telemetry config\n\tscript += createTelemetryConfigScript(browserTelemetryConfig);\n\n\t// Inject trace context for distributed tracing\n\tscript += createTraceContextScript(traceContext);\n\n\t// Inject title suffix for client-side navigation\n\tscript += createTitleSuffixScript(titleSuffix);\n\n\tif (ssrData && Object.keys(ssrData).length > 0) {\n\t\ttry {\n\t\t\tconst duplicatedData = duplicateQueryParamData(ssrData);\n\t\t\tconst dataJson = escapeJsonForScript(JSON.stringify(duplicatedData));\n\t\t\tconst keysJson = escapeJsonForScript(\n\t\t\t\tJSON.stringify(Object.keys(ssrData)),\n\t\t\t);\n\t\t\tscript += `<script>(function(){try{var w=(typeof window!=='undefined'?window:globalThis);w.__REROUTE_DATA__=Object.assign({},w.__REROUTE_DATA__||{},${dataJson});try{w.dispatchEvent(new CustomEvent('__reroute_data__',{detail:{keys:${keysJson}}}));}catch(e){}}catch(e){}})();</script>`;\n\t\t} catch (error) {\n\t\t\tconsole.error('[reroute] Failed to serialize SSR data:', error);\n\t\t}\n\t}\n\n\tif (errorMsg) {\n\t\tconst escapedMsg = JSON.stringify(errorMsg);\n\t\tscript += `<script>(function(){try{console.warn('%c[reroute] SSR Data Error','background: #ff5555; color: white; padding: 2px 6px; border-radius: 3px;',${escapedMsg});}catch(e){}})();</script>`;\n\t}\n\n\treturn script;\n}\n",
29
29
  "export { createCollectionScript, processCollections } from './collections';\nexport { createDataScript, duplicateQueryParamData } from './data';\nexport { escapeJsonForScript } from './escape';\nexport { createFeedsScript, createLlmsScript } from './feeds';\n",
30
- "import type { Span } from '@opentelemetry/api';\nimport { withParentSpan, withSpan } from 'reroute-js/telemetry/server';\nimport type { OGImageOptions, OGOptions } from '../../config';\nimport { cleanupPathScopedSSRData } from './cleanup';\nimport { loadCollections, setGlobalCollections } from './collections';\nimport { computeSSRData, setGlobalSSRData } from './compute';\nimport { extractPageMetadata } from './metadata';\nimport {\n\tcreateBundlePreload,\n\tpreloadContentModule,\n\tresetSSRAccessTracking,\n} from './preload';\nimport {\n\tcreateCollectionScript,\n\tcreateDataScript,\n\tcreateFeedsScript,\n\tcreateLlmsScript,\n\tprocessCollections,\n} from './scripts';\nimport { seedSSRModuleForPath } from './seed';\nimport { inlineTailwindCSS } from './styles';\nimport type { ComputeResult, SSR } from './types';\n\n/**\n * Common SSR options shared between render and stream modes\n */\ntype SSRSetupOptions = {\n\tpathname: string;\n\tclientDir: string;\n\tcwd: string;\n\tisWatchMode: boolean;\n\tbundleUrl: string;\n\tcachedCollections?: Record<string, unknown[]>;\n\tcachedTailwindCSS?: string;\n\tdebug?: boolean;\n\tmaxAge?: number;\n\tsearchParams?: URLSearchParams;\n\togConfig?: OGImageOptions;\n\togMetaConfig?: OGOptions;\n\tbaseUrl?: string;\n\tautoCanonical?: boolean;\n\tparentSpan?: Span | null;\n\t/** Request headers from the incoming HTTP request */\n\theaders?: Record<string, string>;\n\t/** Suffix to append to all page titles */\n\ttitleSuffix?: string;\n\t/** Maximum timeout in milliseconds for SSR setup */\n\ttimeout?: number;\n};\n\n/**\n * Result of SSR setup phase\n */\ntype SSRSetupResult = {\n\tssrData: Record<string, unknown>;\n\tssrError?: string;\n\tstatusContainer: { value: number | undefined };\n\tbyCollectionForSSR: Record<string, unknown[]>;\n\tbundlePreload: string;\n\tpreloadExtraHead: string;\n\tpreloadHydrationScript: string;\n\tpreloadStatusOverride?: number;\n\tinlineStyleTag: string;\n\tmetadataResult: {\n\t\tperPageHead: string;\n\t\tpageLang?: string;\n\t\tstatusOverride?: number;\n\t\t/** SSR export for dynamic head generation at stream end */\n\t\tssrExport?: SSR;\n\t};\n\tpending?: Promise<void>;\n};\n\ntype SSRSetupTimeoutState = {\n\ttimedOut: boolean;\n};\n\n/**\n * Perform common SSR setup steps shared between render and stream modes.\n * This includes seeding modules, computing data, loading collections, and preloading.\n */\nasync function performSSRSetup(\n\toptions: SSRSetupOptions,\n\tstreaming = false,\n): Promise<SSRSetupResult> {\n\tconst { pathname } = options;\n\tconst timeoutState: SSRSetupTimeoutState = { timedOut: false };\n\n\t// Add a global timeout for SSR setup to prevent indefinite hangs.\n\t// Consumer-provided timeout takes precedence.\n\tconst setupTimeout = options.timeout ?? (streaming ? 10000 : 30000);\n\tlet timeoutId: ReturnType<typeof setTimeout> | null = null;\n\tconst timeoutPromise = new Promise<never>((_, reject) => {\n\t\ttimeoutId = setTimeout(() => {\n\t\t\ttimeoutState.timedOut = true;\n\t\t\treject(\n\t\t\t\tnew Error(\n\t\t\t\t\t`[reroute] SSR setup timeout after ${setupTimeout}ms for ${pathname}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}, setupTimeout);\n\t});\n\tconst setupPromise = withParentSpan(options.parentSpan, () =>\n\t\tperformSSRSetupInternal(options, streaming, timeoutState),\n\t);\n\tconst setupPromiseWithCleanup = setupPromise.finally(() => {\n\t\tif (timeoutState.timedOut) {\n\t\t\tcleanupPathScopedSSRData(pathname);\n\t\t}\n\t});\n\n\ttry {\n\t\treturn await Promise.race([setupPromiseWithCleanup, timeoutPromise]);\n\t} catch (error) {\n\t\tcleanupPathScopedSSRData(pathname);\n\t\tconsole.error('[reroute] SSR setup error:', error);\n\t\t// Return minimal setup result to allow page to render with fallback\n\t\treturn {\n\t\t\tssrData: {},\n\t\t\tssrError: error instanceof Error ? error.message : String(error),\n\t\t\tstatusContainer: { value: 500 },\n\t\t\tbyCollectionForSSR: {},\n\t\t\tbundlePreload: '',\n\t\t\tpreloadExtraHead: '',\n\t\t\tpreloadHydrationScript: '',\n\t\t\tinlineStyleTag: '',\n\t\t\tmetadataResult: { perPageHead: '' },\n\t\t};\n\t} finally {\n\t\tif (timeoutId) {\n\t\t\tclearTimeout(timeoutId);\n\t\t}\n\t}\n}\n\n/**\n * Internal SSR setup implementation (wrapped with timeout above)\n */\nasync function performSSRSetupInternal(\n\toptions: SSRSetupOptions,\n\tstreaming: boolean,\n\ttimeoutState: SSRSetupTimeoutState,\n): Promise<SSRSetupResult> {\n\tconst debug = options.debug ?? false;\n\tconst t0 = debug ? performance.now() : 0;\n\tconst {\n\t\tpathname,\n\t\tclientDir,\n\t\tcwd,\n\t\tisWatchMode,\n\t\tbundleUrl,\n\t\tmaxAge = 0,\n\t\tsearchParams,\n\t\togConfig,\n\t} = options;\n\tconst assertNotTimedOut = () => {\n\t\tif (timeoutState.timedOut) {\n\t\t\tthrow new Error(`[reroute] SSR setup cancelled for ${pathname}`);\n\t\t}\n\t};\n\n\t// Note: We don't reset SSR globals here because multiple requests may run concurrently.\n\t// Instead, we use pathname-scoped serialization to ensure each response only includes\n\t// its own data (see createContentHtmlScript and createSSRExportsScript).\n\n\t// 1. Seed content modules for SSR rendering\n\tawait withSpan('ssr.seed', async (span) => {\n\t\tspan.setAttribute('pathname', pathname);\n\t\tspan.setAttribute('streaming', streaming);\n\t\tawait seedSSRModuleForPath(pathname, clientDir, cwd, isWatchMode);\n\t\tif (debug)\n\t\t\tconsole.log(\n\t\t\t\t`[Setup] ${pathname} - seedModule: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t);\n\t});\n\tassertNotTimedOut();\n\n\t// 2. Reset SSR access tracking and create bundle preload\n\tresetSSRAccessTracking();\n\tconst bundlePreload = createBundlePreload(bundleUrl);\n\n\t// 3. Preload content module\n\tconst preloadResult = await withSpan('ssr.preload', async (span) => {\n\t\tspan.setAttribute('pathname', pathname);\n\t\tconst result = await preloadContentModule(\n\t\t\tpathname,\n\t\t\tclientDir,\n\t\t\tcwd,\n\t\t\tisWatchMode,\n\t\t);\n\t\tspan.setAttribute('has_module', !!result.modulePath);\n\t\tif (debug)\n\t\t\tconsole.log(\n\t\t\t\t`[Setup] ${pathname} - preloadContent: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t);\n\t\treturn result;\n\t});\n\tassertNotTimedOut();\n\n\t// 4. Compute SSR data\n\tconst computeResult: ComputeResult = await withSpan(\n\t\t'ssr.compute.data',\n\t\tasync (span) => {\n\t\t\tspan.setAttribute('pathname', pathname);\n\t\t\tspan.setAttribute('streaming', streaming);\n\t\t\tconst result = await computeSSRData(\n\t\t\t\tpathname,\n\t\t\t\tclientDir,\n\t\t\t\tcwd,\n\t\t\t\tisWatchMode,\n\t\t\t\t{ streaming, maxAge, headers: options.headers },\n\t\t\t\tsearchParams,\n\t\t\t);\n\t\t\tspan.setAttribute('has_error', !!result.error);\n\t\t\tspan.setAttribute('has_data', Object.keys(result.data).length > 0);\n\t\t\tif (debug)\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[Setup] ${pathname} - computeSSRData: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t\t);\n\t\t\treturn result;\n\t\t},\n\t);\n\tassertNotTimedOut();\n\n\tsetGlobalSSRData(computeResult.data);\n\n\t// 5. Load content collections (use cached if available)\n\tconst usingCachedCollections = !!options.cachedCollections;\n\tconst byCollectionForSSR = await withSpan(\n\t\t'ssr.load.collections',\n\t\tasync (span) => {\n\t\t\tspan.setAttribute('pathname', pathname);\n\t\t\tspan.setAttribute('cached', usingCachedCollections);\n\t\t\tconst collections = options.cachedCollections\n\t\t\t\t? options.cachedCollections\n\t\t\t\t: await loadCollections(cwd, isWatchMode);\n\t\t\tspan.setAttribute('collection_count', Object.keys(collections).length);\n\t\t\tif (debug)\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[Setup] ${pathname} - loadCollections (cached: ${usingCachedCollections}): ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t\t);\n\t\t\treturn collections;\n\t\t},\n\t);\n\tassertNotTimedOut();\n\tsetGlobalCollections(byCollectionForSSR);\n\n\t// 6. Inline Tailwind CSS (use cached if available)\n\tconst usingCachedCSS = !!options.cachedTailwindCSS;\n\tconst inlineStyleTag = await withSpan('ssr.inline.css', async (span) => {\n\t\tconst css = options.cachedTailwindCSS\n\t\t\t? options.cachedTailwindCSS\n\t\t\t: await inlineTailwindCSS(clientDir, !streaming, isWatchMode);\n\t\tspan.setAttributes({\n\t\t\t'reroute.cached': usingCachedCSS,\n\t\t\t'reroute.css.size': css.length,\n\t\t});\n\t\tif (debug)\n\t\t\tconsole.log(\n\t\t\t\t`[Setup] ${pathname} - inlineTailwindCSS (cached: ${usingCachedCSS}): ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t);\n\t\treturn css;\n\t});\n\tassertNotTimedOut();\n\n\t// 7. Determine initial status override\n\tlet statusOverride = preloadResult.statusOverride;\n\tif (computeResult.statusContainer.value !== undefined) {\n\t\tstatusOverride = computeResult.statusContainer.value;\n\t}\n\n\t// 8. Extract page metadata (with SSR data for dynamic head tags)\n\tconst metadataResult = await withSpan(\n\t\t'ssr.extract.metadata',\n\t\tasync (span) => {\n\t\t\tconst result = await extractPageMetadata(\n\t\t\t\tpathname,\n\t\t\t\tclientDir,\n\t\t\t\tcwd,\n\t\t\t\tisWatchMode,\n\t\t\t\tstatusOverride,\n\t\t\t\togConfig,\n\t\t\t\toptions.ogMetaConfig,\n\t\t\t\toptions.baseUrl,\n\t\t\t\toptions.autoCanonical,\n\t\t\t\tcomputeResult.data,\n\t\t\t\toptions.titleSuffix,\n\t\t\t);\n\t\t\tspan.setAttributes({\n\t\t\t\t'reroute.pathname': pathname,\n\t\t\t\t'reroute.metadata.exists': !!result.perPageHead,\n\t\t\t});\n\t\t\tif (debug)\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[Setup] ${pathname} - extractMetadata: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t\t);\n\t\t\treturn result;\n\t\t},\n\t);\n\tassertNotTimedOut();\n\n\treturn {\n\t\tssrData: computeResult.data,\n\t\tssrError: computeResult.error,\n\t\tstatusContainer: computeResult.statusContainer,\n\t\tbyCollectionForSSR,\n\t\tbundlePreload,\n\t\tpreloadExtraHead: preloadResult.extraHead,\n\t\tpreloadHydrationScript: preloadResult.hydrationScript,\n\t\tpreloadStatusOverride: preloadResult.statusOverride,\n\t\tinlineStyleTag,\n\t\tmetadataResult,\n\t\tpending: computeResult.pending,\n\t};\n}\n\n/**\n * Generate hydration scripts for collections that were accessed during SSR.\n */\nfunction generateCollectionScripts(\n\tbyCollectionForSSR: Record<string, unknown[]>,\n): string {\n\ttry {\n\t\tconst g = globalThis as unknown as { __REROUTE_SSR_ACCESSED__?: unknown };\n\t\tconst acc = g.__REROUTE_SSR_ACCESSED__;\n\n\t\tif (acc) {\n\t\t\tconst { subset, partial } = processCollections(acc, byCollectionForSSR);\n\t\t\tif (Object.keys(subset).length > 0) {\n\t\t\t\treturn createCollectionScript(subset, partial);\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Ignore errors\n\t}\n\treturn '';\n}\n\n/**\n * Generate all hydration scripts for SSR\n */\nfunction generateHydrationScripts(\n\tssrData: Record<string, unknown>,\n\tisWatchMode: boolean,\n\tssrError?: string,\n\tcollectionScripts = '',\n\tpreloadScript = '',\n\tbundleUrl = '',\n\tpathname = '',\n\tbrowserTelemetryConfig?: Record<string, unknown>,\n\ttraceContext?: { traceparent?: string; tracestate?: string },\n\ttitleSuffix?: string,\n\ti18n?: Record<string, unknown>,\n): string {\n\tlet scripts = preloadScript;\n\n\t// Add collection scripts\n\tscripts += collectionScripts;\n\n\t// Add SSR data script (pathname is used to scope content HTML and exports to current request)\n\tscripts += createDataScript(\n\t\tssrData,\n\t\tisWatchMode ? ssrError : undefined,\n\t\tpathname,\n\t\tbrowserTelemetryConfig,\n\t\ttraceContext,\n\t\ttitleSuffix,\n\t\ti18n,\n\t);\n\n\t// Add feeds and llms scripts\n\tscripts += createFeedsScript();\n\tscripts += createLlmsScript();\n\n\t// Add bundle script\n\tif (bundleUrl) {\n\t\tscripts += `<script type=\"module\" src=\"${bundleUrl}\"></script>`;\n\t}\n\n\t// Add dev watcher in watch mode\n\tif (isWatchMode) {\n\t\tscripts += `<script type=\"module\" src=\"/__reroute_watch.js\"></script>`;\n\t}\n\n\treturn scripts;\n}\n\nexport type { SSRSetupOptions, SSRSetupResult };\nexport { performSSRSetup, generateCollectionScripts, generateHydrationScripts };\n",
30
+ "import type { Span } from '@opentelemetry/api';\nimport { withParentSpan, withSpan } from 'reroute-js/telemetry/server';\nimport type { OGImageOptions, OGOptions } from '../../config';\nimport { cleanupPathScopedSSRData } from './cleanup';\nimport { loadCollections, setGlobalCollections } from './collections';\nimport { computeSSRData, setGlobalSSRData } from './compute';\nimport { extractPageMetadata } from './metadata';\nimport {\n\tcreateBundlePreload,\n\tpreloadContentModule,\n\tresetSSRAccessTracking,\n} from './preload';\nimport {\n\tcreateCollectionScript,\n\tcreateDataScript,\n\tcreateFeedsScript,\n\tcreateLlmsScript,\n\tprocessCollections,\n} from './scripts';\nimport { seedSSRModuleForPath } from './seed';\nimport { inlineThemeCSS } from './styles';\nimport type { ComputeResult, SSR } from './types';\n\n/**\n * Common SSR options shared between render and stream modes\n */\ntype SSRSetupOptions = {\n\tpathname: string;\n\tclientDir: string;\n\tcwd: string;\n\tisWatchMode: boolean;\n\tbundleUrl: string;\n\tcachedCollections?: Record<string, unknown[]>;\n\tcachedThemeCSS?: string;\n\tdebug?: boolean;\n\tmaxAge?: number;\n\tsearchParams?: URLSearchParams;\n\togConfig?: OGImageOptions;\n\togMetaConfig?: OGOptions;\n\tbaseUrl?: string;\n\tautoCanonical?: boolean;\n\tparentSpan?: Span | null;\n\t/** Request headers from the incoming HTTP request */\n\theaders?: Record<string, string>;\n\t/** Suffix to append to all page titles */\n\ttitleSuffix?: string;\n\t/** Maximum timeout in milliseconds for SSR setup */\n\ttimeout?: number;\n};\n\n/**\n * Result of SSR setup phase\n */\ntype SSRSetupResult = {\n\tssrData: Record<string, unknown>;\n\tssrError?: string;\n\tstatusContainer: { value: number | undefined };\n\tbyCollectionForSSR: Record<string, unknown[]>;\n\tbundlePreload: string;\n\tpreloadExtraHead: string;\n\tpreloadHydrationScript: string;\n\tpreloadStatusOverride?: number;\n\tinlineStyleTag: string;\n\tmetadataResult: {\n\t\tperPageHead: string;\n\t\tpageLang?: string;\n\t\tstatusOverride?: number;\n\t\t/** SSR export for dynamic head generation at stream end */\n\t\tssrExport?: SSR;\n\t};\n\tpending?: Promise<void>;\n};\n\ntype SSRSetupTimeoutState = {\n\ttimedOut: boolean;\n};\n\n/**\n * Perform common SSR setup steps shared between render and stream modes.\n * This includes seeding modules, computing data, loading collections, and preloading.\n */\nasync function performSSRSetup(\n\toptions: SSRSetupOptions,\n\tstreaming = false,\n): Promise<SSRSetupResult> {\n\tconst { pathname } = options;\n\tconst timeoutState: SSRSetupTimeoutState = { timedOut: false };\n\n\t// Add a global timeout for SSR setup to prevent indefinite hangs.\n\t// Consumer-provided timeout takes precedence.\n\tconst setupTimeout = options.timeout ?? (streaming ? 10000 : 30000);\n\tlet timeoutId: ReturnType<typeof setTimeout> | null = null;\n\tconst timeoutPromise = new Promise<never>((_, reject) => {\n\t\ttimeoutId = setTimeout(() => {\n\t\t\ttimeoutState.timedOut = true;\n\t\t\treject(\n\t\t\t\tnew Error(\n\t\t\t\t\t`[reroute] SSR setup timeout after ${setupTimeout}ms for ${pathname}`,\n\t\t\t\t),\n\t\t\t);\n\t\t}, setupTimeout);\n\t});\n\tconst setupPromise = withParentSpan(options.parentSpan, () =>\n\t\tperformSSRSetupInternal(options, streaming, timeoutState),\n\t);\n\tconst setupPromiseWithCleanup = setupPromise.finally(() => {\n\t\tif (timeoutState.timedOut) {\n\t\t\tcleanupPathScopedSSRData(pathname);\n\t\t}\n\t});\n\n\ttry {\n\t\treturn await Promise.race([setupPromiseWithCleanup, timeoutPromise]);\n\t} catch (error) {\n\t\tcleanupPathScopedSSRData(pathname);\n\t\tconsole.error('[reroute] SSR setup error:', error);\n\t\t// Return minimal setup result to allow page to render with fallback\n\t\treturn {\n\t\t\tssrData: {},\n\t\t\tssrError: error instanceof Error ? error.message : String(error),\n\t\t\tstatusContainer: { value: 500 },\n\t\t\tbyCollectionForSSR: {},\n\t\t\tbundlePreload: '',\n\t\t\tpreloadExtraHead: '',\n\t\t\tpreloadHydrationScript: '',\n\t\t\tinlineStyleTag: '',\n\t\t\tmetadataResult: { perPageHead: '' },\n\t\t};\n\t} finally {\n\t\tif (timeoutId) {\n\t\t\tclearTimeout(timeoutId);\n\t\t}\n\t}\n}\n\n/**\n * Internal SSR setup implementation (wrapped with timeout above)\n */\nasync function performSSRSetupInternal(\n\toptions: SSRSetupOptions,\n\tstreaming: boolean,\n\ttimeoutState: SSRSetupTimeoutState,\n): Promise<SSRSetupResult> {\n\tconst debug = options.debug ?? false;\n\tconst t0 = debug ? performance.now() : 0;\n\tconst {\n\t\tpathname,\n\t\tclientDir,\n\t\tcwd,\n\t\tisWatchMode,\n\t\tbundleUrl,\n\t\tmaxAge = 0,\n\t\tsearchParams,\n\t\togConfig,\n\t} = options;\n\tconst assertNotTimedOut = () => {\n\t\tif (timeoutState.timedOut) {\n\t\t\tthrow new Error(`[reroute] SSR setup cancelled for ${pathname}`);\n\t\t}\n\t};\n\n\t// Note: We don't reset SSR globals here because multiple requests may run concurrently.\n\t// Instead, we use pathname-scoped serialization to ensure each response only includes\n\t// its own data (see createContentHtmlScript and createSSRExportsScript).\n\n\t// 1. Seed content modules for SSR rendering\n\tawait withSpan('ssr.seed', async (span) => {\n\t\tspan.setAttribute('pathname', pathname);\n\t\tspan.setAttribute('streaming', streaming);\n\t\tawait seedSSRModuleForPath(pathname, clientDir, cwd, isWatchMode);\n\t\tif (debug)\n\t\t\tconsole.log(\n\t\t\t\t`[Setup] ${pathname} - seedModule: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t);\n\t});\n\tassertNotTimedOut();\n\n\t// 2. Reset SSR access tracking and create bundle preload\n\tresetSSRAccessTracking();\n\tconst bundlePreload = createBundlePreload(bundleUrl);\n\n\t// 3. Preload content module\n\tconst preloadResult = await withSpan('ssr.preload', async (span) => {\n\t\tspan.setAttribute('pathname', pathname);\n\t\tconst result = await preloadContentModule(\n\t\t\tpathname,\n\t\t\tclientDir,\n\t\t\tcwd,\n\t\t\tisWatchMode,\n\t\t);\n\t\tspan.setAttribute('has_module', !!result.modulePath);\n\t\tif (debug)\n\t\t\tconsole.log(\n\t\t\t\t`[Setup] ${pathname} - preloadContent: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t);\n\t\treturn result;\n\t});\n\tassertNotTimedOut();\n\n\t// 4. Compute SSR data\n\tconst computeResult: ComputeResult = await withSpan(\n\t\t'ssr.compute.data',\n\t\tasync (span) => {\n\t\t\tspan.setAttribute('pathname', pathname);\n\t\t\tspan.setAttribute('streaming', streaming);\n\t\t\tconst result = await computeSSRData(\n\t\t\t\tpathname,\n\t\t\t\tclientDir,\n\t\t\t\tcwd,\n\t\t\t\tisWatchMode,\n\t\t\t\t{ streaming, maxAge, headers: options.headers },\n\t\t\t\tsearchParams,\n\t\t\t);\n\t\t\tspan.setAttribute('has_error', !!result.error);\n\t\t\tspan.setAttribute('has_data', Object.keys(result.data).length > 0);\n\t\t\tif (debug)\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[Setup] ${pathname} - computeSSRData: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t\t);\n\t\t\treturn result;\n\t\t},\n\t);\n\tassertNotTimedOut();\n\n\tsetGlobalSSRData(computeResult.data);\n\n\t// 5. Load content collections (use cached if available)\n\tconst usingCachedCollections = !!options.cachedCollections;\n\tconst byCollectionForSSR = await withSpan(\n\t\t'ssr.load.collections',\n\t\tasync (span) => {\n\t\t\tspan.setAttribute('pathname', pathname);\n\t\t\tspan.setAttribute('cached', usingCachedCollections);\n\t\t\tconst collections = options.cachedCollections\n\t\t\t\t? options.cachedCollections\n\t\t\t\t: await loadCollections(cwd, isWatchMode);\n\t\t\tspan.setAttribute('collection_count', Object.keys(collections).length);\n\t\t\tif (debug)\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[Setup] ${pathname} - loadCollections (cached: ${usingCachedCollections}): ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t\t);\n\t\t\treturn collections;\n\t\t},\n\t);\n\tassertNotTimedOut();\n\tsetGlobalCollections(byCollectionForSSR);\n\n\t// 6. Inline theme CSS (use cached if available)\n\tconst usingCachedCSS = !!options.cachedThemeCSS;\n\tconst inlineStyleTag = await withSpan('ssr.inline.css', async (span) => {\n\t\tconst css = options.cachedThemeCSS\n\t\t\t? options.cachedThemeCSS\n\t\t\t: await inlineThemeCSS(clientDir, !streaming, isWatchMode);\n\t\tspan.setAttributes({\n\t\t\t'reroute.cached': usingCachedCSS,\n\t\t\t'reroute.css.size': css.length,\n\t\t});\n\t\tif (debug)\n\t\t\tconsole.log(\n\t\t\t\t`[Setup] ${pathname} - inlineThemeCSS (cached: ${usingCachedCSS}): ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t);\n\t\treturn css;\n\t});\n\tassertNotTimedOut();\n\n\t// 7. Determine initial status override\n\tlet statusOverride = preloadResult.statusOverride;\n\tif (computeResult.statusContainer.value !== undefined) {\n\t\tstatusOverride = computeResult.statusContainer.value;\n\t}\n\n\t// 8. Extract page metadata (with SSR data for dynamic head tags)\n\tconst metadataResult = await withSpan(\n\t\t'ssr.extract.metadata',\n\t\tasync (span) => {\n\t\t\tconst result = await extractPageMetadata(\n\t\t\t\tpathname,\n\t\t\t\tclientDir,\n\t\t\t\tcwd,\n\t\t\t\tisWatchMode,\n\t\t\t\tstatusOverride,\n\t\t\t\togConfig,\n\t\t\t\toptions.ogMetaConfig,\n\t\t\t\toptions.baseUrl,\n\t\t\t\toptions.autoCanonical,\n\t\t\t\tcomputeResult.data,\n\t\t\t\toptions.titleSuffix,\n\t\t\t);\n\t\t\tspan.setAttributes({\n\t\t\t\t'reroute.pathname': pathname,\n\t\t\t\t'reroute.metadata.exists': !!result.perPageHead,\n\t\t\t});\n\t\t\tif (debug)\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[Setup] ${pathname} - extractMetadata: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t\t);\n\t\t\treturn result;\n\t\t},\n\t);\n\tassertNotTimedOut();\n\n\treturn {\n\t\tssrData: computeResult.data,\n\t\tssrError: computeResult.error,\n\t\tstatusContainer: computeResult.statusContainer,\n\t\tbyCollectionForSSR,\n\t\tbundlePreload,\n\t\tpreloadExtraHead: preloadResult.extraHead,\n\t\tpreloadHydrationScript: preloadResult.hydrationScript,\n\t\tpreloadStatusOverride: preloadResult.statusOverride,\n\t\tinlineStyleTag,\n\t\tmetadataResult,\n\t\tpending: computeResult.pending,\n\t};\n}\n\n/**\n * Generate hydration scripts for collections that were accessed during SSR.\n */\nfunction generateCollectionScripts(\n\tbyCollectionForSSR: Record<string, unknown[]>,\n): string {\n\ttry {\n\t\tconst g = globalThis as unknown as { __REROUTE_SSR_ACCESSED__?: unknown };\n\t\tconst acc = g.__REROUTE_SSR_ACCESSED__;\n\n\t\tif (acc) {\n\t\t\tconst { subset, partial } = processCollections(acc, byCollectionForSSR);\n\t\t\tif (Object.keys(subset).length > 0) {\n\t\t\t\treturn createCollectionScript(subset, partial);\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Ignore errors\n\t}\n\treturn '';\n}\n\n/**\n * Generate all hydration scripts for SSR\n */\nfunction generateHydrationScripts(\n\tssrData: Record<string, unknown>,\n\tisWatchMode: boolean,\n\tssrError?: string,\n\tcollectionScripts = '',\n\tpreloadScript = '',\n\tbundleUrl = '',\n\tpathname = '',\n\tbrowserTelemetryConfig?: Record<string, unknown>,\n\ttraceContext?: { traceparent?: string; tracestate?: string },\n\ttitleSuffix?: string,\n\ti18n?: Record<string, unknown>,\n): string {\n\tlet scripts = preloadScript;\n\n\t// Add collection scripts\n\tscripts += collectionScripts;\n\n\t// Add SSR data script (pathname is used to scope content HTML and exports to current request)\n\tscripts += createDataScript(\n\t\tssrData,\n\t\tisWatchMode ? ssrError : undefined,\n\t\tpathname,\n\t\tbrowserTelemetryConfig,\n\t\ttraceContext,\n\t\ttitleSuffix,\n\t\ti18n,\n\t);\n\n\t// Add feeds and llms scripts\n\tscripts += createFeedsScript();\n\tscripts += createLlmsScript();\n\n\t// Add bundle script\n\tif (bundleUrl) {\n\t\tscripts += `<script type=\"module\" src=\"${bundleUrl}\"></script>`;\n\t}\n\n\t// Add dev watcher in watch mode\n\tif (isWatchMode) {\n\t\tscripts += `<script type=\"module\" src=\"/__reroute_watch.js\"></script>`;\n\t}\n\n\treturn scripts;\n}\n\nexport type { SSRSetupOptions, SSRSetupResult };\nexport { performSSRSetup, generateCollectionScripts, generateHydrationScripts };\n",
31
31
  "// Types\n\n// Core utilities\nexport * from './cache';\nexport * from './cleanup';\n// Content handling\nexport * from './collections';\n// HTTP utilities\nexport * from './compression';\n// SSR compute\nexport * from './compute';\nexport { computeSSRDataForPath } from './data';\n// HTML handling\nexport * from './html';\nexport * from './imports';\nexport * from './layouts';\nexport * from './metadata';\nexport * from './mime';\nexport * from './modules';\nexport * from './path';\nexport * from './preload';\nexport * from './route-match';\n// Script generation\nexport * from './scripts';\nexport * from './seed';\n// Shared setup\nexport * from './setup';\nexport * from './styles';\nexport * from './template';\nexport * from './types';\n",
32
- "import type { Span } from '@opentelemetry/api';\nimport dedent from 'dedent';\nimport { cloneElement, type ReactElement } from 'react';\nimport { renderToString } from 'react-dom/server';\nimport {\n\tgetTraceContextForInjection,\n\twithSpan,\n\twithSpanSync,\n} from 'reroute-js/telemetry/server';\nimport { loadConfig, type OGImageOptions, type OGOptions } from '../config';\nimport {\n\ttype Doc,\n\tduplicateQueryParamData,\n\tgenerateCollectionScripts,\n\tgenerateHydrationScripts,\n\tperformSSRSetup,\n\tsetGlobalSSRData,\n} from './lib';\nimport { applyIndexTemplate, loadIndexHtml } from './lib/html';\n\ntype SSRRenderOptions = {\n\tpathname: string;\n\trootComponent: ReactElement;\n\tclientDir: string;\n\tcwd: string;\n\tisWatchMode: boolean;\n\tbundleUrl: string;\n\tcachedCollections?: Record<string, unknown[]>;\n\tcachedTailwindCSS?: string;\n\thead?: string;\n\tlang?: string;\n\tappId?: string;\n\tminify?: boolean;\n\tmaxAge?: number;\n\tsearchParams?: URLSearchParams;\n\togConfig?: OGImageOptions;\n\togMetaConfig?: OGOptions;\n\tbaseUrl?: string;\n\tautoCanonical?: boolean;\n\tparentSpan?: Span | null;\n\t/** Request headers from the incoming HTTP request */\n\theaders?: Record<string, string>;\n\t/** Suffix to append to all page titles */\n\ttitleSuffix?: string;\n\t/** Hydrated i18n state (opt-in) */\n\ti18n?: Record<string, unknown>;\n};\n\ntype SSRRenderResult = {\n\thtml: string;\n\tstatus: number;\n};\n\n/**\n * Render a React component to a complete HTML document for SSR.\n * Uses synchronous rendering (renderToString) for full HTML generation.\n */\nasync function renderSSRDocument(\n\toptions: SSRRenderOptions,\n): Promise<SSRRenderResult> {\n\tconst {\n\t\tpathname,\n\t\trootComponent,\n\t\tclientDir,\n\t\tcwd,\n\t\tisWatchMode,\n\t\tbundleUrl,\n\t\thead = '',\n\t\tlang = 'en',\n\t\tappId = 'root',\n\t\tmaxAge = 0,\n\t\tsearchParams,\n\t\togConfig,\n\t} = options;\n\n\t// Perform shared SSR setup\n\tconst setup = await performSSRSetup(\n\t\t{\n\t\t\tpathname,\n\t\t\tclientDir,\n\t\t\tcwd,\n\t\t\tisWatchMode,\n\t\t\tparentSpan: options.parentSpan,\n\t\t\tbundleUrl,\n\t\t\tmaxAge,\n\t\t\tsearchParams,\n\t\t\togConfig,\n\t\t\togMetaConfig: options.ogMetaConfig,\n\t\t\tbaseUrl: options.baseUrl,\n\t\t\tautoCanonical: options.autoCanonical,\n\t\t\tcachedCollections: options.cachedCollections,\n\t\t\tcachedTailwindCSS: options.cachedTailwindCSS,\n\t\t\theaders: options.headers,\n\t\t\ttitleSuffix: options.titleSuffix,\n\t\t},\n\t\tfalse, // not streaming\n\t);\n\n\t// Duplicate data for query param routes\n\tconst duplicatedData = duplicateQueryParamData(setup.ssrData);\n\tsetGlobalSSRData(duplicatedData);\n\n\t// Render React component to string\n\tconst appHtml = await withSpan('ssr.render.react', async (span) => {\n\t\tconst componentWithPathname = cloneElement<Doc>(rootComponent, {\n\t\t\tpathname,\n\t\t\tsearchParams,\n\t\t} as Doc);\n\t\tspan.setAttribute('reroute.pathname', pathname);\n\t\tconst html = renderToString(componentWithPathname);\n\t\tspan.setAttribute('reroute.html.final.size', html.length);\n\t\treturn html;\n\t});\n\n\t// Load base template\n\tconst baseTemplate = await withSpan('ssr.load.template', async (span) => {\n\t\tconst template = await loadIndexHtml(clientDir);\n\t\tspan.setAttribute('reroute.template.size', template.length);\n\t\treturn template;\n\t});\n\n\t// Generate collection scripts from accessed collections\n\tconst collectionScripts = generateCollectionScripts(setup.byCollectionForSSR);\n\n\t// Load config to get browser telemetry settings\n\tconst config = await loadConfig(cwd);\n\tconst browserTelemetryConfigRaw = config.telemetry?.browser as\n\t\t| Record<string, unknown>\n\t\t| undefined;\n\n\t// Serialize browser telemetry config (convert functions to strings for JSON)\n\tconst { serializeBrowserTelemetryConfig } = await import('./lib/serialize');\n\tconst browserTelemetryConfig = serializeBrowserTelemetryConfig(\n\t\tbrowserTelemetryConfigRaw,\n\t);\n\n\t// Extract trace context from parent span for distributed tracing\n\tconst traceContext = getTraceContextForInjection(options.parentSpan);\n\n\t// Generate all hydration scripts\n\tconst hydrationScript = await withSpan(\n\t\t'ssr.generate.scripts',\n\t\tasync (span) => {\n\t\t\tconst script = generateHydrationScripts(\n\t\t\t\tsetup.ssrData,\n\t\t\t\tisWatchMode,\n\t\t\t\tsetup.ssrError,\n\t\t\t\tcollectionScripts,\n\t\t\t\tsetup.preloadHydrationScript,\n\t\t\t\tbundleUrl,\n\t\t\t\tpathname,\n\t\t\t\tbrowserTelemetryConfig,\n\t\t\t\ttraceContext,\n\t\t\t\toptions.titleSuffix,\n\t\t\t\toptions.i18n,\n\t\t\t);\n\t\t\tspan.setAttribute('reroute.scripts.size', script.length);\n\t\t\treturn script;\n\t\t},\n\t);\n\n\t// Determine final status (only override if value is set)\n\tlet statusOverride = setup.preloadStatusOverride;\n\tif (setup.statusContainer.value !== undefined) {\n\t\tstatusOverride = setup.statusContainer.value;\n\t}\n\tif (setup.metadataResult.statusOverride !== undefined) {\n\t\tstatusOverride = setup.metadataResult.statusOverride;\n\t}\n\n\t// Build combined head content\n\tconst extraHead = setup.bundlePreload + setup.preloadExtraHead;\n\tconst combinedHead = dedent(\n\t\t[\n\t\t\tdedent(head) || '',\n\t\t\tdedent(extraHead),\n\t\t\tdedent(setup.metadataResult.perPageHead),\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join('\\n'),\n\t);\n\n\tconst i18nLocale = options.i18n?.enabled\n\t\t? String(options.i18n.locale || '')\n\t\t: '';\n\n\t// Apply template with SSR content\n\tconst html = withSpanSync('ssr.apply.template', (span) => {\n\t\tconst result = applyIndexTemplate(baseTemplate, appHtml, {\n\t\t\thead: [setup.inlineStyleTag, combinedHead].filter(Boolean).join('\\n'),\n\t\t\thydrationScript,\n\t\t\tlang: setup.metadataResult.pageLang || i18nLocale || lang,\n\t\t\tappId,\n\t\t});\n\t\tspan.setAttributes({\n\t\t\t'reroute.html.final.size': result.length,\n\t\t\t'reroute.html.original.size': appHtml.length,\n\t\t});\n\t\treturn result;\n\t});\n\n\treturn {\n\t\thtml,\n\t\tstatus: statusOverride || 200,\n\t};\n}\n\nexport { renderSSRDocument, type SSRRenderOptions, type SSRRenderResult };\n",
32
+ "import type { Span } from '@opentelemetry/api';\nimport dedent from 'dedent';\nimport { cloneElement, type ReactElement } from 'react';\nimport { renderToString } from 'react-dom/server';\nimport {\n\tgetTraceContextForInjection,\n\twithSpan,\n\twithSpanSync,\n} from 'reroute-js/telemetry/server';\nimport { loadConfig, type OGImageOptions, type OGOptions } from '../config';\nimport {\n\ttype Doc,\n\tduplicateQueryParamData,\n\tgenerateCollectionScripts,\n\tgenerateHydrationScripts,\n\tperformSSRSetup,\n\tsetGlobalSSRData,\n} from './lib';\nimport { applyIndexTemplate, loadIndexHtml } from './lib/html';\n\ntype SSRRenderOptions = {\n\tpathname: string;\n\trootComponent: ReactElement;\n\tclientDir: string;\n\tcwd: string;\n\tisWatchMode: boolean;\n\tbundleUrl: string;\n\tcachedCollections?: Record<string, unknown[]>;\n\tcachedThemeCSS?: string;\n\thead?: string;\n\tlang?: string;\n\tappId?: string;\n\tminify?: boolean;\n\tmaxAge?: number;\n\tsearchParams?: URLSearchParams;\n\togConfig?: OGImageOptions;\n\togMetaConfig?: OGOptions;\n\tbaseUrl?: string;\n\tautoCanonical?: boolean;\n\tparentSpan?: Span | null;\n\t/** Request headers from the incoming HTTP request */\n\theaders?: Record<string, string>;\n\t/** Suffix to append to all page titles */\n\ttitleSuffix?: string;\n\t/** Hydrated i18n state (opt-in) */\n\ti18n?: Record<string, unknown>;\n};\n\ntype SSRRenderResult = {\n\thtml: string;\n\tstatus: number;\n};\n\n/**\n * Render a React component to a complete HTML document for SSR.\n * Uses synchronous rendering (renderToString) for full HTML generation.\n */\nasync function renderSSRDocument(\n\toptions: SSRRenderOptions,\n): Promise<SSRRenderResult> {\n\tconst {\n\t\tpathname,\n\t\trootComponent,\n\t\tclientDir,\n\t\tcwd,\n\t\tisWatchMode,\n\t\tbundleUrl,\n\t\thead = '',\n\t\tlang = 'en',\n\t\tappId = 'root',\n\t\tmaxAge = 0,\n\t\tsearchParams,\n\t\togConfig,\n\t} = options;\n\n\t// Perform shared SSR setup\n\tconst setup = await performSSRSetup(\n\t\t{\n\t\t\tpathname,\n\t\t\tclientDir,\n\t\t\tcwd,\n\t\t\tisWatchMode,\n\t\t\tparentSpan: options.parentSpan,\n\t\t\tbundleUrl,\n\t\t\tmaxAge,\n\t\t\tsearchParams,\n\t\t\togConfig,\n\t\t\togMetaConfig: options.ogMetaConfig,\n\t\t\tbaseUrl: options.baseUrl,\n\t\t\tautoCanonical: options.autoCanonical,\n\t\t\tcachedCollections: options.cachedCollections,\n\t\t\tcachedThemeCSS: options.cachedThemeCSS,\n\t\t\theaders: options.headers,\n\t\t\ttitleSuffix: options.titleSuffix,\n\t\t},\n\t\tfalse, // not streaming\n\t);\n\n\t// Duplicate data for query param routes\n\tconst duplicatedData = duplicateQueryParamData(setup.ssrData);\n\tsetGlobalSSRData(duplicatedData);\n\n\t// Render React component to string\n\tconst appHtml = await withSpan('ssr.render.react', async (span) => {\n\t\tconst componentWithPathname = cloneElement<Doc>(rootComponent, {\n\t\t\tpathname,\n\t\t\tsearchParams,\n\t\t} as Doc);\n\t\tspan.setAttribute('reroute.pathname', pathname);\n\t\tconst html = renderToString(componentWithPathname);\n\t\tspan.setAttribute('reroute.html.final.size', html.length);\n\t\treturn html;\n\t});\n\n\t// Load base template\n\tconst baseTemplate = await withSpan('ssr.load.template', async (span) => {\n\t\tconst template = await loadIndexHtml(clientDir);\n\t\tspan.setAttribute('reroute.template.size', template.length);\n\t\treturn template;\n\t});\n\n\t// Generate collection scripts from accessed collections\n\tconst collectionScripts = generateCollectionScripts(setup.byCollectionForSSR);\n\n\t// Load config to get browser telemetry settings\n\tconst config = await loadConfig(cwd);\n\tconst browserTelemetryConfigRaw = config.telemetry?.browser as\n\t\t| Record<string, unknown>\n\t\t| undefined;\n\n\t// Serialize browser telemetry config (convert functions to strings for JSON)\n\tconst { serializeBrowserTelemetryConfig } = await import('./lib/serialize');\n\tconst browserTelemetryConfig = serializeBrowserTelemetryConfig(\n\t\tbrowserTelemetryConfigRaw,\n\t);\n\n\t// Extract trace context from parent span for distributed tracing\n\tconst traceContext = getTraceContextForInjection(options.parentSpan);\n\n\t// Generate all hydration scripts\n\tconst hydrationScript = await withSpan(\n\t\t'ssr.generate.scripts',\n\t\tasync (span) => {\n\t\t\tconst script = generateHydrationScripts(\n\t\t\t\tsetup.ssrData,\n\t\t\t\tisWatchMode,\n\t\t\t\tsetup.ssrError,\n\t\t\t\tcollectionScripts,\n\t\t\t\tsetup.preloadHydrationScript,\n\t\t\t\tbundleUrl,\n\t\t\t\tpathname,\n\t\t\t\tbrowserTelemetryConfig,\n\t\t\t\ttraceContext,\n\t\t\t\toptions.titleSuffix,\n\t\t\t\toptions.i18n,\n\t\t\t);\n\t\t\tspan.setAttribute('reroute.scripts.size', script.length);\n\t\t\treturn script;\n\t\t},\n\t);\n\n\t// Determine final status (only override if value is set)\n\tlet statusOverride = setup.preloadStatusOverride;\n\tif (setup.statusContainer.value !== undefined) {\n\t\tstatusOverride = setup.statusContainer.value;\n\t}\n\tif (setup.metadataResult.statusOverride !== undefined) {\n\t\tstatusOverride = setup.metadataResult.statusOverride;\n\t}\n\n\t// Build combined head content\n\tconst extraHead = setup.bundlePreload + setup.preloadExtraHead;\n\tconst combinedHead = dedent(\n\t\t[\n\t\t\tdedent(head) || '',\n\t\t\tdedent(extraHead),\n\t\t\tdedent(setup.metadataResult.perPageHead),\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join('\\n'),\n\t);\n\n\tconst i18nLocale = options.i18n?.enabled\n\t\t? String(options.i18n.locale || '')\n\t\t: '';\n\n\t// Apply template with SSR content\n\tconst html = withSpanSync('ssr.apply.template', (span) => {\n\t\tconst result = applyIndexTemplate(baseTemplate, appHtml, {\n\t\t\thead: [setup.inlineStyleTag, combinedHead].filter(Boolean).join('\\n'),\n\t\t\thydrationScript,\n\t\t\tlang: setup.metadataResult.pageLang || i18nLocale || lang,\n\t\t\tappId,\n\t\t});\n\t\tspan.setAttributes({\n\t\t\t'reroute.html.final.size': result.length,\n\t\t\t'reroute.html.original.size': appHtml.length,\n\t\t});\n\t\treturn result;\n\t});\n\n\treturn {\n\t\thtml,\n\t\tstatus: statusOverride || 200,\n\t};\n}\n\nexport { renderSSRDocument, type SSRRenderOptions, type SSRRenderResult };\n",
33
33
  "import { pathToFileURL } from 'node:url';\nimport type { ReactElement } from 'react';\nimport { renderToStaticMarkup } from 'react-dom/server';\nimport type { LLMsOptions } from '../config';\nimport { join } from '../ssr/lib/path';\nimport type { Doc } from '../ssr/lib/types';\nimport { renderSSRDocument } from '../ssr/render';\nimport { extractTitle, htmlToMarkdown, stripHtmlTags } from './formatter';\n\n/**\n * Check if a route should be excluded from LLM features\n * Supports strings (substring match), RegExp, and custom functions\n */\nexport function shouldExcludeRoute(\n\tpathname: string,\n\texcludeRoutes?: (string | RegExp | ((pathname: string) => boolean))[],\n): boolean {\n\tif (!excludeRoutes || excludeRoutes.length === 0) {\n\t\treturn false;\n\t}\n\n\treturn Boolean(\n\t\texcludeRoutes.find((pattern) => {\n\t\t\tif (typeof pattern === 'string') {\n\t\t\t\t// Substring match for simplicity\n\t\t\t\treturn pathname.includes(pattern);\n\t\t\t}\n\t\t\tif (pattern instanceof RegExp) {\n\t\t\t\treturn pattern.test(pathname);\n\t\t\t}\n\t\t\tif (typeof pattern === 'function') {\n\t\t\t\treturn pattern(pathname);\n\t\t\t}\n\t\t\treturn false;\n\t\t}),\n\t);\n}\n\nasync function loadCollectionItem(\n\tcwd: string,\n\tpathname: string,\n\tisWatchMode: boolean,\n): Promise<{ item: Doc; collection: string } | null> {\n\tconst parts = pathname.split('/').filter(Boolean);\n\tif (parts.length < 2) return null;\n\n\tconst collection = parts[0];\n\tconst collectionFile = join(\n\t\tcwd,\n\t\t'.reroute',\n\t\t'collections',\n\t\t`${collection}.js`,\n\t);\n\tconst exists = await Bun.file(collectionFile).exists();\n\tif (!exists) return null;\n\n\tconst url = `${pathToFileURL(collectionFile).href}${isWatchMode ? `?t=${Date.now()}` : ''}`;\n\tconst mod = await import(url);\n\tconst items = mod.items || [];\n\n\tconst item = items.find((i: Doc) => i.href === pathname);\n\tif (!item) return null;\n\n\treturn { item, collection };\n}\n\nasync function findComponentPath(\n\tclientDir: string,\n\tcollection: string,\n\tslug: string,\n): Promise<string | null> {\n\tconst extensions = ['.mdx', '.md', '.tsx', '.jsx'];\n\n\tfor (const ext of extensions) {\n\t\tconst testPath = join(\n\t\t\tclientDir,\n\t\t\t'routes',\n\t\t\tcollection,\n\t\t\t'content',\n\t\t\t`${slug}${ext}`,\n\t\t);\n\t\tconst file = Bun.file(testPath);\n\t\tif (await file.exists()) {\n\t\t\treturn testPath;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction stripFrontmatterAndJsx(content: string, isMdx: boolean): string {\n\tlet rawContent = content.replace(/^---\\n[\\s\\S]*?\\n---\\n/, '');\n\n\tif (isMdx) {\n\t\trawContent = rawContent.replace(\n\t\t\t/^import\\s+.*?from\\s+['\"].*?['\"];?\\s*$/gm,\n\t\t\t'',\n\t\t);\n\t\trawContent = rawContent.replace(/<[A-Z][\\w]*[^>]*\\/>/g, '');\n\t\trawContent = rawContent.replace(\n\t\t\t/<[A-Z][\\w]*[^>]*>[\\s\\S]*?<\\/[A-Z][\\w]*>/g,\n\t\t\t'',\n\t\t);\n\t}\n\n\treturn rawContent.trim();\n}\n\nasync function extractMarkdownContent(\n\tcomponentPath: string,\n\tmeta: Record<string, unknown>,\n): Promise<{ title?: string; body: string; markdown: string }> {\n\tconst file = Bun.file(componentPath);\n\tlet rawContent = await file.text();\n\n\tconst isMdx = componentPath.endsWith('.mdx');\n\trawContent = stripFrontmatterAndJsx(rawContent, isMdx);\n\n\treturn {\n\t\ttitle: (meta.title as string) || extractTitle(rawContent),\n\t\tbody: stripHtmlTags(rawContent),\n\t\tmarkdown: rawContent,\n\t};\n}\n\nasync function extractComponentContent(\n\tcomponentPath: string,\n\tmeta: Record<string, unknown>,\n\tisWatchMode: boolean,\n): Promise<{ title?: string; body: string; markdown: string } | null> {\n\ttry {\n\t\tconst componentUrl = `${pathToFileURL(componentPath).href}${isWatchMode ? `?t=${Date.now()}` : ''}`;\n\t\tconst componentMod = await import(componentUrl);\n\n\t\tconst Component = componentMod.default;\n\t\tif (!Component || typeof Component !== 'function') return null;\n\n\t\tconst html = renderToStaticMarkup(Component({}));\n\n\t\treturn {\n\t\t\ttitle: (meta.title as string) || extractTitle(html),\n\t\t\tbody: stripHtmlTags(html),\n\t\t\tmarkdown: htmlToMarkdown(html),\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t`[reroute/llms] Failed to import component ${componentPath}:`,\n\t\t\terror,\n\t\t);\n\t\treturn null;\n\t}\n}\n\n/**\n * Extract content from a collection item (markdown/mdx)\n */\nasync function extractCollectionContent(\n\tcwd: string,\n\tclientDir: string,\n\tpathname: string,\n\tisWatchMode: boolean,\n\t_format: 'txt' | 'md',\n): Promise<{ title?: string; body: string; markdown: string } | null> {\n\ttry {\n\t\tconst collectionData = await loadCollectionItem(cwd, pathname, isWatchMode);\n\t\tif (!collectionData) return null;\n\n\t\tconst { item, collection } = collectionData;\n\t\tconst slug = item.slug || item.name;\n\t\tif (!slug) return null;\n\n\t\tconst componentPath = await findComponentPath(clientDir, collection, slug);\n\t\tif (!componentPath) return null;\n\n\t\tconst meta = item.meta || {};\n\n\t\tif (componentPath.endsWith('.md') || componentPath.endsWith('.mdx')) {\n\t\t\treturn await extractMarkdownContent(componentPath, meta);\n\t\t}\n\n\t\treturn await extractComponentContent(componentPath, meta, isWatchMode);\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t`[reroute/llms] Failed to extract collection content for ${pathname}:`,\n\t\t\terror,\n\t\t);\n\t\treturn null;\n\t}\n}\n\n/**\n * Extract content from an SSR route using full app rendering\n */\nasync function extractSSRContent(\n\tpathname: string,\n\trootComponent: ReactElement,\n\tclientDir: string,\n\tcwd: string,\n\tisWatchMode: boolean,\n\tbundleUrl: string,\n\t_format: 'txt' | 'md',\n): Promise<{ title?: string; body: string; markdown: string } | null> {\n\ttry {\n\t\t// Use the full SSR rendering pipeline to get the complete HTML\n\t\t// This includes all providers, context, and hooks - just like a real request\n\t\tconst { html } = await renderSSRDocument({\n\t\t\tpathname,\n\t\t\trootComponent,\n\t\t\tclientDir,\n\t\t\tcwd,\n\t\t\tisWatchMode,\n\t\t\tbundleUrl,\n\t\t\tminify: false,\n\t\t\tmaxAge: 0,\n\t\t});\n\n\t\t// Extract just the content from the rendered HTML\n\t\t// Remove script tags, styles, nav, footer, etc.\n\t\tlet contentHtml = html;\n\n\t\t// Extract the body content (inside the app div)\n\t\tconst appDivMatch = html.match(/<div id=\"[^\"]+\">(.+?)<\\/div>\\s*<script/s);\n\t\tif (appDivMatch) {\n\t\t\tcontentHtml = appDivMatch[1];\n\t\t}\n\n\t\t// Remove nav and footer elements (common layout noise)\n\t\tcontentHtml = contentHtml.replace(/<nav[\\s\\S]*?<\\/nav>/gi, '');\n\t\tcontentHtml = contentHtml.replace(/<footer[\\s\\S]*?<\\/footer>/gi, '');\n\t\tcontentHtml = contentHtml.replace(/<header[\\s\\S]*?<\\/header>/gi, '');\n\t\tcontentHtml = contentHtml.replace(/<aside[\\s\\S]*?<\\/aside>/gi, '');\n\n\t\treturn {\n\t\t\ttitle: extractTitle(html),\n\t\t\tbody: stripHtmlTags(contentHtml),\n\t\t\tmarkdown: htmlToMarkdown(contentHtml),\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t`[reroute/llms] Failed to extract SSR content for ${pathname}:`,\n\t\t\terror,\n\t\t);\n\t\treturn null;\n\t}\n}\n\n/**\n * Main content extraction function\n * Extracts clean, LLM-optimized content from any route type\n */\nexport async function extractContentForLLMs(options: {\n\tpathname: string;\n\trootComponent?: ReactElement;\n\tclientDir: string;\n\tcwd: string;\n\tisWatchMode: boolean;\n\tbundleUrl?: string;\n\tformat: 'txt' | 'md';\n\tllmsConfig?: LLMsOptions;\n}): Promise<string> {\n\tconst {\n\t\tpathname,\n\t\trootComponent,\n\t\tclientDir,\n\t\tcwd,\n\t\tisWatchMode,\n\t\tbundleUrl,\n\t\tformat,\n\t\tllmsConfig,\n\t} = options;\n\n\t// Check if route should be excluded\n\tif (shouldExcludeRoute(pathname, llmsConfig?.excludeRoutes)) {\n\t\tthrow new Error('Route excluded from LLM features');\n\t}\n\n\t// Try collection content first (most common case for content sites)\n\tlet content = await extractCollectionContent(\n\t\tcwd,\n\t\tclientDir,\n\t\tpathname,\n\t\tisWatchMode,\n\t\tformat,\n\t);\n\n\t// Fall back to SSR route (uses full app rendering)\n\tif (!content && rootComponent && bundleUrl) {\n\t\tcontent = await extractSSRContent(\n\t\t\tpathname,\n\t\t\trootComponent,\n\t\t\tclientDir,\n\t\t\tcwd,\n\t\t\tisWatchMode,\n\t\t\tbundleUrl,\n\t\t\tformat,\n\t\t);\n\t}\n\n\t// If we still don't have content, throw\n\tif (!content) {\n\t\tthrow new Error('Content not found');\n\t}\n\n\t// Return based on format\n\tif (format === 'md') {\n\t\t// Return markdown with title as h1\n\t\tconst parts: string[] = [];\n\t\tif (content.title) {\n\t\t\tparts.push(`# ${content.title}`);\n\t\t\tparts.push('');\n\t\t}\n\t\tparts.push(content.markdown);\n\t\treturn parts.join('\\n');\n\t}\n\n\t// Return plain text\n\tconst parts: string[] = [];\n\tif (content.title) {\n\t\tparts.push(content.title);\n\t\tparts.push('');\n\t}\n\tparts.push(content.body);\n\treturn parts.join('\\n');\n}\n",
34
34
  "import type { ReactElement } from 'react';\nimport type { LLMsOptions } from '../config';\nimport { extractContentForLLMs, shouldExcludeRoute } from './extractor';\n\ntype RouteEntry = {\n\tpath: string;\n\tdate?: string;\n};\n\nfunction buildHeader(baseUrl: string, llmsConfig?: LLMsOptions): string[] {\n\tconst parts: string[] = [];\n\n\tif (llmsConfig?.siteName) {\n\t\tparts.push(`# ${llmsConfig.siteName}`);\n\t\tparts.push('');\n\t}\n\n\tif (llmsConfig?.siteDescription) {\n\t\tparts.push(llmsConfig.siteDescription);\n\t\tparts.push('');\n\t}\n\n\tif (parts.length > 0) {\n\t\tparts.push(`${baseUrl}/index.txt`);\n\t\tparts.push('');\n\t\tparts.push('---');\n\t\tparts.push('');\n\t}\n\n\treturn parts;\n}\n\nasync function discoverAllRoutes(\n\tcwd: string,\n\tcollections: string[],\n\tisWatchMode: boolean,\n\tllmsConfig?: LLMsOptions,\n): Promise<RouteEntry[]> {\n\tconst {\n\t\tdiscoverStaticRoutes,\n\t\tdiscoverCollectionRoutes,\n\t\tdiscoverSSRDataRoutes,\n\t} = await import('./index-generator');\n\n\tconst staticRoutes = await discoverStaticRoutes(cwd, isWatchMode);\n\tconst collectionsMap = await discoverCollectionRoutes(\n\t\tcwd,\n\t\tcollections,\n\t\tisWatchMode,\n\t\tllmsConfig,\n\t);\n\tconst ssrDataRoutes = await discoverSSRDataRoutes(\n\t\tcwd,\n\t\tstaticRoutes,\n\t\tisWatchMode,\n\t);\n\n\tconst allRoutes: RouteEntry[] = [];\n\n\tfor (const route of staticRoutes) {\n\t\tif (!shouldExcludeRoute(route.path, llmsConfig?.excludeRoutes)) {\n\t\t\tallRoutes.push({ path: route.path });\n\t\t}\n\t}\n\n\tfor (const [_collection, routes] of collectionsMap.entries()) {\n\t\tfor (const route of routes) {\n\t\t\tif (!shouldExcludeRoute(route.path, llmsConfig?.excludeRoutes)) {\n\t\t\t\tallRoutes.push({ path: route.path });\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (const [_routePattern, routes] of ssrDataRoutes.entries()) {\n\t\tfor (const route of routes) {\n\t\t\tif (!shouldExcludeRoute(route.path, llmsConfig?.excludeRoutes)) {\n\t\t\t\tallRoutes.push({ path: route.path });\n\t\t\t}\n\t\t}\n\t}\n\n\treturn allRoutes;\n}\n\nfunction formatContentBlock(\n\tcontent: string,\n\troutePath: string,\n\tbaseUrl: string,\n): string[] {\n\tconst parts: string[] = [];\n\tconst lines = content.split('\\n');\n\tconst title = lines[0] || 'Untitled';\n\tconst body = lines.slice(lines[1] === '' ? 2 : 1).join('\\n');\n\n\tconst urlPath = routePath === '/' ? '/index' : routePath;\n\tconst url = `${baseUrl}${urlPath}.txt`;\n\n\tparts.push(title);\n\tparts.push('');\n\tparts.push(url);\n\tparts.push('');\n\tif (body.trim()) {\n\t\tparts.push(body);\n\t\tparts.push('');\n\t}\n\tparts.push('---');\n\tparts.push('');\n\n\treturn parts;\n}\n\nasync function extractRouteContents(\n\troutes: RouteEntry[],\n\toptions: {\n\t\trootComponent?: ReactElement;\n\t\tcwd: string;\n\t\tclientDir: string;\n\t\tbaseUrl: string;\n\t\tisWatchMode: boolean;\n\t\tbundleUrl?: string;\n\t\tllmsConfig?: LLMsOptions;\n\t},\n): Promise<{ parts: string[]; itemCount: number; currentSize: number }> {\n\tconst parts: string[] = [];\n\tconst maxSize = options.llmsConfig?.maxSize || 50 * 1024 * 1024;\n\tlet itemCount = 0;\n\tlet currentSize = 0;\n\n\tfor (const route of routes) {\n\t\ttry {\n\t\t\tconst content = await extractContentForLLMs({\n\t\t\t\tpathname: route.path,\n\t\t\t\trootComponent: options.rootComponent,\n\t\t\t\tclientDir: options.clientDir,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tisWatchMode: options.isWatchMode,\n\t\t\t\tbundleUrl: options.bundleUrl,\n\t\t\t\tformat: 'txt',\n\t\t\t\tllmsConfig: options.llmsConfig,\n\t\t\t});\n\n\t\t\tconst contentSize = Buffer.byteLength(content, 'utf8');\n\t\t\tif (currentSize + contentSize > maxSize) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[reroute/llms] Reached size limit (${maxSize} bytes), stopping at ${itemCount} items`,\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst blockParts = formatContentBlock(\n\t\t\t\tcontent,\n\t\t\t\troute.path,\n\t\t\t\toptions.baseUrl,\n\t\t\t);\n\t\t\tparts.push(...blockParts);\n\n\t\t\titemCount++;\n\t\t\tcurrentSize += contentSize;\n\t\t} catch (error) {\n\t\t\tconsole.warn(\n\t\t\t\t`[reroute/llms] Failed to extract content for ${route.path}:`,\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn { parts, itemCount, currentSize };\n}\n\nfunction buildFooter(parts: string[]): void {\n\tif (parts.length === 0) return;\n\n\t// Remove last separator\n\tif (parts[parts.length - 1] === '') parts.pop();\n\tif (parts[parts.length - 1] === '---') parts.pop();\n\tif (parts[parts.length - 1] === '') parts.pop();\n\n\tparts.push('---');\n\tparts.push('');\n\tparts.push(\n\t\t'Formats: .txt | .md | Accept: text/plain | Accept: text/markdown',\n\t);\n}\n\n/**\n * Generate /llms-full.txt - all site content in one file\n * Runtime-only generation with aggressive caching (7 days default)\n */\nexport async function generateLLMsFullContent(options: {\n\trootComponent?: ReactElement;\n\tcwd: string;\n\tclientDir: string;\n\tcollections: string[];\n\tbaseUrl: string;\n\tisWatchMode: boolean;\n\tbundleUrl?: string;\n\tllmsConfig?: LLMsOptions;\n}): Promise<{\n\tcontent: string;\n\tstats: { itemCount: number; byteSize: number };\n}> {\n\tconst { cwd, collections, baseUrl, isWatchMode, llmsConfig } = options;\n\n\tconst parts = buildHeader(baseUrl, llmsConfig);\n\n\tconst allRoutes = await discoverAllRoutes(\n\t\tcwd,\n\t\tcollections,\n\t\tisWatchMode,\n\t\tllmsConfig,\n\t);\n\n\tconst maxItems = llmsConfig?.maxItems || 10000;\n\tconst routesToProcess = allRoutes.slice(0, maxItems);\n\n\tconst extracted = await extractRouteContents(routesToProcess, options);\n\tparts.push(...extracted.parts);\n\n\tbuildFooter(parts);\n\n\tconst fullContent = parts.join('\\n');\n\tconst byteSize = Buffer.byteLength(fullContent, 'utf8');\n\n\treturn {\n\t\tcontent: fullContent,\n\t\tstats: { itemCount: extracted.itemCount, byteSize },\n\t};\n}\n",
35
35
  "import { pathToFileURL } from 'node:url';\nimport type { LLMsOptions } from '../config';\nimport { join } from '../ssr/lib/path';\nimport type { Doc, SSR } from '../ssr/lib/types';\nimport { shouldExcludeRoute } from './extractor';\n\ntype RouteEntry = {\n\tpath: string;\n\tsection?: string;\n\ttitle?: string;\n};\n\n/**\n * Discover static routes from routes.ts\n */\nexport async function discoverStaticRoutes(\n\tcwd: string,\n\tisWatchMode: boolean,\n): Promise<RouteEntry[]> {\n\tconst routes: RouteEntry[] = [];\n\n\ttry {\n\t\t// Check for bundled routes first (compiled binary support)\n\t\tlet routesList = (globalThis as Record<string, unknown>)\n\t\t\t.__REROUTE_ROUTES__ as Doc[] | undefined;\n\n\t\t// Fallback to dynamic import (dev mode)\n\t\tif (!routesList) {\n\t\t\tconst routesPath = join(cwd, '.reroute', 'routes.ts');\n\t\t\tconst url = pathToFileURL(routesPath).href;\n\t\t\tconst mod = await import(\n\t\t\t\t`${url}${isWatchMode ? `?t=${Date.now()}` : ''}`\n\t\t\t);\n\t\t\troutesList = (mod as Doc)?.routes as Doc[] | undefined;\n\t\t}\n\t\tif (Array.isArray(routesList)) {\n\t\t\tfor (const route of routesList) {\n\t\t\t\tconst pattern = String(route?.pattern || '');\n\n\t\t\t\t// Skip error pages, layouts, and dynamic routes\n\t\t\t\tif (\n\t\t\t\t\tpattern.includes('[404]') ||\n\t\t\t\t\tpattern.includes('[layout]') ||\n\t\t\t\t\tpattern.includes('[skeleton]') ||\n\t\t\t\t\tpattern.includes(':')\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\troutes.push({\n\t\t\t\t\tpath: pattern,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tconsole.error('[reroute/llms] Failed to discover routes for index:', error);\n\t}\n\n\treturn routes;\n}\n\nasync function loadCollectionModule(\n\tcwd: string,\n\tcollection: string,\n\tisWatchMode: boolean,\n): Promise<Doc[] | null> {\n\tconst collectionFile = join(\n\t\tcwd,\n\t\t'.reroute',\n\t\t'collections',\n\t\t`${collection}.js`,\n\t);\n\tconst exists = await Bun.file(collectionFile).exists();\n\n\tif (!exists) return null;\n\n\tconst url = `${pathToFileURL(collectionFile).href}${isWatchMode ? `?t=${Date.now()}` : ''}`;\n\tconst mod = await import(url);\n\treturn mod.items || [];\n}\n\nfunction createRouteEntriesFromItems(\n\titems: Doc[],\n\tcollection: string,\n): RouteEntry[] {\n\tconst routes: RouteEntry[] = [];\n\n\tfor (const item of items) {\n\t\tconst href = String(item.href || '');\n\t\tif (href) {\n\t\t\tconst title = item.meta?.title || item.meta?.name || item.name;\n\t\t\troutes.push({\n\t\t\t\tpath: href,\n\t\t\t\tsection: collection,\n\t\t\t\ttitle,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn routes;\n}\n\nfunction sortRoutesByDate(routes: RouteEntry[], items: Doc[]): void {\n\troutes.sort((a, b) => {\n\t\tconst aItem = items.find((i: Doc) => i.href === a.path);\n\t\tconst bItem = items.find((i: Doc) => i.href === b.path);\n\n\t\tconst aDate = aItem?.meta?.date;\n\t\tconst bDate = bItem?.meta?.date;\n\n\t\tif (aDate && bDate) {\n\t\t\treturn new Date(bDate).getTime() - new Date(aDate).getTime();\n\t\t}\n\n\t\treturn 0;\n\t});\n}\n\n/**\n * Discover collection content\n */\nexport async function discoverCollectionRoutes(\n\tcwd: string,\n\tcollections: string[],\n\tisWatchMode: boolean,\n\tllmsConfig?: LLMsOptions,\n): Promise<Map<string, RouteEntry[]>> {\n\tconst collectionsMap = new Map<string, RouteEntry[]>();\n\n\tfor (const collection of collections) {\n\t\tif (llmsConfig?.excludeCollections?.includes(collection)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tconst items = await loadCollectionModule(cwd, collection, isWatchMode);\n\t\t\tif (!items) continue;\n\n\t\t\tconst routes = createRouteEntriesFromItems(items, collection);\n\n\t\t\tif (routes.length > 0) {\n\t\t\t\tsortRoutesByDate(routes, items);\n\t\t\t\tcollectionsMap.set(collection, routes);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(\n\t\t\t\t`[reroute/llms] Failed to discover collection ${collection}:`,\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn collectionsMap;\n}\n\nasync function loadRouteModule(\n\tcwd: string,\n\troutePath: string,\n\tisWatchMode: boolean,\n): Promise<Doc | null> {\n\ttry {\n\t\tconst abs = join(cwd, 'src', 'client', 'routes', routePath);\n\t\tconst modUrl = `${pathToFileURL(abs).href}${isWatchMode ? `?t=${Date.now()}` : ''}`;\n\t\treturn (await import(modUrl)) as Doc;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function callDataFunction(\n\tdataFn: (ctx: Doc) => unknown | Promise<unknown>,\n\troutePath: string,\n): Promise<unknown> {\n\tconst mockSet = { status: 200 };\n\treturn await dataFn({\n\t\tpathname: routePath,\n\t\tparams: {},\n\t\tset: mockSet,\n\t});\n}\n\nfunction extractIdentifier(item: Record<string, unknown>): string | undefined {\n\treturn (item.version || item.slug || item.id || item.name || item.key) as\n\t\t| string\n\t\t| undefined;\n}\n\nfunction createEntriesFromArray(array: Doc[], routePath: string): RouteEntry[] {\n\tconst entries: RouteEntry[] = [];\n\n\tfor (const item of array) {\n\t\tif (typeof item !== 'object' || item === null) continue;\n\n\t\tconst identifier = extractIdentifier(item);\n\t\tif (identifier) {\n\t\t\tentries.push({\n\t\t\t\tpath: `${routePath}/${identifier}`,\n\t\t\t\tsection: routePath.split('/').filter(Boolean)[0],\n\t\t\t});\n\t\t}\n\t}\n\n\treturn entries;\n}\n\n/**\n * Discover SSR data routes (routes with ssr.data that return arrays)\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: discovering ssr data routes is complex\nexport async function discoverSSRDataRoutes(\n\tcwd: string,\n\tstaticRoutes: RouteEntry[],\n\tisWatchMode: boolean,\n): Promise<Map<string, RouteEntry[]>> {\n\tconst ssrDataRoutes = new Map<string, RouteEntry[]>();\n\n\t// Check for bundled routes first (compiled binary support)\n\tconst bundledRoutes = (globalThis as Record<string, unknown>)\n\t\t.__REROUTE_ROUTES__ as Doc[] | undefined;\n\n\tif (bundledRoutes && Array.isArray(bundledRoutes)) {\n\t\t// In production: use pre-loaded SSR data from bundled routes\n\t\t// Match static routes against bundled routes to get their ssr.data\n\t\tfor (const route of staticRoutes) {\n\t\t\t// Find the matching bundled route by path\n\t\t\tconst bundledRoute = bundledRoutes.find((r) => r?.path === route.path);\n\n\t\t\tif (!bundledRoute) continue;\n\n\t\t\tconst ssr = (bundledRoute as Doc)?.ssr as Doc | undefined;\n\t\t\tconst dataFn = (ssr as Doc)?.data as\n\t\t\t\t| ((ctx: Doc) => unknown | Promise<unknown>)\n\t\t\t\t| undefined;\n\n\t\t\tif (typeof dataFn !== 'function') continue;\n\n\t\t\tconst result = await callDataFunction(dataFn, route.path);\n\t\t\tconst arrays = findArraysInData(result);\n\n\t\t\tfor (const array of arrays) {\n\t\t\t\tif (array.length === 0) continue;\n\n\t\t\t\tconst entries = createEntriesFromArray(array, route.path);\n\t\t\t\tif (entries.length > 0) {\n\t\t\t\t\tssrDataRoutes.set(route.path, entries);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\t// Dev mode: dynamically import route modules\n\t\tfor (const route of staticRoutes) {\n\t\t\tconst mod = await loadRouteModule(cwd, route.path, isWatchMode);\n\t\t\tif (!mod) continue;\n\n\t\t\tconst ssr = (mod as Doc)?.ssr as SSR | undefined;\n\t\t\tconst dataFn = ssr?.data;\n\n\t\t\tif (typeof dataFn !== 'function') continue;\n\n\t\t\tconst result = await callDataFunction(dataFn, route.path);\n\t\t\tconst arrays = findArraysInData(result);\n\n\t\t\tfor (const array of arrays) {\n\t\t\t\tif (array.length === 0) continue;\n\n\t\t\t\tconst entries = createEntriesFromArray(array, route.path);\n\t\t\t\tif (entries.length > 0) {\n\t\t\t\t\tssrDataRoutes.set(route.path, entries);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn ssrDataRoutes;\n}\n\n/**\n * Find arrays in data object (recursive)\n */\nfunction findArraysInData(obj: unknown): Doc[] {\n\tconst arrays: Doc[] = [];\n\n\tif (!obj || typeof obj !== 'object') {\n\t\treturn arrays;\n\t}\n\n\tfor (const value of Object.values(obj)) {\n\t\tif (Array.isArray(value)) {\n\t\t\tarrays.push(value);\n\t\t} else if (value && typeof value === 'object') {\n\t\t\tarrays.push(...findArraysInData(value));\n\t\t}\n\t}\n\n\treturn arrays;\n}\n\nfunction addIndexHeader(parts: string[], llmsConfig?: LLMsOptions): void {\n\tif (llmsConfig?.siteName) {\n\t\tparts.push(`# ${llmsConfig.siteName}`);\n\t\tparts.push('');\n\t}\n\n\tif (llmsConfig?.siteDescription) {\n\t\tparts.push(llmsConfig.siteDescription);\n\t\tparts.push('');\n\t}\n}\n\nfunction groupStaticRoutes(\n\tstaticRoutes: RouteEntry[],\n\tllmsConfig?: LLMsOptions,\n): { sections: Map<string, RouteEntry[]>; rootRoutes: RouteEntry[] } {\n\tconst sections = new Map<string, RouteEntry[]>();\n\tconst rootRoutes: RouteEntry[] = [];\n\n\tfor (const route of staticRoutes) {\n\t\tif (shouldExcludeRoute(route.path, llmsConfig?.excludeRoutes)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (route.path === '/') {\n\t\t\trootRoutes.push(route);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst firstSegment = route.path.split('/').filter(Boolean)[0];\n\t\tif (!firstSegment) {\n\t\t\trootRoutes.push(route);\n\t\t} else {\n\t\t\tif (!sections.has(firstSegment)) {\n\t\t\t\tsections.set(firstSegment, []);\n\t\t\t}\n\t\t\tsections.get(firstSegment)?.push(route);\n\t\t}\n\t}\n\n\treturn { sections, rootRoutes };\n}\n\nfunction formatRouteUrl(routePath: string, baseUrl: string): string {\n\tconst urlPath = routePath === '/' ? '/index' : routePath;\n\treturn `${baseUrl}${urlPath}.txt`;\n}\n\nfunction getRouteTitle(route: RouteEntry): string {\n\treturn (\n\t\troute.title ||\n\t\t(route.path === '/' ? 'Home' : route.path.split('/').pop() || 'Page')\n\t);\n}\n\nfunction addRootRoutes(\n\tparts: string[],\n\trootRoutes: RouteEntry[],\n\tbaseUrl: string,\n\tisSingleCollection: boolean,\n): void {\n\tif (isSingleCollection || rootRoutes.length === 0) return;\n\n\tfor (const route of rootRoutes) {\n\t\tconst title = getRouteTitle(route);\n\t\tconst url = formatRouteUrl(route.path, baseUrl);\n\t\tparts.push(`- [${title}](${url})`);\n\t}\n\tparts.push('');\n}\n\nfunction addCollectionSection(\n\tparts: string[],\n\tcollection: string,\n\troutes: RouteEntry[],\n\tbaseUrl: string,\n\tllmsConfig?: LLMsOptions,\n): void {\n\tconst filteredRoutes = routes.filter(\n\t\t(r) => !shouldExcludeRoute(r.path, llmsConfig?.excludeRoutes),\n\t);\n\n\tif (filteredRoutes.length === 0) return;\n\n\tconst sectionName = collection.charAt(0).toUpperCase() + collection.slice(1);\n\tparts.push(`## ${sectionName}`);\n\tparts.push('');\n\n\tfor (const route of filteredRoutes) {\n\t\tconst title = route.title || route.path.split('/').pop() || 'Untitled';\n\t\tconst url = `${baseUrl}${route.path}.txt`;\n\t\tparts.push(`- [${title}](${url})`);\n\t}\n\tparts.push('');\n}\n\nfunction shouldIncludeSection(\n\tsection: string,\n\tisSingleCollection: boolean,\n\ttargetCollection: string | null,\n): boolean {\n\treturn !isSingleCollection || section === targetCollection;\n}\n\nfunction addSSRDataSection(\n\tparts: string[],\n\troutePattern: string,\n\troutes: RouteEntry[],\n\tbaseUrl: string,\n\tisSingleCollection: boolean,\n\ttargetCollection: string | null,\n\tllmsConfig?: LLMsOptions,\n): void {\n\tconst routeSection = routePattern.split('/').filter(Boolean)[0];\n\n\tif (\n\t\t!shouldIncludeSection(routeSection, isSingleCollection, targetCollection)\n\t) {\n\t\treturn;\n\t}\n\n\tconst filteredRoutes = routes.filter(\n\t\t(r) => !shouldExcludeRoute(r.path, llmsConfig?.excludeRoutes),\n\t);\n\n\tif (filteredRoutes.length === 0) return;\n\n\tconst sectionName =\n\t\trouteSection?.charAt(0).toUpperCase() + routeSection?.slice(1) || 'Content';\n\tparts.push(`## ${sectionName}`);\n\tparts.push('');\n\n\tfor (const route of filteredRoutes) {\n\t\tconst title = route.title || route.path.split('/').pop() || 'Untitled';\n\t\tconst url = `${baseUrl}${route.path}.txt`;\n\t\tparts.push(`- [${title}](${url})`);\n\t}\n\tparts.push('');\n}\n\nfunction addStaticSection(\n\tparts: string[],\n\tsection: string,\n\troutes: RouteEntry[],\n\tbaseUrl: string,\n\tisSingleCollection: boolean,\n\ttargetCollection: string | null,\n\tcollectionsMap: Map<string, RouteEntry[]>,\n\tllmsConfig?: LLMsOptions,\n): void {\n\tif (!shouldIncludeSection(section, isSingleCollection, targetCollection)) {\n\t\treturn;\n\t}\n\n\tconst filteredRoutes = routes.filter(\n\t\t(r) => !shouldExcludeRoute(r.path, llmsConfig?.excludeRoutes),\n\t);\n\n\tif (filteredRoutes.length === 0 || collectionsMap.has(section)) return;\n\n\tconst sectionName = section.charAt(0).toUpperCase() + section.slice(1);\n\tparts.push(`## ${sectionName}`);\n\tparts.push('');\n\n\tfor (const route of filteredRoutes) {\n\t\tconst title = route.title || route.path.split('/').pop() || 'Untitled';\n\t\tconst url = `${baseUrl}${route.path}.txt`;\n\t\tparts.push(`- [${title}](${url})`);\n\t}\n\tparts.push('');\n}\n\n/**\n * Generate /llms.txt index\n * Simple, token-efficient format: just URLs grouped by section\n */\nexport async function generateLLMsIndex(options: {\n\tcwd: string;\n\tcollections: string[];\n\tbaseUrl: string;\n\tisWatchMode: boolean;\n\tllmsConfig?: LLMsOptions;\n}): Promise<string> {\n\tconst { cwd, collections, baseUrl, isWatchMode, llmsConfig } = options;\n\n\tconst parts: string[] = [];\n\taddIndexHeader(parts, llmsConfig);\n\n\tconst staticRoutes = await discoverStaticRoutes(cwd, isWatchMode);\n\tconst collectionsMap = await discoverCollectionRoutes(\n\t\tcwd,\n\t\tcollections,\n\t\tisWatchMode,\n\t\tllmsConfig,\n\t);\n\tconst ssrDataRoutes = await discoverSSRDataRoutes(\n\t\tcwd,\n\t\tstaticRoutes,\n\t\tisWatchMode,\n\t);\n\n\tconst isSingleCollection = collections.length === 1;\n\tconst targetCollection = isSingleCollection ? collections[0] : null;\n\n\tconst { sections, rootRoutes } = groupStaticRoutes(staticRoutes, llmsConfig);\n\n\taddRootRoutes(parts, rootRoutes, baseUrl, isSingleCollection);\n\n\tfor (const [collection, routes] of collectionsMap.entries()) {\n\t\tif (routes.length > 0) {\n\t\t\taddCollectionSection(parts, collection, routes, baseUrl, llmsConfig);\n\t\t}\n\t}\n\n\tfor (const [routePattern, routes] of ssrDataRoutes.entries()) {\n\t\tif (routes.length > 0) {\n\t\t\taddSSRDataSection(\n\t\t\t\tparts,\n\t\t\t\troutePattern,\n\t\t\t\troutes,\n\t\t\t\tbaseUrl,\n\t\t\t\tisSingleCollection,\n\t\t\t\ttargetCollection,\n\t\t\t\tllmsConfig,\n\t\t\t);\n\t\t}\n\t}\n\n\tfor (const [section, routes] of sections.entries()) {\n\t\tif (routes.length > 0) {\n\t\t\taddStaticSection(\n\t\t\t\tparts,\n\t\t\t\tsection,\n\t\t\t\troutes,\n\t\t\t\tbaseUrl,\n\t\t\t\tisSingleCollection,\n\t\t\t\ttargetCollection,\n\t\t\t\tcollectionsMap,\n\t\t\t\tllmsConfig,\n\t\t\t);\n\t\t}\n\t}\n\n\tparts.push('---');\n\tparts.push('');\n\tparts.push(\n\t\t'Formats: .txt | .md | Accept: text/plain | Accept: text/markdown',\n\t);\n\n\treturn parts.join('\\n');\n}\n",
@@ -39,7 +39,7 @@
39
39
  "export * from './discovery';\nexport * from './generator';\nexport * from './policies';\n",
40
40
  "export * from './discovery';\nexport * from './generator';\n",
41
41
  "export * from './discovery';\nexport * from './generator';\n",
42
- "import type { Span } from '@opentelemetry/api';\nimport { cloneElement, type ReactElement } from 'react';\nimport { renderToReadableStream } from 'react-dom/server';\nimport {\n\tgetTraceContextForInjection,\n\twithParentSpan,\n\twithSpan,\n} from 'reroute-js/telemetry/server';\nimport { loadConfig, type OGImageOptions, type OGOptions } from '../config';\nimport {\n\tcleanupPathScopedSSRData,\n\tcreateDataScript,\n\tcreateFeedsScript,\n\tcreateLlmsScript,\n\ttype Doc,\n\tgenerateCollectionScripts,\n\tperformSSRSetup,\n\ttype SSR,\n} from './lib';\nimport {\n\tdeduplicateMetaTags,\n\tloadIndexHtml,\n\tremoveOverriddenMetaTags,\n} from './lib/html';\nimport { isThenable } from './lib/imports';\nimport { splitTemplate } from './lib/template';\n\ntype StreamingSSROptions = {\n\tpathname: string;\n\trootComponent: ReactElement;\n\tclientDir: string;\n\tcwd: string;\n\tisWatchMode: boolean;\n\tbundleUrl: string;\n\tcachedCollections?: Record<string, unknown[]>;\n\tcachedTailwindCSS?: string;\n\tcachedIndexHtml?: string;\n\tdebug?: boolean;\n\thead?: string;\n\tlang?: string;\n\tappId?: string;\n\tmaxAge?: number;\n\tsearchParams?: URLSearchParams;\n\togConfig?: OGImageOptions;\n\togMetaConfig?: OGOptions;\n\tbaseUrl?: string;\n\tautoCanonical?: boolean;\n\tparentSpan?: Span | null;\n\t/** Request headers from the incoming HTTP request */\n\theaders?: Record<string, string>;\n\t/** Maximum streaming timeout in milliseconds (default: 120000 / 120s) */\n\ttimeout?: number;\n\t/** Suffix to append to all page titles */\n\ttitleSuffix?: string;\n\t/** Hydrated i18n state (opt-in) */\n\ti18n?: Record<string, unknown>;\n};\n\ntype StreamingSSRResult = {\n\tstream: ReadableStream<Uint8Array>;\n\tstatus: number;\n};\n\n/**\n * Render a React component to a streaming HTML response.\n * Uses React 19's streaming with progressive Suspense resolution.\n */\nasync function renderSSRDocumentStream(\n\toptions: StreamingSSROptions,\n): Promise<StreamingSSRResult> {\n\tconst debug = options.debug ?? false;\n\tconst t0 = debug ? performance.now() : 0;\n\tconst {\n\t\tpathname,\n\t\trootComponent,\n\t\tclientDir,\n\t\tcwd,\n\t\tisWatchMode,\n\t\tbundleUrl,\n\t\thead = '',\n\t\tlang = 'en',\n\t\tappId = 'root',\n\t\tmaxAge = 0,\n\t\tsearchParams,\n\t\togConfig,\n\t} = options;\n\n\tif (debug) console.log(`[renderStream] ${pathname} - start: 0ms`);\n\n\t// Perform shared SSR setup\n\tconst setup = await performSSRSetup(\n\t\t{\n\t\t\tpathname,\n\t\t\tclientDir,\n\t\t\tcwd,\n\t\t\tisWatchMode,\n\t\t\tparentSpan: options.parentSpan,\n\t\t\tbundleUrl,\n\t\t\tmaxAge,\n\t\t\tsearchParams,\n\t\t\togConfig,\n\t\t\togMetaConfig: options.ogMetaConfig,\n\t\t\tbaseUrl: options.baseUrl,\n\t\t\tautoCanonical: options.autoCanonical,\n\t\t\tcachedCollections: options.cachedCollections,\n\t\t\tcachedTailwindCSS: options.cachedTailwindCSS,\n\t\t\tdebug,\n\t\t\theaders: options.headers,\n\t\t\ttitleSuffix: options.titleSuffix,\n\t\t\ttimeout: options.timeout,\n\t\t},\n\t\ttrue, // streaming mode\n\t);\n\tif (debug)\n\t\tconsole.log(\n\t\t\t`[renderStream] ${pathname} - performSSRSetup: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t);\n\n\t// Determine status (only override if value is set)\n\tlet statusOverride = setup.preloadStatusOverride;\n\tif (setup.statusContainer.value !== undefined) {\n\t\tstatusOverride = setup.statusContainer.value;\n\t}\n\tif (setup.metadataResult.statusOverride !== undefined) {\n\t\tstatusOverride = setup.metadataResult.statusOverride;\n\t}\n\n\t// Set up streaming\n\tconst encoder = new TextEncoder();\n\tconst { readable, writable } = new TransformStream<Uint8Array>();\n\tconst writer = writable.getWriter();\n\n\t// Load and split template (use cached if available)\n\tconst usingCache = !!options.cachedIndexHtml;\n\tconst { htmlHead, rootStart, rootEnd, htmlTail } = await withSpan(\n\t\t'ssr.load.template',\n\t\tasync (span) => {\n\t\t\tconst template = options.cachedIndexHtml\n\t\t\t\t? options.cachedIndexHtml\n\t\t\t\t: await loadIndexHtml(clientDir);\n\n\t\t\tspan.setAttribute('reroute.cached', usingCache);\n\t\t\tspan.setAttribute('reroute.template.size', template.length);\n\n\t\t\tif (debug)\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[renderStream] ${pathname} - loadIndexHtml (cached: ${usingCache}): ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t\t);\n\n\t\t\tconst parts = splitTemplate(template, appId);\n\n\t\t\tif (debug)\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[renderStream] ${pathname} - splitTemplate: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t\t);\n\n\t\t\treturn {\n\t\t\t\t...parts,\n\t\t\t};\n\t\t},\n\t);\n\n\t// Build head with lang attribute (replace existing lang or add new one)\n\tconst i18nLocale = options.i18n?.enabled\n\t\t? String(options.i18n.locale || '')\n\t\t: '';\n\tconst pageLang = setup.metadataResult.pageLang || i18nLocale || lang;\n\tlet headWithLang = htmlHead.replace(/<html([^>]*)>/i, (_m, attrs: string) => {\n\t\tconst hasLang = /(^|\\s)lang\\s*=/.test(attrs);\n\t\tconst newAttrs = hasLang\n\t\t\t? attrs.replace(\n\t\t\t\t\t/lang\\s*=\\s*(\"[^\"]*\"|'[^']*'|[^\\s>]+)/i,\n\t\t\t\t\t`lang=\"${pageLang}\"`,\n\t\t\t\t)\n\t\t\t: `${attrs} lang=\"${pageLang}\"`;\n\t\treturn `<html${newAttrs}>`;\n\t});\n\n\t// Build extra head content\n\tconst extraHead =\n\t\tsetup.bundlePreload +\n\t\tsetup.preloadExtraHead +\n\t\tsetup.metadataResult.perPageHead;\n\n\t// Remove default title/description from template if we have page-specific ones\n\tif (/<title[\\s\\S]*?<\\/title>/i.test(extraHead)) {\n\t\theadWithLang = headWithLang.replace(/<title[\\s\\S]*?<\\/title>/i, '');\n\t}\n\tif (/<meta\\s+name\\s*=\\s*['\"]description['\"][^>]*>/i.test(extraHead)) {\n\t\theadWithLang = headWithLang.replace(\n\t\t\t/<meta\\s+name\\s*=\\s*['\"]description['\"][^>]*>/i,\n\t\t\t'',\n\t\t);\n\t}\n\n\t// Remove OG/Twitter meta tags from template that will be overridden\n\theadWithLang = removeOverriddenMetaTags(headWithLang, extraHead);\n\n\t// Load config to get browser telemetry settings\n\tconst config = await loadConfig(cwd);\n\tconst browserTelemetryConfigRaw = config.telemetry?.browser as\n\t\t| Record<string, unknown>\n\t\t| undefined;\n\n\t// Serialize browser telemetry config (convert functions to strings for JSON)\n\tconst { serializeBrowserTelemetryConfig } = await import('./lib/serialize');\n\tconst browserTelemetryConfig = serializeBrowserTelemetryConfig(\n\t\tbrowserTelemetryConfigRaw,\n\t);\n\n\t// Extract trace context from parent span for distributed tracing\n\tconst traceContext = getTraceContextForInjection(options.parentSpan);\n\n\t// Start streaming in background\n\tstreamSSRContent(writer, encoder, {\n\t\trootComponent,\n\t\tpathname,\n\t\tsearchParams,\n\t\theadWithLang,\n\t\thead,\n\t\textraHead,\n\t\tinlineStyleTag: setup.inlineStyleTag,\n\t\tpageLang,\n\t\trootStart,\n\t\trootEnd,\n\t\thtmlTail,\n\t\tbundleUrl,\n\t\tisWatchMode,\n\t\tdebug,\n\t\tssrData: setup.ssrData,\n\t\tssrError: setup.ssrError,\n\t\tbyCollectionForSSR: setup.byCollectionForSSR,\n\t\tpreloadHydrationScript: setup.preloadHydrationScript,\n\t\tbrowserTelemetryConfig,\n\t\ttraceContext,\n\t\tparentSpan: options.parentSpan,\n\t\ttimeout: options.timeout,\n\t\tssrExport: setup.metadataResult.ssrExport,\n\t\ttitleSuffix: options.titleSuffix,\n\t\ti18n: options.i18n,\n\t});\n\n\tif (debug)\n\t\tconsole.log(\n\t\t\t`[renderStream] ${pathname} - returning stream: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t);\n\treturn { stream: readable, status: statusOverride || 200 };\n}\n\ntype StreamContext = {\n\trootComponent: ReactElement;\n\tpathname: string;\n\tsearchParams?: URLSearchParams;\n\theadWithLang: string;\n\thead: string;\n\textraHead: string;\n\tinlineStyleTag: string;\n\tpageLang: string;\n\trootStart: string;\n\trootEnd: string;\n\thtmlTail: string;\n\tbundleUrl: string;\n\tisWatchMode: boolean;\n\tdebug: boolean;\n\tssrData: Record<string, unknown>;\n\tssrError?: string;\n\tbyCollectionForSSR: Record<string, unknown[]>;\n\tpreloadHydrationScript: string;\n\tbrowserTelemetryConfig?: Record<string, unknown>;\n\ttraceContext?: { traceparent?: string; tracestate?: string };\n\tparentSpan?: Span | null;\n\ttimeout?: number;\n\t/** SSR export for dynamic head generation at stream end */\n\tssrExport?: SSR;\n\t/** Suffix to append to page titles */\n\ttitleSuffix?: string;\n\t/** Hydrated i18n state (opt-in) */\n\ti18n?: Record<string, unknown>;\n};\n\n/**\n * Stream SSR content progressively\n * NOTE: This runs during the HTTP request lifecycle - Elysia waits for the stream\n * to complete before calling onAfterResponse\n */\nasync function streamSSRContent(\n\twriter: WritableStreamDefaultWriter<Uint8Array>,\n\tencoder: TextEncoder,\n\tctx: StreamContext,\n): Promise<void> {\n\t// Execute within parent span context to properly nest spans\n\treturn withParentSpan(ctx.parentSpan, async () => {\n\t\tconst t0 = ctx.debug ? performance.now() : 0;\n\t\t// Set a maximum streaming timeout to prevent server hangs\n\t\t// This ensures the stream always completes even if React is waiting for promises\n\t\t// Default to 120 seconds, but allow configuration for long operations like AI analysis\n\t\tconst STREAM_TIMEOUT_MS = ctx.timeout ?? 120000;\n\t\tlet streamTimedOut = false;\n\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n\t\tconst cleanup = () => {\n\t\t\tif (timeoutId) {\n\t\t\t\tclearTimeout(timeoutId);\n\t\t\t\ttimeoutId = null;\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\t// 1. Send HTML head immediately (shell)\n\t\t\tconst combinedHead = deduplicateMetaTags(\n\t\t\t\t[ctx.inlineStyleTag, ctx.head, ctx.extraHead]\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join('\\n'),\n\t\t\t);\n\t\t\t// Inject combined head BEFORE </head> (lang is already handled in headWithLang)\n\t\t\tconst headWithLangAndContent = ctx.headWithLang.replace(\n\t\t\t\t/<\\/head>/i,\n\t\t\t\t`${combinedHead ? `${combinedHead}\\n` : ''}</head>`,\n\t\t\t);\n\t\t\tconst headContent = `${headWithLangAndContent}`;\n\t\t\tawait writer.write(encoder.encode(headContent));\n\t\t\tif (ctx.debug)\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[Stream] ${ctx.pathname} - first byte written: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t\t);\n\n\t\t\t// 2. Send root div start\n\t\t\tawait writer.write(encoder.encode(ctx.rootStart));\n\n\t\t\t// 3. Stream React content (both create and pipe)\n\t\t\t// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Stream creation and piping requires timeout handling\n\t\t\tawait withSpan('ssr.document.stream', async (span) => {\n\t\t\t\tconst componentWithPathname = cloneElement(ctx.rootComponent, {\n\t\t\t\t\tpathname: ctx.pathname,\n\t\t\t\t\tsearchParams: ctx.searchParams,\n\t\t\t\t} as Doc);\n\n\t\t\t\tspan.setAttribute('reroute.pathname', ctx.pathname);\n\n\t\t\t\tlet streamError: Error | null = null;\n\t\t\t\tconst streamPromise = renderToReadableStream(componentWithPathname, {\n\t\t\t\t\tonError(error) {\n\t\t\t\t\t\tconsole.error('[reroute] SSR stream error:', error);\n\t\t\t\t\t\tstreamError =\n\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t},\n\t\t\t\t}).catch((err) => {\n\t\t\t\t\tstreamError = err;\n\t\t\t\t\tthrow err;\n\t\t\t\t});\n\n\t\t\t\tconst reactStream = await streamPromise;\n\t\t\t\tif (streamError) throw streamError;\n\n\t\t\t\t// Pipe React stream to writer\n\t\t\t\t// Set up streaming timeout - if React takes too long, force close\n\t\t\t\tconst streamTimeoutPromise = new Promise<{\n\t\t\t\t\tdone: true;\n\t\t\t\t\tvalue: undefined;\n\t\t\t\t}>((resolve) => {\n\t\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`[reroute] Stream timeout after ${STREAM_TIMEOUT_MS}ms for ${ctx.pathname}, forcing close`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tstreamTimedOut = true;\n\t\t\t\t\t\tresolve({ done: true, value: undefined });\n\t\t\t\t\t}, STREAM_TIMEOUT_MS);\n\t\t\t\t});\n\n\t\t\t\tconst reader = reactStream.getReader();\n\t\t\t\tlet chunkCount = 0;\n\t\t\t\twhile (true) {\n\t\t\t\t\t// Race between getting next chunk and timeout\n\t\t\t\t\tconst result = await Promise.race([\n\t\t\t\t\t\treader.read(),\n\t\t\t\t\t\tstreamTimeoutPromise,\n\t\t\t\t\t]);\n\n\t\t\t\t\tif (result.done || streamTimedOut) {\n\t\t\t\t\t\tif (streamTimedOut) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait reader.cancel(\n\t\t\t\t\t\t\t\t\t`[reroute] stream timeout for ${ctx.pathname}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} catch {}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Release the reader lock before breaking\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treader.releaseLock();\n\t\t\t\t\t\t} catch {}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif (result.value) {\n\t\t\t\t\t\t// Decode, obfuscate emails, and re-encode if needed\n\t\t\t\t\t\tawait writer.write(result.value);\n\t\t\t\t\t\tchunkCount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tcleanup();\n\n\t\t\t\tspan.setAttributes({\n\t\t\t\t\t'reroute.stream.chunks': chunkCount,\n\t\t\t\t\t'reroute.stream.timedOut': streamTimedOut,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (streamTimedOut) {\n\t\t\t\tcleanupPathScopedSSRData(ctx.pathname);\n\t\t\t}\n\n\t\t\t// 4. Close root div\n\t\t\tawait writer.write(encoder.encode(ctx.rootEnd));\n\n\t\t\t// 5. Generate scripts\n\t\t\tconst allScripts = await withSpan(\n\t\t\t\t'ssr.generate.scripts',\n\t\t\t\tasync (span) => {\n\t\t\t\t\tconst scripts = buildStreamingScripts(ctx);\n\t\t\t\t\tspan.setAttribute('reroute.script_size', scripts.length);\n\t\t\t\t\treturn scripts;\n\t\t\t\t},\n\t\t\t);\n\t\t\tawait writer.write(encoder.encode(allScripts + ctx.htmlTail));\n\t\t\tawait writer.close();\n\t\t} catch (error) {\n\t\t\tcleanup();\n\t\t\tcleanupPathScopedSSRData(ctx.pathname);\n\t\t\tconsole.error('[reroute] Stream error:', error);\n\t\t\ttry {\n\t\t\t\tawait writer.abort(error);\n\t\t\t} catch {\n\t\t\t\t// Writer might already be closed\n\t\t\t}\n\t\t}\n\t});\n}\n\n/**\n * Build all scripts for streaming SSR\n */\nfunction buildStreamingScripts(ctx: StreamContext): string {\n\t// Generate collection scripts\n\tconst collectionScripts = generateCollectionScripts(ctx.byCollectionForSSR);\n\n\t// Create snapshot of resolved SSR data\n\tconst ssrDataSnapshot: Record<string, unknown> = {};\n\tfor (const key of Object.keys(ctx.ssrData)) {\n\t\tconst value = ctx.ssrData[key];\n\t\tif (!isThenable(value)) {\n\t\t\tssrDataSnapshot[key] = value;\n\t\t}\n\t}\n\n\t// Build scripts\n\tconst dataScript = createDataScript(\n\t\tssrDataSnapshot,\n\t\tctx.isWatchMode ? ctx.ssrError : undefined,\n\t\tctx.pathname,\n\t\tctx.browserTelemetryConfig,\n\t\tctx.traceContext,\n\t\tctx.titleSuffix,\n\t\tctx.i18n,\n\t);\n\tconst feedsScript = createFeedsScript();\n\tconst llmsScript = createLlmsScript();\n\n\tlet allScripts =\n\t\tdataScript +\n\t\tfeedsScript +\n\t\tllmsScript +\n\t\tcollectionScripts +\n\t\tctx.preloadHydrationScript;\n\n\t// Generate meta update script if route has dynamic head function\n\tconst metaUpdateScript = generateMetaUpdateScript(ctx, ssrDataSnapshot);\n\tif (metaUpdateScript) {\n\t\tallScripts += metaUpdateScript;\n\t}\n\n\t// Add bundle script\n\tallScripts += `<script type=\"module\" src=\"${ctx.bundleUrl}\"></script>`;\n\n\t// Add dev watcher\n\tif (ctx.isWatchMode) {\n\t\tallScripts += `<script type=\"module\" src=\"/__reroute_watch.js\"></script>`;\n\t}\n\n\treturn allScripts;\n}\n\n/**\n * Apply titleSuffix to title-related fields in meta updates\n */\nfunction applyTitleSuffixToMetaUpdates(\n\tmetaUpdates: Record<string, string>,\n\ttitleSuffix: string,\n): void {\n\tif (metaUpdates.title && !metaUpdates.title.endsWith(titleSuffix)) {\n\t\tmetaUpdates.title = metaUpdates.title + titleSuffix;\n\t}\n\tif (\n\t\tmetaUpdates['og:title'] &&\n\t\t!metaUpdates['og:title'].endsWith(titleSuffix)\n\t) {\n\t\tmetaUpdates['og:title'] = metaUpdates['og:title'] + titleSuffix;\n\t}\n\tif (\n\t\tmetaUpdates['twitter:title'] &&\n\t\t!metaUpdates['twitter:title'].endsWith(titleSuffix)\n\t) {\n\t\tmetaUpdates['twitter:title'] = metaUpdates['twitter:title'] + titleSuffix;\n\t}\n}\n\n/**\n * Generate a script to update head meta tags at stream end.\n * This is used when streaming SSR needs to update dynamic meta tags\n * after data has resolved.\n */\nfunction generateMetaUpdateScript(\n\tctx: StreamContext,\n\tssrDataSnapshot: Record<string, unknown>,\n): string {\n\t// Only generate if route has dynamic head function\n\tif (typeof ctx.ssrExport?.head !== 'function') {\n\t\treturn '';\n\t}\n\n\t// Get the resolved route data\n\tconst routeData = ssrDataSnapshot[ctx.pathname];\n\tif (!routeData) {\n\t\treturn '';\n\t}\n\n\t// Call the head function with resolved data\n\tlet headResult: string | string[] | undefined;\n\ttry {\n\t\theadResult = ctx.ssrExport.head({ data: routeData });\n\t} catch (err) {\n\t\tconsole.error('[reroute] Error calling ssr.head() at stream end:', err);\n\t\treturn '';\n\t}\n\n\tif (!headResult) {\n\t\treturn '';\n\t}\n\n\t// Convert to string\n\tconst headHtml = Array.isArray(headResult)\n\t\t? headResult.join('\\n')\n\t\t: headResult;\n\tif (!headHtml) {\n\t\treturn '';\n\t}\n\n\t// Parse the head HTML to extract meta tag values\n\tconst metaUpdates = parseHeadForMetaUpdates(headHtml);\n\tif (Object.keys(metaUpdates).length === 0) {\n\t\treturn '';\n\t}\n\n\t// Apply titleSuffix to title and related meta tags\n\tif (ctx.titleSuffix) {\n\t\tapplyTitleSuffixToMetaUpdates(metaUpdates, ctx.titleSuffix);\n\t}\n\n\t// Generate inline script to update the head\n\tconst updatesJson = JSON.stringify(metaUpdates);\n\treturn `<script>(function(){var u=${updatesJson};if(u.title){document.title=u.title}Object.keys(u).forEach(function(k){if(k==='title')return;var s=k.split(':');var isOg=s[0]==='og'||s[0]==='twitter';var el=isOg?document.querySelector('meta[property=\"'+k+'\"]')||document.querySelector('meta[name=\"'+k+'\"]'):document.querySelector('meta[name=\"'+k+'\"]');if(el){el.setAttribute('content',u[k])}else{var m=document.createElement('meta');m.setAttribute(isOg?'property':'name',k);m.setAttribute('content',u[k]);document.head.appendChild(m)}})})()</script>`;\n}\n\n/**\n * Parse head HTML to extract values for meta tag updates\n */\nfunction parseHeadForMetaUpdates(headHtml: string): Record<string, string> {\n\tconst updates: Record<string, string> = {};\n\n\t// Extract title\n\tconst titleMatch = headHtml.match(/<title[^>]*>(.*?)<\\/title>/is);\n\tif (titleMatch?.[1]) {\n\t\tupdates.title = unescapeHtmlEntities(titleMatch[1].trim());\n\t}\n\n\t// Extract meta description\n\tlet descMatch = headHtml.match(\n\t\t/<meta\\s+name=[\"']description[\"']\\s+content=[\"'](.+?)[\"']/i,\n\t);\n\tif (!descMatch) {\n\t\tdescMatch = headHtml.match(\n\t\t\t/<meta\\s+content=[\"'](.+?)[\"']\\s+name=[\"']description[\"']/i,\n\t\t);\n\t}\n\tif (descMatch?.[1]) {\n\t\tupdates.description = unescapeHtmlEntities(descMatch[1].trim());\n\t}\n\n\t// Extract og:title\n\tlet ogTitleMatch = headHtml.match(\n\t\t/<meta\\s+property=[\"']og:title[\"']\\s+content=[\"'](.+?)[\"']/i,\n\t);\n\tif (!ogTitleMatch) {\n\t\togTitleMatch = headHtml.match(\n\t\t\t/<meta\\s+content=[\"'](.+?)[\"']\\s+property=[\"']og:title[\"']/i,\n\t\t);\n\t}\n\tif (ogTitleMatch?.[1]) {\n\t\tupdates['og:title'] = unescapeHtmlEntities(ogTitleMatch[1].trim());\n\t} else if (updates.title) {\n\t\t// Fallback: use title for og:title\n\t\tupdates['og:title'] = updates.title;\n\t}\n\n\t// Extract og:description\n\tlet ogDescMatch = headHtml.match(\n\t\t/<meta\\s+property=[\"']og:description[\"']\\s+content=[\"'](.+?)[\"']/i,\n\t);\n\tif (!ogDescMatch) {\n\t\togDescMatch = headHtml.match(\n\t\t\t/<meta\\s+content=[\"'](.+?)[\"']\\s+property=[\"']og:description[\"']/i,\n\t\t);\n\t}\n\tif (ogDescMatch?.[1]) {\n\t\tupdates['og:description'] = unescapeHtmlEntities(ogDescMatch[1].trim());\n\t} else if (updates.description) {\n\t\t// Fallback: use description for og:description\n\t\tupdates['og:description'] = updates.description;\n\t}\n\n\t// Extract twitter:title\n\tlet twitterTitleMatch = headHtml.match(\n\t\t/<meta\\s+name=[\"']twitter:title[\"']\\s+content=[\"'](.+?)[\"']/i,\n\t);\n\tif (!twitterTitleMatch) {\n\t\ttwitterTitleMatch = headHtml.match(\n\t\t\t/<meta\\s+content=[\"'](.+?)[\"']\\s+name=[\"']twitter:title[\"']/i,\n\t\t);\n\t}\n\tif (twitterTitleMatch?.[1]) {\n\t\tupdates['twitter:title'] = unescapeHtmlEntities(\n\t\t\ttwitterTitleMatch[1].trim(),\n\t\t);\n\t} else if (updates.title) {\n\t\t// Fallback: use title for twitter:title\n\t\tupdates['twitter:title'] = updates.title;\n\t}\n\n\t// Extract twitter:description\n\tlet twitterDescMatch = headHtml.match(\n\t\t/<meta\\s+name=[\"']twitter:description[\"']\\s+content=[\"'](.+?)[\"']/i,\n\t);\n\tif (!twitterDescMatch) {\n\t\ttwitterDescMatch = headHtml.match(\n\t\t\t/<meta\\s+content=[\"'](.+?)[\"']\\s+name=[\"']twitter:description[\"']/i,\n\t\t);\n\t}\n\tif (twitterDescMatch?.[1]) {\n\t\tupdates['twitter:description'] = unescapeHtmlEntities(\n\t\t\ttwitterDescMatch[1].trim(),\n\t\t);\n\t} else if (updates.description) {\n\t\t// Fallback: use description for twitter:description\n\t\tupdates['twitter:description'] = updates.description;\n\t}\n\n\treturn updates;\n}\n\n/**\n * Unescape HTML entities\n */\nfunction unescapeHtmlEntities(str: string): string {\n\treturn str\n\t\t.replace(/&quot;/g, '\"')\n\t\t.replace(/&#39;/g, \"'\")\n\t\t.replace(/&lt;/g, '<')\n\t\t.replace(/&gt;/g, '>')\n\t\t.replace(/&amp;/g, '&');\n}\n\nexport { renderSSRDocumentStream };\nexport type { StreamingSSROptions, StreamingSSRResult };\n",
42
+ "import type { Span } from '@opentelemetry/api';\nimport { cloneElement, type ReactElement } from 'react';\nimport { renderToReadableStream } from 'react-dom/server';\nimport {\n\tgetTraceContextForInjection,\n\twithParentSpan,\n\twithSpan,\n} from 'reroute-js/telemetry/server';\nimport { loadConfig, type OGImageOptions, type OGOptions } from '../config';\nimport {\n\tcleanupPathScopedSSRData,\n\tcreateDataScript,\n\tcreateFeedsScript,\n\tcreateLlmsScript,\n\ttype Doc,\n\tgenerateCollectionScripts,\n\tperformSSRSetup,\n\ttype SSR,\n} from './lib';\nimport {\n\tdeduplicateMetaTags,\n\tloadIndexHtml,\n\tremoveOverriddenMetaTags,\n} from './lib/html';\nimport { isThenable } from './lib/imports';\nimport { splitTemplate } from './lib/template';\n\ntype StreamingSSROptions = {\n\tpathname: string;\n\trootComponent: ReactElement;\n\tclientDir: string;\n\tcwd: string;\n\tisWatchMode: boolean;\n\tbundleUrl: string;\n\tcachedCollections?: Record<string, unknown[]>;\n\tcachedThemeCSS?: string;\n\tcachedIndexHtml?: string;\n\tdebug?: boolean;\n\thead?: string;\n\tlang?: string;\n\tappId?: string;\n\tmaxAge?: number;\n\tsearchParams?: URLSearchParams;\n\togConfig?: OGImageOptions;\n\togMetaConfig?: OGOptions;\n\tbaseUrl?: string;\n\tautoCanonical?: boolean;\n\tparentSpan?: Span | null;\n\t/** Request headers from the incoming HTTP request */\n\theaders?: Record<string, string>;\n\t/** Maximum streaming timeout in milliseconds (default: 120000 / 120s) */\n\ttimeout?: number;\n\t/** Suffix to append to all page titles */\n\ttitleSuffix?: string;\n\t/** Hydrated i18n state (opt-in) */\n\ti18n?: Record<string, unknown>;\n};\n\ntype StreamingSSRResult = {\n\tstream: ReadableStream<Uint8Array>;\n\tstatus: number;\n};\n\n/**\n * Render a React component to a streaming HTML response.\n * Uses React 19's streaming with progressive Suspense resolution.\n */\nasync function renderSSRDocumentStream(\n\toptions: StreamingSSROptions,\n): Promise<StreamingSSRResult> {\n\tconst debug = options.debug ?? false;\n\tconst t0 = debug ? performance.now() : 0;\n\tconst {\n\t\tpathname,\n\t\trootComponent,\n\t\tclientDir,\n\t\tcwd,\n\t\tisWatchMode,\n\t\tbundleUrl,\n\t\thead = '',\n\t\tlang = 'en',\n\t\tappId = 'root',\n\t\tmaxAge = 0,\n\t\tsearchParams,\n\t\togConfig,\n\t} = options;\n\n\tif (debug) console.log(`[renderStream] ${pathname} - start: 0ms`);\n\n\t// Perform shared SSR setup\n\tconst setup = await performSSRSetup(\n\t\t{\n\t\t\tpathname,\n\t\t\tclientDir,\n\t\t\tcwd,\n\t\t\tisWatchMode,\n\t\t\tparentSpan: options.parentSpan,\n\t\t\tbundleUrl,\n\t\t\tmaxAge,\n\t\t\tsearchParams,\n\t\t\togConfig,\n\t\t\togMetaConfig: options.ogMetaConfig,\n\t\t\tbaseUrl: options.baseUrl,\n\t\t\tautoCanonical: options.autoCanonical,\n\t\t\tcachedCollections: options.cachedCollections,\n\t\t\tcachedThemeCSS: options.cachedThemeCSS,\n\t\t\tdebug,\n\t\t\theaders: options.headers,\n\t\t\ttitleSuffix: options.titleSuffix,\n\t\t\ttimeout: options.timeout,\n\t\t},\n\t\ttrue, // streaming mode\n\t);\n\tif (debug)\n\t\tconsole.log(\n\t\t\t`[renderStream] ${pathname} - performSSRSetup: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t);\n\n\t// Determine status (only override if value is set)\n\tlet statusOverride = setup.preloadStatusOverride;\n\tif (setup.statusContainer.value !== undefined) {\n\t\tstatusOverride = setup.statusContainer.value;\n\t}\n\tif (setup.metadataResult.statusOverride !== undefined) {\n\t\tstatusOverride = setup.metadataResult.statusOverride;\n\t}\n\n\t// Set up streaming\n\tconst encoder = new TextEncoder();\n\tconst { readable, writable } = new TransformStream<Uint8Array>();\n\tconst writer = writable.getWriter();\n\n\t// Load and split template (use cached if available)\n\tconst usingCache = !!options.cachedIndexHtml;\n\tconst { htmlHead, rootStart, rootEnd, htmlTail } = await withSpan(\n\t\t'ssr.load.template',\n\t\tasync (span) => {\n\t\t\tconst template = options.cachedIndexHtml\n\t\t\t\t? options.cachedIndexHtml\n\t\t\t\t: await loadIndexHtml(clientDir);\n\n\t\t\tspan.setAttribute('reroute.cached', usingCache);\n\t\t\tspan.setAttribute('reroute.template.size', template.length);\n\n\t\t\tif (debug)\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[renderStream] ${pathname} - loadIndexHtml (cached: ${usingCache}): ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t\t);\n\n\t\t\tconst parts = splitTemplate(template, appId);\n\n\t\t\tif (debug)\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[renderStream] ${pathname} - splitTemplate: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t\t);\n\n\t\t\treturn {\n\t\t\t\t...parts,\n\t\t\t};\n\t\t},\n\t);\n\n\t// Build head with lang attribute (replace existing lang or add new one)\n\tconst i18nLocale = options.i18n?.enabled\n\t\t? String(options.i18n.locale || '')\n\t\t: '';\n\tconst pageLang = setup.metadataResult.pageLang || i18nLocale || lang;\n\tlet headWithLang = htmlHead.replace(/<html([^>]*)>/i, (_m, attrs: string) => {\n\t\tconst hasLang = /(^|\\s)lang\\s*=/.test(attrs);\n\t\tconst newAttrs = hasLang\n\t\t\t? attrs.replace(\n\t\t\t\t\t/lang\\s*=\\s*(\"[^\"]*\"|'[^']*'|[^\\s>]+)/i,\n\t\t\t\t\t`lang=\"${pageLang}\"`,\n\t\t\t\t)\n\t\t\t: `${attrs} lang=\"${pageLang}\"`;\n\t\treturn `<html${newAttrs}>`;\n\t});\n\n\t// Build extra head content\n\tconst extraHead =\n\t\tsetup.bundlePreload +\n\t\tsetup.preloadExtraHead +\n\t\tsetup.metadataResult.perPageHead;\n\n\t// Remove default title/description from template if we have page-specific ones\n\tif (/<title[\\s\\S]*?<\\/title>/i.test(extraHead)) {\n\t\theadWithLang = headWithLang.replace(/<title[\\s\\S]*?<\\/title>/i, '');\n\t}\n\tif (/<meta\\s+name\\s*=\\s*['\"]description['\"][^>]*>/i.test(extraHead)) {\n\t\theadWithLang = headWithLang.replace(\n\t\t\t/<meta\\s+name\\s*=\\s*['\"]description['\"][^>]*>/i,\n\t\t\t'',\n\t\t);\n\t}\n\n\t// Remove OG/Twitter meta tags from template that will be overridden\n\theadWithLang = removeOverriddenMetaTags(headWithLang, extraHead);\n\n\t// Load config to get browser telemetry settings\n\tconst config = await loadConfig(cwd);\n\tconst browserTelemetryConfigRaw = config.telemetry?.browser as\n\t\t| Record<string, unknown>\n\t\t| undefined;\n\n\t// Serialize browser telemetry config (convert functions to strings for JSON)\n\tconst { serializeBrowserTelemetryConfig } = await import('./lib/serialize');\n\tconst browserTelemetryConfig = serializeBrowserTelemetryConfig(\n\t\tbrowserTelemetryConfigRaw,\n\t);\n\n\t// Extract trace context from parent span for distributed tracing\n\tconst traceContext = getTraceContextForInjection(options.parentSpan);\n\n\t// Start streaming in background\n\tstreamSSRContent(writer, encoder, {\n\t\trootComponent,\n\t\tpathname,\n\t\tsearchParams,\n\t\theadWithLang,\n\t\thead,\n\t\textraHead,\n\t\tinlineStyleTag: setup.inlineStyleTag,\n\t\tpageLang,\n\t\trootStart,\n\t\trootEnd,\n\t\thtmlTail,\n\t\tbundleUrl,\n\t\tisWatchMode,\n\t\tdebug,\n\t\tssrData: setup.ssrData,\n\t\tssrError: setup.ssrError,\n\t\tbyCollectionForSSR: setup.byCollectionForSSR,\n\t\tpreloadHydrationScript: setup.preloadHydrationScript,\n\t\tbrowserTelemetryConfig,\n\t\ttraceContext,\n\t\tparentSpan: options.parentSpan,\n\t\ttimeout: options.timeout,\n\t\tssrExport: setup.metadataResult.ssrExport,\n\t\ttitleSuffix: options.titleSuffix,\n\t\ti18n: options.i18n,\n\t});\n\n\tif (debug)\n\t\tconsole.log(\n\t\t\t`[renderStream] ${pathname} - returning stream: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t);\n\treturn { stream: readable, status: statusOverride || 200 };\n}\n\ntype StreamContext = {\n\trootComponent: ReactElement;\n\tpathname: string;\n\tsearchParams?: URLSearchParams;\n\theadWithLang: string;\n\thead: string;\n\textraHead: string;\n\tinlineStyleTag: string;\n\tpageLang: string;\n\trootStart: string;\n\trootEnd: string;\n\thtmlTail: string;\n\tbundleUrl: string;\n\tisWatchMode: boolean;\n\tdebug: boolean;\n\tssrData: Record<string, unknown>;\n\tssrError?: string;\n\tbyCollectionForSSR: Record<string, unknown[]>;\n\tpreloadHydrationScript: string;\n\tbrowserTelemetryConfig?: Record<string, unknown>;\n\ttraceContext?: { traceparent?: string; tracestate?: string };\n\tparentSpan?: Span | null;\n\ttimeout?: number;\n\t/** SSR export for dynamic head generation at stream end */\n\tssrExport?: SSR;\n\t/** Suffix to append to page titles */\n\ttitleSuffix?: string;\n\t/** Hydrated i18n state (opt-in) */\n\ti18n?: Record<string, unknown>;\n};\n\n/**\n * Stream SSR content progressively\n * NOTE: This runs during the HTTP request lifecycle - Elysia waits for the stream\n * to complete before calling onAfterResponse\n */\nasync function streamSSRContent(\n\twriter: WritableStreamDefaultWriter<Uint8Array>,\n\tencoder: TextEncoder,\n\tctx: StreamContext,\n): Promise<void> {\n\t// Execute within parent span context to properly nest spans\n\treturn withParentSpan(ctx.parentSpan, async () => {\n\t\tconst t0 = ctx.debug ? performance.now() : 0;\n\t\t// Set a maximum streaming timeout to prevent server hangs\n\t\t// This ensures the stream always completes even if React is waiting for promises\n\t\t// Default to 120 seconds, but allow configuration for long operations like AI analysis\n\t\tconst STREAM_TIMEOUT_MS = ctx.timeout ?? 120000;\n\t\tlet streamTimedOut = false;\n\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n\t\tconst cleanup = () => {\n\t\t\tif (timeoutId) {\n\t\t\t\tclearTimeout(timeoutId);\n\t\t\t\ttimeoutId = null;\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\t// 1. Send HTML head immediately (shell)\n\t\t\tconst combinedHead = deduplicateMetaTags(\n\t\t\t\t[ctx.inlineStyleTag, ctx.head, ctx.extraHead]\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join('\\n'),\n\t\t\t);\n\t\t\t// Inject combined head BEFORE </head> (lang is already handled in headWithLang)\n\t\t\tconst headWithLangAndContent = ctx.headWithLang.replace(\n\t\t\t\t/<\\/head>/i,\n\t\t\t\t`${combinedHead ? `${combinedHead}\\n` : ''}</head>`,\n\t\t\t);\n\t\t\tconst headContent = `${headWithLangAndContent}`;\n\t\t\tawait writer.write(encoder.encode(headContent));\n\t\t\tif (ctx.debug)\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[Stream] ${ctx.pathname} - first byte written: ${(performance.now() - t0).toFixed(2)}ms`,\n\t\t\t\t);\n\n\t\t\t// 2. Send root div start\n\t\t\tawait writer.write(encoder.encode(ctx.rootStart));\n\n\t\t\t// 3. Stream React content (both create and pipe)\n\t\t\t// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Stream creation and piping requires timeout handling\n\t\t\tawait withSpan('ssr.document.stream', async (span) => {\n\t\t\t\tconst componentWithPathname = cloneElement(ctx.rootComponent, {\n\t\t\t\t\tpathname: ctx.pathname,\n\t\t\t\t\tsearchParams: ctx.searchParams,\n\t\t\t\t} as Doc);\n\n\t\t\t\tspan.setAttribute('reroute.pathname', ctx.pathname);\n\n\t\t\t\tlet streamError: Error | null = null;\n\t\t\t\tconst streamPromise = renderToReadableStream(componentWithPathname, {\n\t\t\t\t\tonError(error) {\n\t\t\t\t\t\tconsole.error('[reroute] SSR stream error:', error);\n\t\t\t\t\t\tstreamError =\n\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t},\n\t\t\t\t}).catch((err) => {\n\t\t\t\t\tstreamError = err;\n\t\t\t\t\tthrow err;\n\t\t\t\t});\n\n\t\t\t\tconst reactStream = await streamPromise;\n\t\t\t\tif (streamError) throw streamError;\n\n\t\t\t\t// Pipe React stream to writer\n\t\t\t\t// Set up streaming timeout - if React takes too long, force close\n\t\t\t\tconst streamTimeoutPromise = new Promise<{\n\t\t\t\t\tdone: true;\n\t\t\t\t\tvalue: undefined;\n\t\t\t\t}>((resolve) => {\n\t\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`[reroute] Stream timeout after ${STREAM_TIMEOUT_MS}ms for ${ctx.pathname}, forcing close`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tstreamTimedOut = true;\n\t\t\t\t\t\tresolve({ done: true, value: undefined });\n\t\t\t\t\t}, STREAM_TIMEOUT_MS);\n\t\t\t\t});\n\n\t\t\t\tconst reader = reactStream.getReader();\n\t\t\t\tlet chunkCount = 0;\n\t\t\t\twhile (true) {\n\t\t\t\t\t// Race between getting next chunk and timeout\n\t\t\t\t\tconst result = await Promise.race([\n\t\t\t\t\t\treader.read(),\n\t\t\t\t\t\tstreamTimeoutPromise,\n\t\t\t\t\t]);\n\n\t\t\t\t\tif (result.done || streamTimedOut) {\n\t\t\t\t\t\tif (streamTimedOut) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait reader.cancel(\n\t\t\t\t\t\t\t\t\t`[reroute] stream timeout for ${ctx.pathname}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} catch {}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Release the reader lock before breaking\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treader.releaseLock();\n\t\t\t\t\t\t} catch {}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif (result.value) {\n\t\t\t\t\t\t// Decode, obfuscate emails, and re-encode if needed\n\t\t\t\t\t\tawait writer.write(result.value);\n\t\t\t\t\t\tchunkCount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tcleanup();\n\n\t\t\t\tspan.setAttributes({\n\t\t\t\t\t'reroute.stream.chunks': chunkCount,\n\t\t\t\t\t'reroute.stream.timedOut': streamTimedOut,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (streamTimedOut) {\n\t\t\t\tcleanupPathScopedSSRData(ctx.pathname);\n\t\t\t}\n\n\t\t\t// 4. Close root div\n\t\t\tawait writer.write(encoder.encode(ctx.rootEnd));\n\n\t\t\t// 5. Generate scripts\n\t\t\tconst allScripts = await withSpan(\n\t\t\t\t'ssr.generate.scripts',\n\t\t\t\tasync (span) => {\n\t\t\t\t\tconst scripts = buildStreamingScripts(ctx);\n\t\t\t\t\tspan.setAttribute('reroute.script_size', scripts.length);\n\t\t\t\t\treturn scripts;\n\t\t\t\t},\n\t\t\t);\n\t\t\tawait writer.write(encoder.encode(allScripts + ctx.htmlTail));\n\t\t\tawait writer.close();\n\t\t} catch (error) {\n\t\t\tcleanup();\n\t\t\tcleanupPathScopedSSRData(ctx.pathname);\n\t\t\tconsole.error('[reroute] Stream error:', error);\n\t\t\ttry {\n\t\t\t\tawait writer.abort(error);\n\t\t\t} catch {\n\t\t\t\t// Writer might already be closed\n\t\t\t}\n\t\t}\n\t});\n}\n\n/**\n * Build all scripts for streaming SSR\n */\nfunction buildStreamingScripts(ctx: StreamContext): string {\n\t// Generate collection scripts\n\tconst collectionScripts = generateCollectionScripts(ctx.byCollectionForSSR);\n\n\t// Create snapshot of resolved SSR data\n\tconst ssrDataSnapshot: Record<string, unknown> = {};\n\tfor (const key of Object.keys(ctx.ssrData)) {\n\t\tconst value = ctx.ssrData[key];\n\t\tif (!isThenable(value)) {\n\t\t\tssrDataSnapshot[key] = value;\n\t\t}\n\t}\n\n\t// Build scripts\n\tconst dataScript = createDataScript(\n\t\tssrDataSnapshot,\n\t\tctx.isWatchMode ? ctx.ssrError : undefined,\n\t\tctx.pathname,\n\t\tctx.browserTelemetryConfig,\n\t\tctx.traceContext,\n\t\tctx.titleSuffix,\n\t\tctx.i18n,\n\t);\n\tconst feedsScript = createFeedsScript();\n\tconst llmsScript = createLlmsScript();\n\n\tlet allScripts =\n\t\tdataScript +\n\t\tfeedsScript +\n\t\tllmsScript +\n\t\tcollectionScripts +\n\t\tctx.preloadHydrationScript;\n\n\t// Generate meta update script if route has dynamic head function\n\tconst metaUpdateScript = generateMetaUpdateScript(ctx, ssrDataSnapshot);\n\tif (metaUpdateScript) {\n\t\tallScripts += metaUpdateScript;\n\t}\n\n\t// Add bundle script\n\tallScripts += `<script type=\"module\" src=\"${ctx.bundleUrl}\"></script>`;\n\n\t// Add dev watcher\n\tif (ctx.isWatchMode) {\n\t\tallScripts += `<script type=\"module\" src=\"/__reroute_watch.js\"></script>`;\n\t}\n\n\treturn allScripts;\n}\n\n/**\n * Apply titleSuffix to title-related fields in meta updates\n */\nfunction applyTitleSuffixToMetaUpdates(\n\tmetaUpdates: Record<string, string>,\n\ttitleSuffix: string,\n): void {\n\tif (metaUpdates.title && !metaUpdates.title.endsWith(titleSuffix)) {\n\t\tmetaUpdates.title = metaUpdates.title + titleSuffix;\n\t}\n\tif (\n\t\tmetaUpdates['og:title'] &&\n\t\t!metaUpdates['og:title'].endsWith(titleSuffix)\n\t) {\n\t\tmetaUpdates['og:title'] = metaUpdates['og:title'] + titleSuffix;\n\t}\n\tif (\n\t\tmetaUpdates['twitter:title'] &&\n\t\t!metaUpdates['twitter:title'].endsWith(titleSuffix)\n\t) {\n\t\tmetaUpdates['twitter:title'] = metaUpdates['twitter:title'] + titleSuffix;\n\t}\n}\n\n/**\n * Generate a script to update head meta tags at stream end.\n * This is used when streaming SSR needs to update dynamic meta tags\n * after data has resolved.\n */\nfunction generateMetaUpdateScript(\n\tctx: StreamContext,\n\tssrDataSnapshot: Record<string, unknown>,\n): string {\n\t// Only generate if route has dynamic head function\n\tif (typeof ctx.ssrExport?.head !== 'function') {\n\t\treturn '';\n\t}\n\n\t// Get the resolved route data\n\tconst routeData = ssrDataSnapshot[ctx.pathname];\n\tif (!routeData) {\n\t\treturn '';\n\t}\n\n\t// Call the head function with resolved data\n\tlet headResult: string | string[] | undefined;\n\ttry {\n\t\theadResult = ctx.ssrExport.head({ data: routeData });\n\t} catch (err) {\n\t\tconsole.error('[reroute] Error calling ssr.head() at stream end:', err);\n\t\treturn '';\n\t}\n\n\tif (!headResult) {\n\t\treturn '';\n\t}\n\n\t// Convert to string\n\tconst headHtml = Array.isArray(headResult)\n\t\t? headResult.join('\\n')\n\t\t: headResult;\n\tif (!headHtml) {\n\t\treturn '';\n\t}\n\n\t// Parse the head HTML to extract meta tag values\n\tconst metaUpdates = parseHeadForMetaUpdates(headHtml);\n\tif (Object.keys(metaUpdates).length === 0) {\n\t\treturn '';\n\t}\n\n\t// Apply titleSuffix to title and related meta tags\n\tif (ctx.titleSuffix) {\n\t\tapplyTitleSuffixToMetaUpdates(metaUpdates, ctx.titleSuffix);\n\t}\n\n\t// Generate inline script to update the head\n\tconst updatesJson = JSON.stringify(metaUpdates);\n\treturn `<script>(function(){var u=${updatesJson};if(u.title){document.title=u.title}Object.keys(u).forEach(function(k){if(k==='title')return;var s=k.split(':');var isOg=s[0]==='og'||s[0]==='twitter';var el=isOg?document.querySelector('meta[property=\"'+k+'\"]')||document.querySelector('meta[name=\"'+k+'\"]'):document.querySelector('meta[name=\"'+k+'\"]');if(el){el.setAttribute('content',u[k])}else{var m=document.createElement('meta');m.setAttribute(isOg?'property':'name',k);m.setAttribute('content',u[k]);document.head.appendChild(m)}})})()</script>`;\n}\n\n/**\n * Parse head HTML to extract values for meta tag updates\n */\nfunction parseHeadForMetaUpdates(headHtml: string): Record<string, string> {\n\tconst updates: Record<string, string> = {};\n\n\t// Extract title\n\tconst titleMatch = headHtml.match(/<title[^>]*>(.*?)<\\/title>/is);\n\tif (titleMatch?.[1]) {\n\t\tupdates.title = unescapeHtmlEntities(titleMatch[1].trim());\n\t}\n\n\t// Extract meta description\n\tlet descMatch = headHtml.match(\n\t\t/<meta\\s+name=[\"']description[\"']\\s+content=[\"'](.+?)[\"']/i,\n\t);\n\tif (!descMatch) {\n\t\tdescMatch = headHtml.match(\n\t\t\t/<meta\\s+content=[\"'](.+?)[\"']\\s+name=[\"']description[\"']/i,\n\t\t);\n\t}\n\tif (descMatch?.[1]) {\n\t\tupdates.description = unescapeHtmlEntities(descMatch[1].trim());\n\t}\n\n\t// Extract og:title\n\tlet ogTitleMatch = headHtml.match(\n\t\t/<meta\\s+property=[\"']og:title[\"']\\s+content=[\"'](.+?)[\"']/i,\n\t);\n\tif (!ogTitleMatch) {\n\t\togTitleMatch = headHtml.match(\n\t\t\t/<meta\\s+content=[\"'](.+?)[\"']\\s+property=[\"']og:title[\"']/i,\n\t\t);\n\t}\n\tif (ogTitleMatch?.[1]) {\n\t\tupdates['og:title'] = unescapeHtmlEntities(ogTitleMatch[1].trim());\n\t} else if (updates.title) {\n\t\t// Fallback: use title for og:title\n\t\tupdates['og:title'] = updates.title;\n\t}\n\n\t// Extract og:description\n\tlet ogDescMatch = headHtml.match(\n\t\t/<meta\\s+property=[\"']og:description[\"']\\s+content=[\"'](.+?)[\"']/i,\n\t);\n\tif (!ogDescMatch) {\n\t\togDescMatch = headHtml.match(\n\t\t\t/<meta\\s+content=[\"'](.+?)[\"']\\s+property=[\"']og:description[\"']/i,\n\t\t);\n\t}\n\tif (ogDescMatch?.[1]) {\n\t\tupdates['og:description'] = unescapeHtmlEntities(ogDescMatch[1].trim());\n\t} else if (updates.description) {\n\t\t// Fallback: use description for og:description\n\t\tupdates['og:description'] = updates.description;\n\t}\n\n\t// Extract twitter:title\n\tlet twitterTitleMatch = headHtml.match(\n\t\t/<meta\\s+name=[\"']twitter:title[\"']\\s+content=[\"'](.+?)[\"']/i,\n\t);\n\tif (!twitterTitleMatch) {\n\t\ttwitterTitleMatch = headHtml.match(\n\t\t\t/<meta\\s+content=[\"'](.+?)[\"']\\s+name=[\"']twitter:title[\"']/i,\n\t\t);\n\t}\n\tif (twitterTitleMatch?.[1]) {\n\t\tupdates['twitter:title'] = unescapeHtmlEntities(\n\t\t\ttwitterTitleMatch[1].trim(),\n\t\t);\n\t} else if (updates.title) {\n\t\t// Fallback: use title for twitter:title\n\t\tupdates['twitter:title'] = updates.title;\n\t}\n\n\t// Extract twitter:description\n\tlet twitterDescMatch = headHtml.match(\n\t\t/<meta\\s+name=[\"']twitter:description[\"']\\s+content=[\"'](.+?)[\"']/i,\n\t);\n\tif (!twitterDescMatch) {\n\t\ttwitterDescMatch = headHtml.match(\n\t\t\t/<meta\\s+content=[\"'](.+?)[\"']\\s+name=[\"']twitter:description[\"']/i,\n\t\t);\n\t}\n\tif (twitterDescMatch?.[1]) {\n\t\tupdates['twitter:description'] = unescapeHtmlEntities(\n\t\t\ttwitterDescMatch[1].trim(),\n\t\t);\n\t} else if (updates.description) {\n\t\t// Fallback: use description for twitter:description\n\t\tupdates['twitter:description'] = updates.description;\n\t}\n\n\treturn updates;\n}\n\n/**\n * Unescape HTML entities\n */\nfunction unescapeHtmlEntities(str: string): string {\n\treturn str\n\t\t.replace(/&quot;/g, '\"')\n\t\t.replace(/&#39;/g, \"'\")\n\t\t.replace(/&lt;/g, '<')\n\t\t.replace(/&gt;/g, '>')\n\t\t.replace(/&amp;/g, '&');\n}\n\nexport { renderSSRDocumentStream };\nexport type { StreamingSSROptions, StreamingSSRResult };\n",
43
43
  "export * from './lib';\nexport * from './render';\nexport * from './stream';\n",
44
44
  "export * from './bundler';\nexport * from './config';\nexport * from './content';\nexport * from './i18n';\nexport * from './llms';\nexport * from './og';\nexport * from './robots';\nexport * from './rss';\nexport * from './sitemap';\nexport * from './ssr';\n",
45
45
  "export * from './src';\n",
@@ -49,6 +49,6 @@
49
49
  "export * from './src/server';\n"
50
50
  ],
51
51
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AA8BO,SAAS,UAAU,CAAC,YAA0C;AAAA,EACpE,MAAM,UAAU,eAAe,SAAS,KAAK,CAAC;AAAA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QAAQ,OAAO,OAAO,CAAC;AAAA,UAClD,OAAO,OAAO;AAAA,UACf,QAAQ,MAAM,oCAAoC,KAAK;AAAA,UACvD,OAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,IAAI,CAAC;AAAA;AAAA,OAG5C,EACC,IAAI,GAAG,yBAAyB,MAAM;AAAA,QACtC,OAAO;AAAA,UACN,QAAQ;AAAA,UACR,cAAc;AAAA,UACd,WAAW,IAAI,KAAK,EAAE,YAAY;AAAA,QACnC;AAAA,OACA;AAAA,IACH;AAAA,IAEA,OAAO;AAAA;AAAA;AAAA;AAAA,EA/lCT;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA;;;;ECtCA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;;;;ECJA;AAAA;",
52
- "debugId": "244EE9C4DF624C5F64756E2164756E21",
52
+ "debugId": "FF48D9F74F8695E064756E2164756E21",
53
53
  "names": []
54
54
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.46.0
2
+ * reroute-js v1.0.0-alpha.1
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.46.0
2
+ * reroute-js v1.0.0-alpha.1
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.46.0
2
+ * reroute-js v1.0.0-alpha.1
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.46.0
2
+ * reroute-js v1.0.0-alpha.1
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.46.0
2
+ * reroute-js v1.0.0-alpha.1
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.46.0
2
+ * reroute-js v1.0.0-alpha.1
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.46.0
2
+ * reroute-js v1.0.0-alpha.1
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.46.0
2
+ * reroute-js v1.0.0-alpha.1
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.46.0
2
+ * reroute-js v1.0.0-alpha.1
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.46.0
2
+ * reroute-js v1.0.0-alpha.1
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.46.0
2
+ * reroute-js v1.0.0-alpha.1
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.46.0
2
+ * reroute-js v1.0.0-alpha.1
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>