reroute-js 1.0.0-alpha.36 → 1.0.0-alpha.37

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 (224) hide show
  1. package/README.md +2 -0
  2. package/cli/bin.d.ts +1 -1
  3. package/cli/bin.js +129 -22
  4. package/cli/bin.js.map +9 -8
  5. package/cli/index.d.ts +1 -1
  6. package/cli/index.js +4 -4
  7. package/cli/index.js.map +4 -4
  8. package/cli/src/cli.d.ts +1 -1
  9. package/cli/src/commands/analyze.d.ts +1 -1
  10. package/cli/src/commands/build.d.ts +1 -1
  11. package/cli/src/commands/dev.d.ts +1 -1
  12. package/cli/src/commands/gen.d.ts +1 -1
  13. package/cli/src/commands/gen.d.ts.map +1 -1
  14. package/cli/src/commands/index.d.ts +1 -1
  15. package/cli/src/commands/init.d.ts +1 -1
  16. package/cli/src/commands/lib/assets.d.ts +1 -1
  17. package/cli/src/commands/lib/bundler.d.ts +1 -1
  18. package/cli/src/commands/lib/command.d.ts +1 -1
  19. package/cli/src/commands/lib/env.d.ts +1 -1
  20. package/cli/src/commands/lib/images.d.ts +1 -1
  21. package/cli/src/commands/lib/index.d.ts +1 -1
  22. package/cli/src/commands/lib/log.d.ts +1 -1
  23. package/cli/src/commands/lib/markdown/availability.d.ts +1 -1
  24. package/cli/src/commands/lib/markdown/index.d.ts +1 -1
  25. package/cli/src/commands/lib/markdown/processor.d.ts +1 -1
  26. package/cli/src/commands/lib/prerender.d.ts +1 -1
  27. package/cli/src/commands/lib/production.d.ts +1 -1
  28. package/cli/src/commands/lib/routes.d.ts +1 -1
  29. package/cli/src/commands/lib/server.d.ts +1 -1
  30. package/cli/src/commands/lib/ssr-strip.d.ts +33 -0
  31. package/cli/src/commands/lib/ssr-strip.d.ts.map +1 -0
  32. package/cli/src/commands/lib/static.d.ts +1 -1
  33. package/cli/src/commands/lib/streaming/analyzer.d.ts +1 -1
  34. package/cli/src/commands/lib/streaming/suspense.d.ts +1 -1
  35. package/cli/src/commands/lib/supervise.d.ts +1 -1
  36. package/cli/src/commands/lib/terminal-ui.d.ts +1 -1
  37. package/cli/src/commands/lib/theme.d.ts +1 -1
  38. package/cli/src/commands/lib/version.d.ts +1 -1
  39. package/cli/src/commands/lib/watch.d.ts +1 -1
  40. package/cli/src/commands/og.d.ts +1 -1
  41. package/cli/src/commands/start.d.ts +1 -1
  42. package/cli/src/commands/static-render.d.ts +1 -1
  43. package/cli/src/index.d.ts +1 -1
  44. package/core/index.d.ts +1 -1
  45. package/core/index.js +10 -4
  46. package/core/index.js.map +5 -5
  47. package/core/src/app-paths.d.ts +1 -1
  48. package/core/src/bundler/hash.d.ts +1 -1
  49. package/core/src/bundler/index.d.ts +1 -1
  50. package/core/src/config.d.ts +1 -1
  51. package/core/src/content/discovery.d.ts +1 -1
  52. package/core/src/content/index.d.ts +1 -1
  53. package/core/src/content/metadata.d.ts +1 -1
  54. package/core/src/i18n/catalog.d.ts +1 -1
  55. package/core/src/i18n/discover.d.ts +1 -1
  56. package/core/src/i18n/index.d.ts +1 -1
  57. package/core/src/i18n/messages.d.ts +1 -1
  58. package/core/src/i18n/negotiate.d.ts +1 -1
  59. package/core/src/i18n/pathname.d.ts +1 -1
  60. package/core/src/i18n/resolve.d.ts +1 -1
  61. package/core/src/i18n/types.d.ts +1 -1
  62. package/core/src/image.d.ts +1 -1
  63. package/core/src/index.d.ts +1 -1
  64. package/core/src/llms/discovery.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 +7 -1
  97. package/core/src/ssr/lib/html.d.ts.map +1 -1
  98. package/core/src/ssr/lib/imports.d.ts +1 -1
  99. package/core/src/ssr/lib/index.d.ts +1 -1
  100. package/core/src/ssr/lib/layouts.d.ts +1 -1
  101. package/core/src/ssr/lib/metadata.d.ts +1 -1
  102. package/core/src/ssr/lib/mime.d.ts +1 -1
  103. package/core/src/ssr/lib/modules.d.ts +1 -1
  104. package/core/src/ssr/lib/path.d.ts +1 -1
  105. package/core/src/ssr/lib/preload.d.ts +1 -1
  106. package/core/src/ssr/lib/route-match.d.ts +1 -1
  107. package/core/src/ssr/lib/scripts/collections.d.ts +1 -1
  108. package/core/src/ssr/lib/scripts/data.d.ts +1 -1
  109. package/core/src/ssr/lib/scripts/escape.d.ts +1 -1
  110. package/core/src/ssr/lib/scripts/feeds.d.ts +1 -1
  111. package/core/src/ssr/lib/scripts/index.d.ts +1 -1
  112. package/core/src/ssr/lib/seed.d.ts +1 -1
  113. package/core/src/ssr/lib/serialize.d.ts +1 -1
  114. package/core/src/ssr/lib/setup.d.ts +1 -1
  115. package/core/src/ssr/lib/styles.d.ts +1 -1
  116. package/core/src/ssr/lib/template.d.ts +1 -1
  117. package/core/src/ssr/lib/types.d.ts +10 -2
  118. package/core/src/ssr/lib/types.d.ts.map +1 -1
  119. package/core/src/ssr/render.d.ts +1 -1
  120. package/core/src/ssr/stream.d.ts +1 -1
  121. package/core/src/ssr/stream.d.ts.map +1 -1
  122. package/elysia/index.d.ts +1 -1
  123. package/elysia/index.js +171 -124
  124. package/elysia/index.js.map +9 -9
  125. package/elysia/src/index.d.ts +1 -1
  126. package/elysia/src/libs/assets.d.ts +1 -1
  127. package/elysia/src/libs/cache.d.ts +1 -1
  128. package/elysia/src/libs/caching.d.ts +1 -1
  129. package/elysia/src/libs/devReload.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/plugin.d.ts.map +1 -1
  139. package/elysia/src/routes/artifacts.d.ts +1 -1
  140. package/elysia/src/routes/content.d.ts +1 -1
  141. package/elysia/src/routes/image.d.ts +1 -1
  142. package/elysia/src/routes/index.d.ts +1 -1
  143. package/elysia/src/routes/internal.d.ts +12 -2
  144. package/elysia/src/routes/internal.d.ts.map +1 -1
  145. package/elysia/src/routes/liveReloadClient.d.ts +1 -1
  146. package/elysia/src/routes/llms.d.ts +1 -1
  147. package/elysia/src/routes/og.d.ts +1 -1
  148. package/elysia/src/routes/redirects.d.ts +1 -1
  149. package/elysia/src/routes/robots.d.ts +1 -1
  150. package/elysia/src/routes/rss.d.ts +1 -1
  151. package/elysia/src/routes/search.d.ts +1 -1
  152. package/elysia/src/routes/sitemap.d.ts +1 -1
  153. package/elysia/src/routes/ssr.d.ts +1 -1
  154. package/elysia/src/routes/static.d.ts +1 -1
  155. package/elysia/src/routes/themeCssRefresh.d.ts +1 -1
  156. package/elysia/src/types.d.ts +1 -1
  157. package/package.json +1 -1
  158. package/react/index.d.ts +1 -1
  159. package/react/index.js +202 -188
  160. package/react/index.js.map +9 -9
  161. package/react/src/components/ClientOnly.d.ts +1 -1
  162. package/react/src/components/ContentRoute.d.ts +1 -1
  163. package/react/src/components/Image.d.ts +1 -1
  164. package/react/src/components/LazyRoute.d.ts +1 -1
  165. package/react/src/components/Link.d.ts +1 -1
  166. package/react/src/components/Link.d.ts.map +1 -1
  167. package/react/src/components/Markdown.d.ts +1 -1
  168. package/react/src/components/Outlet.d.ts +1 -1
  169. package/react/src/components/index.d.ts +1 -1
  170. package/react/src/hooks/index.d.ts +1 -1
  171. package/react/src/hooks/useContent.d.ts +1 -1
  172. package/react/src/hooks/useData.d.ts +1 -1
  173. package/react/src/hooks/useData.d.ts.map +1 -1
  174. package/react/src/hooks/useFeed.d.ts +1 -1
  175. package/react/src/hooks/useLayoutData.d.ts +1 -1
  176. package/react/src/hooks/useLayoutData.d.ts.map +1 -1
  177. package/react/src/hooks/useLlms.d.ts +1 -1
  178. package/react/src/hooks/useNavigate.d.ts +1 -1
  179. package/react/src/hooks/useParams.d.ts +1 -1
  180. package/react/src/hooks/useRouter.d.ts +1 -1
  181. package/react/src/hooks/useSearch.d.ts +1 -1
  182. package/react/src/hooks/useSearchParams.d.ts +1 -1
  183. package/react/src/hooks/useToc.d.ts +1 -1
  184. package/react/src/i18n/LocaleProvider.d.ts +1 -1
  185. package/react/src/i18n/helpers.d.ts +1 -1
  186. package/react/src/i18n/index.d.ts +1 -1
  187. package/react/src/index.d.ts +1 -1
  188. package/react/src/lib/bundle.d.ts +1 -1
  189. package/react/src/lib/collection.d.ts +1 -1
  190. package/react/src/lib/content.d.ts +1 -1
  191. package/react/src/lib/head.d.ts +37 -1
  192. package/react/src/lib/head.d.ts.map +1 -1
  193. package/react/src/lib/index.d.ts +1 -1
  194. package/react/src/lib/layouts.d.ts +1 -1
  195. package/react/src/lib/lazy-route.d.ts +1 -1
  196. package/react/src/lib/route-loader.d.ts +1 -1
  197. package/react/src/lib/static-data.d.ts +7 -1
  198. package/react/src/lib/static-data.d.ts.map +1 -1
  199. package/react/src/providers/ContentProvider.d.ts +1 -1
  200. package/react/src/providers/RerouteProvider.d.ts +1 -1
  201. package/react/src/providers/RouterProvider.d.ts +1 -1
  202. package/react/src/providers/RouterProvider.d.ts.map +1 -1
  203. package/react/src/providers/index.d.ts +1 -1
  204. package/react/src/types/any.d.ts +1 -1
  205. package/react/src/types/index.d.ts +1 -1
  206. package/react/src/types/router.d.ts +1 -1
  207. package/telemetry/react.d.ts +1 -1
  208. package/telemetry/react.js +2 -2
  209. package/telemetry/react.js.map +1 -1
  210. package/telemetry/server.d.ts +1 -1
  211. package/telemetry/server.js +2 -2
  212. package/telemetry/server.js.map +4 -4
  213. package/telemetry/src/react/api.d.ts +1 -1
  214. package/telemetry/src/react/context.d.ts +1 -1
  215. package/telemetry/src/react/index.d.ts +1 -1
  216. package/telemetry/src/react/telemetry.d.ts +1 -1
  217. package/telemetry/src/server/context.d.ts +1 -1
  218. package/telemetry/src/server/headers/extractor.d.ts +1 -1
  219. package/telemetry/src/server/headers/index.d.ts +1 -1
  220. package/telemetry/src/server/headers/presets.d.ts +1 -1
  221. package/telemetry/src/server/index.d.ts +1 -1
  222. package/telemetry/src/server/instrumentation.d.ts +1 -1
  223. package/telemetry/src/server/plugin.d.ts +1 -1
  224. package/telemetry/src/server/sourcemap.d.ts +1 -1
package/README.md CHANGED
@@ -618,6 +618,8 @@ Files are loaded in order, with later files overriding earlier ones.
618
618
  - ❌ `DATABASE_URL` - Server-only
619
619
  - ❌ `SECRET_KEY` - Server-only
620
620
 
621
+ A route's or layout's `ssr` (`data`, `head`, `lang`, `sitemap`) is server code too: the browser bundle leaves it out, with every import only `ssr` uses, so a loader can import a database client or call `Bun` freely. Declare it as `export const ssr = …` (or `const ssr = …; export { ssr }`); a form the build can't leave out fails it. When the browser navigates, the server sends the page's head and lang, built as for a full page load (layouts, `meta`, content and `ssr.head`), with its data; the browser swaps the page's own head for it.
622
+
621
623
  ### TypeScript Support
622
624
 
623
625
  For type safety, create a `env.d.ts` file:
package/cli/bin.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v1.0.0-alpha.36
2
+ * reroute-js v1.0.0-alpha.37
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
package/cli/bin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
3
  /**
4
- * reroute-js v1.0.0-alpha.36
4
+ * reroute-js v1.0.0-alpha.37
5
5
  *
6
6
  * @license MIT
7
7
  * @copyright 2026 stewones <hi@stewan.io>
@@ -68,7 +68,7 @@ async function getVersionString() {
68
68
  }
69
69
  async function getVersion() {
70
70
  if (true) {
71
- return "1.0.0-alpha.36";
71
+ return "1.0.0-alpha.37";
72
72
  }
73
73
  const possiblePaths = [
74
74
  path.join(import.meta.dir, "../../../../package.json"),
@@ -86,7 +86,7 @@ async function getVersion() {
86
86
  }
87
87
  async function getCommit() {
88
88
  if (true) {
89
- return "dfc0a27";
89
+ return "6e28dd5";
90
90
  }
91
91
  return "dev";
92
92
  }
@@ -2818,6 +2818,11 @@ function deduplicateMetaByProperty(headContent) {
2818
2818
  }
2819
2819
  return result;
2820
2820
  }
2821
+ function markPageHead(head) {
2822
+ return `<!--reroute:head-->${head ? `
2823
+ ${head}
2824
+ ` : ""}<!--/reroute:head-->`;
2825
+ }
2821
2826
  function deduplicateMetaTags(headContent) {
2822
2827
  try {
2823
2828
  let result = headContent;
@@ -4366,7 +4371,7 @@ async function renderSSRDocument(options) {
4366
4371
  const combinedHead = dedent([
4367
4372
  dedent(head) || "",
4368
4373
  dedent(extraHead),
4369
- dedent(setup2.metadataResult.perPageHead)
4374
+ markPageHead(dedent(setup2.metadataResult.perPageHead))
4370
4375
  ].filter(Boolean).join(`
4371
4376
  `));
4372
4377
  const i18nLocale = options.i18n?.enabled ? String(options.i18n.locale || "") : "";
@@ -6746,7 +6751,7 @@ async function renderSSRDocumentStream(options) {
6746
6751
  const newAttrs = hasLang ? attrs.replace(/lang\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/i, `lang="${pageLang}"`) : `${attrs} lang="${pageLang}"`;
6747
6752
  return `<html${newAttrs}>`;
6748
6753
  });
6749
- const extraHeadBase = setup2.bundlePreload + setup2.preloadExtraHead + setup2.metadataResult.perPageHead;
6754
+ const extraHeadBase = setup2.bundlePreload + setup2.preloadExtraHead + markPageHead(setup2.metadataResult.perPageHead);
6750
6755
  if (/<title[\s\S]*?<\/title>/i.test(extraHeadBase)) {
6751
6756
  headWithLang = headWithLang.replace(/<title[\s\S]*?<\/title>/i, "");
6752
6757
  }
@@ -7167,6 +7172,7 @@ __export(exports_core, {
7167
7172
  localizeHref: () => localizeHref,
7168
7173
  looksLikeLocale: () => looksLikeLocale,
7169
7174
  lookupMessage: () => lookupMessage,
7175
+ markPageHead: () => markPageHead,
7170
7176
  markdownTwinPath: () => markdownTwinPath,
7171
7177
  matchRoutePattern: () => matchRoutePattern,
7172
7178
  matchRoutes: () => matchRoutes,
@@ -8237,6 +8243,87 @@ var init_routes2 = __esm(() => {
8237
8243
  groupSegment = /^\(.+\)$/;
8238
8244
  });
8239
8245
 
8246
+ // packages/cli/src/commands/lib/ssr-strip.ts
8247
+ function scriptLoader(path3) {
8248
+ if (path3.endsWith(".tsx"))
8249
+ return "tsx";
8250
+ if (path3.endsWith(".jsx"))
8251
+ return "jsx";
8252
+ if (path3.endsWith(".js") || path3.endsWith(".mjs"))
8253
+ return "js";
8254
+ return "ts";
8255
+ }
8256
+ function exportsSsr(code, loader) {
8257
+ try {
8258
+ return new Bun.Transpiler({ loader }).scan(code).exports.includes("ssr");
8259
+ } catch {
8260
+ return true;
8261
+ }
8262
+ }
8263
+ function bareImports(code) {
8264
+ return new Set(Array.from(code.matchAll(BARE_IMPORT), (match) => match[2]));
8265
+ }
8266
+ function exportSsrInline(code) {
8267
+ if (!SSR_DECLARATION.test(code))
8268
+ return code;
8269
+ let moved = false;
8270
+ const listed = code.replace(EXPORT_LIST, (statement, names) => {
8271
+ const list = names.split(",").map((name) => name.trim()).filter(Boolean);
8272
+ if (!list.includes("ssr"))
8273
+ return statement;
8274
+ moved = true;
8275
+ const rest = list.filter((name) => name !== "ssr");
8276
+ return rest.length > 0 ? `export { ${rest.join(", ")} };` : "";
8277
+ });
8278
+ return moved ? listed.replace(SSR_DECLARATION, "$1export const ssr") : code;
8279
+ }
8280
+ function stripSsr(code, loader, path3, development) {
8281
+ const stripped = new Bun.Transpiler({
8282
+ loader,
8283
+ trimUnusedImports: true,
8284
+ autoImportJSX: true,
8285
+ exports: { eliminate: ["ssr"] },
8286
+ tsconfig: {
8287
+ compilerOptions: {
8288
+ jsx: development ? "react-jsxdev" : "react-jsx",
8289
+ jsxImportSource: "react"
8290
+ }
8291
+ }
8292
+ }).transformSync(exportSsrInline(code));
8293
+ if (exportsSsr(stripped, "js") || SSR_DECLARATION.test(stripped)) {
8294
+ throw new Error(`[reroute] ${path3}: declare the route's ssr as \`export const ssr = …\` so the browser bundle can leave it out`);
8295
+ }
8296
+ const own = bareImports(code);
8297
+ return stripped.replace(BARE_IMPORT, (statement, _quote, specifier) => own.has(specifier) ? statement : "").replace(EMPTY_REEXPORT, "");
8298
+ }
8299
+ function ssrStripPlugin(options) {
8300
+ const roots = [options.routesDir, options.markdownDir].map((dir) => dir.replace(/[\\/]+$/, ""));
8301
+ const escaped = roots.map((dir) => dir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
8302
+ const filter = new RegExp(`^(?:${escaped.join("|")})[\\\\/].*\\.[cm]?[jt]sx?$`);
8303
+ return {
8304
+ name: "reroute-ssr-strip",
8305
+ setup(build) {
8306
+ build.onLoad({ filter }, async ({ path: path3 }) => {
8307
+ const code = await Bun.file(path3).text();
8308
+ const loader = scriptLoader(path3);
8309
+ if (!exportsSsr(code, loader))
8310
+ return { contents: code, loader };
8311
+ return {
8312
+ contents: stripSsr(code, loader, path3, options.development),
8313
+ loader: "js"
8314
+ };
8315
+ });
8316
+ }
8317
+ };
8318
+ }
8319
+ var BARE_IMPORT, EMPTY_REEXPORT, SSR_DECLARATION, EXPORT_LIST;
8320
+ var init_ssr_strip = __esm(() => {
8321
+ BARE_IMPORT = /^[ \t]*import\s*(["'])([^"'\n]+)\1;?[ \t]*$/gm;
8322
+ EMPTY_REEXPORT = /^[ \t]*export\s*\{\s*\}\s*from\s*(["'])[^"'\n]+\1;?[ \t]*$/gm;
8323
+ SSR_DECLARATION = /^([ \t]*)(?:const|let|var)\s+ssr\b/m;
8324
+ EXPORT_LIST = /^[ \t]*export\s*\{([^}]*)\}[ \t]*;?[ \t]*$/gm;
8325
+ });
8326
+
8240
8327
  // packages/cli/src/commands/lib/streaming/analyzer.ts
8241
8328
  import { dirname as dirname4, join as join10 } from "node:path";
8242
8329
  function hasSSRDataExport(source) {
@@ -8787,24 +8874,36 @@ function getImportPath(filePath, streamingMap, routesImportBase) {
8787
8874
  const pathWithoutExt = filePath.replace(/\.(tsx|ts)$/, "");
8788
8875
  return `${routesImportBase}/${pathWithoutExt}`;
8789
8876
  }
8877
+ async function routeFilesWithSsr(cwd, routesPath, tree) {
8878
+ const found = new Set;
8879
+ for (const { filePath } of [...tree.routes, ...tree.layouts]) {
8880
+ const source = /\.(md|mdx)$/.test(filePath) ? join14(cwd, ".reroute", "markdown", filePath.replace(/\.(md|mdx)$/, ".tsx")) : join14(routesPath, filePath);
8881
+ const code = await Bun.file(source).text().catch(() => {
8882
+ return;
8883
+ });
8884
+ if (code !== undefined && exportsSsr(code, scriptLoader(source)))
8885
+ found.add(filePath);
8886
+ }
8887
+ return found;
8888
+ }
8790
8889
  function lazyRouteFallbackImport(config2) {
8791
8890
  const value = config2.streaming?.defaultSkeleton;
8792
8891
  if (typeof value !== "string" || value.trim().length === 0)
8793
8892
  return;
8794
8893
  return importFromReroute(value);
8795
8894
  }
8796
- function generateTypeScript(tree, streamingMap, client, routesImportBase, fallbackImport) {
8895
+ function generateTypeScript(tree, streamingMap, clientSsr, routesImportBase, fallbackImport) {
8797
8896
  const helperImport = fallbackImport ? `import { createLazyRoute } from 'reroute-js/react';
8798
8897
  import LazyRouteFallback from '${fallbackImport}';` : "import { createLazyRoute } from 'reroute-js/react';";
8799
8898
  const fallbackArgs = fallbackImport ? ", LazyRouteFallback" : "";
8800
8899
  const ssrHelper = "const _ssr = (m: any) => m.ssr;";
8801
8900
  const metaHelper = "const _meta = (m: any) => m.meta;";
8901
+ const ssrLine = (name) => clientSsr ? "" : `
8902
+ const ${name}SSR = _ssr(${name}Module);`;
8802
8903
  const metaImports = [
8803
- ...tree.routes.map((r, i) => `import * as Route${i}Module from '${getImportPath(r.filePath, streamingMap, routesImportBase)}';
8804
- const Route${i}SSR = _ssr(Route${i}Module);
8904
+ ...tree.routes.map((r, i) => `import * as Route${i}Module from '${getImportPath(r.filePath, streamingMap, routesImportBase)}';${ssrLine(`Route${i}`)}
8805
8905
  const Route${i}Meta = _meta(Route${i}Module);`),
8806
- ...tree.layouts.map((l, i) => `import * as Layout${i}Module from '${getImportPath(l.filePath, streamingMap, routesImportBase)}';
8807
- const Layout${i}SSR = _ssr(Layout${i}Module);
8906
+ ...tree.layouts.map((l, i) => `import * as Layout${i}Module from '${getImportPath(l.filePath, streamingMap, routesImportBase)}';${ssrLine(`Layout${i}`)}
8808
8907
  const Layout${i}Meta = _meta(Layout${i}Module);`)
8809
8908
  ].join(`
8810
8909
  `);
@@ -8837,7 +8936,7 @@ const Layout${i}Meta = _meta(Layout${i}Module);`)
8837
8936
  component: Route${i},
8838
8937
  params: ${JSON.stringify(r.params)},
8839
8938
  isDynamic: ${r.isDynamic},
8840
- ssr: Route${i}SSR,
8939
+ ${clientSsr ? `hasSsr: ${clientSsr.has(r.filePath)}` : `ssr: Route${i}SSR`},
8841
8940
  meta: Route${i}Meta,
8842
8941
  } as const`;
8843
8942
  }).join(`,
@@ -8855,8 +8954,8 @@ const Layout${i}Meta = _meta(Layout${i}Module);`)
8855
8954
  return ` {
8856
8955
  pattern: "${l.pattern}",
8857
8956
  path: "${l.path}",${scope}
8858
- component: Layout${i},
8859
- ssr: Layout${i}SSR,
8957
+ component: Layout${i},${clientSsr ? "" : `
8958
+ ssr: Layout${i}SSR,`}
8860
8959
  meta: Layout${i}Meta,
8861
8960
  } as const`;
8862
8961
  }).join(`,
@@ -8874,8 +8973,8 @@ const Layout${i}Meta = _meta(Layout${i}Module);`)
8874
8973
  // @ts-nocheck
8875
8974
 
8876
8975
  ${helperImport}
8877
-
8878
- ${ssrHelper}
8976
+ ${clientSsr ? "" : `
8977
+ ${ssrHelper}`}
8879
8978
  ${metaHelper}
8880
8979
 
8881
8980
  ${eagerImports}
@@ -8907,7 +9006,7 @@ export interface Route {
8907
9006
  component: any;
8908
9007
  params: string[];
8909
9008
  isDynamic: boolean;
8910
- ssr?: any;
9009
+ ${clientSsr ? "hasSsr?: boolean;" : "ssr?: any;"}
8911
9010
  meta?: any;
8912
9011
  }
8913
9012
 
@@ -8958,7 +9057,7 @@ function matchPattern(route: Route, pathname: string): Record<string, string> |
8958
9057
  return pathnameIndex === pathnameParts.length ? params : null;
8959
9058
  }
8960
9059
 
8961
- ${client ? "" : `// Set globals for compiled binary support (sitemap/RSS/robots discovery)
9060
+ ${clientSsr ? "" : `// Set globals for compiled binary support (sitemap/RSS/robots discovery)
8962
9061
  (globalThis as any).__REROUTE_ROUTES__ = routes;
8963
9062
  (globalThis as any).__REROUTE_LAYOUTS__ = layouts;
8964
9063
  (globalThis as any).__REROUTE_NOT_FOUND_ROUTES__ = notFoundRoutes;`}
@@ -9505,6 +9604,13 @@ async function buildEntrypointBundle(cwd, args = []) {
9505
9604
  ...getCommonBuildOptions(),
9506
9605
  naming: getNamingConfig({ entry: "index.[hash].[ext]" }),
9507
9606
  ...bundleGraphOptions,
9607
+ plugins: [
9608
+ ssrStripPlugin({
9609
+ routesDir: join14(cwd, paths.routesDir),
9610
+ markdownDir: join14(cwd, ".reroute", "markdown"),
9611
+ development: !isProd
9612
+ })
9613
+ ],
9508
9614
  jsx: {
9509
9615
  runtime: "automatic",
9510
9616
  importSource: "react",
@@ -9689,8 +9795,8 @@ async function generate(cwd, args = [], options = {}) {
9689
9795
  const tree = generateRouteTree(all.map((f) => f.replace(/\\/g, "/")));
9690
9796
  const streamingAnalyses = streamingEnabled ? await buildStreamingWrappersForTree(cwd, routesPath, tree, config2) : new Map;
9691
9797
  const fallbackImport = lazyRouteFallbackImport(config2);
9692
- const serverRoutes = generateTypeScript(tree, streamingAnalyses, false, routesImportBase, fallbackImport);
9693
- const clientRoutes = generateTypeScript(tree, streamingAnalyses, true, routesImportBase, fallbackImport);
9798
+ const serverRoutes = generateTypeScript(tree, streamingAnalyses, undefined, routesImportBase, fallbackImport);
9799
+ const clientRoutes = generateTypeScript(tree, streamingAnalyses, await routeFilesWithSsr(cwd, routesPath, tree), routesImportBase, fallbackImport);
9694
9800
  await Bun.write(join14(cwd, OUTPUT_ROUTES), serverRoutes);
9695
9801
  await Bun.write(join14(cwd, OUTPUT_ROUTES_CLIENT), clientRoutes);
9696
9802
  });
@@ -10377,6 +10483,7 @@ var init_gen = __esm(() => {
10377
10483
  init_images();
10378
10484
  init_markdown();
10379
10485
  init_routes2();
10486
+ init_ssr_strip();
10380
10487
  init_analyzer();
10381
10488
  init_suspense();
10382
10489
  init_theme();
@@ -108731,7 +108838,7 @@ async function getVersionString2() {
108731
108838
  }
108732
108839
  async function getVersion2() {
108733
108840
  if (true) {
108734
- return "1.0.0-alpha.36";
108841
+ return "1.0.0-alpha.37";
108735
108842
  }
108736
108843
  const possiblePaths = [
108737
108844
  path3.join(import.meta.dir, "../../../package.json"),
@@ -108748,10 +108855,10 @@ async function getVersion2() {
108748
108855
  }
108749
108856
  async function getCommit2() {
108750
108857
  if (true) {
108751
- return "dfc0a27";
108858
+ return "6e28dd5";
108752
108859
  }
108753
108860
  return "dev";
108754
108861
  }
108755
108862
  main();
108756
108863
 
108757
- //# debugId=A24C16CC41DCEA0564756E2164756E21
108864
+ //# debugId=E7D58218ED0BCE3D64756E2164756E21