heliumts 0.7.6 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +51 -1
  2. package/dist/bin/helium.js +131 -2
  3. package/dist/bin/helium.js.map +1 -1
  4. package/dist/client/Router.d.ts +1 -0
  5. package/dist/client/Router.d.ts.map +1 -1
  6. package/dist/client/Router.js +69 -1
  7. package/dist/client/Router.js.map +1 -1
  8. package/dist/client/index.d.ts +6 -0
  9. package/dist/client/index.d.ts.map +1 -1
  10. package/dist/client/index.js +8 -0
  11. package/dist/client/index.js.map +1 -1
  12. package/dist/server/defineServerSideProps.d.ts +22 -0
  13. package/dist/server/defineServerSideProps.d.ts.map +1 -0
  14. package/dist/server/defineServerSideProps.js +2 -0
  15. package/dist/server/defineServerSideProps.js.map +1 -0
  16. package/dist/server/devServer.d.ts +8 -1
  17. package/dist/server/devServer.d.ts.map +1 -1
  18. package/dist/server/devServer.js +113 -15
  19. package/dist/server/devServer.js.map +1 -1
  20. package/dist/server/httpRouter.d.ts +6 -0
  21. package/dist/server/httpRouter.d.ts.map +1 -1
  22. package/dist/server/httpRouter.js +7 -5
  23. package/dist/server/httpRouter.js.map +1 -1
  24. package/dist/server/index.d.ts +1 -0
  25. package/dist/server/index.d.ts.map +1 -1
  26. package/dist/server/index.js +1 -0
  27. package/dist/server/index.js.map +1 -1
  28. package/dist/server/prodServer.d.ts +8 -0
  29. package/dist/server/prodServer.d.ts.map +1 -1
  30. package/dist/server/prodServer.js +71 -4
  31. package/dist/server/prodServer.js.map +1 -1
  32. package/dist/server/serverPropsRouter.d.ts +1 -0
  33. package/dist/server/serverPropsRouter.d.ts.map +1 -0
  34. package/dist/server/serverPropsRouter.js +2 -0
  35. package/dist/server/serverPropsRouter.js.map +1 -0
  36. package/dist/server/ssr.d.ts +38 -0
  37. package/dist/server/ssr.d.ts.map +1 -0
  38. package/dist/server/ssr.js +172 -0
  39. package/dist/server/ssr.js.map +1 -0
  40. package/dist/vite/heliumPlugin.d.ts.map +1 -1
  41. package/dist/vite/heliumPlugin.js +145 -5
  42. package/dist/vite/heliumPlugin.js.map +1 -1
  43. package/dist/vite/scanner.d.ts +8 -0
  44. package/dist/vite/scanner.d.ts.map +1 -1
  45. package/dist/vite/scanner.js +107 -0
  46. package/dist/vite/scanner.js.map +1 -1
  47. package/dist/vite/virtualServerModule.d.ts +2 -2
  48. package/dist/vite/virtualServerModule.d.ts.map +1 -1
  49. package/dist/vite/virtualServerModule.js +60 -3
  50. package/dist/vite/virtualServerModule.js.map +1 -1
  51. package/package.json +1 -1
package/README.md CHANGED
@@ -23,6 +23,7 @@ HeliumTS is a blazing fast 🚀 and opinionated full-stack React + Vite framewor
23
23
  - [Middleware](#35-middleware)
24
24
  - [Configuration](#36-heliumconfigts)
25
25
  - [Static Site Generation (SSG)](#37-static-site-generation-ssg)
26
+ - [Server-Side Rendering (SSR)](#38-server-side-rendering-ssr)
26
27
  4. [CLI Reference](#4-cli-reference)
27
28
  5. [More Documentation](#5-more-documentation)
28
29
  6. [Contributing](#6-contributing)
@@ -331,7 +332,55 @@ During build, Helium validates SSG pages and generates optimized static HTML fil
331
332
 
332
333
  See [SSG Documentation](./docs/ssg.md) for detailed information including limitations, hybrid rendering, and best practices.
333
334
 
334
- ## 4.CLI Reference
335
+ ### 3.8. Server-Side Rendering (SSR)
336
+
337
+ HeliumTS supports Server-Side Rendering (SSR) for pages that need fully rendered HTML on every request — useful for SEO, social media crawlers, and pages with per-request personalised data.
338
+
339
+ Add a `"use ssr"` directive at the top of your page file to enable SSR:
340
+
341
+ **SSR page: (`src/pages/dashboard.tsx`)**
342
+ ```tsx
343
+ "use ssr";
344
+
345
+ export default function DashboardPage({ user }: { user: string }) {
346
+ return <h1>Welcome, {user}</h1>;
347
+ }
348
+ ```
349
+
350
+ To fetch data on the server for each request, export a `getServerSideProps` function from the same file or a sidecar `page.server.ts` file (recommended):
351
+
352
+ ```ts
353
+ // src/pages/dashboard.server.ts
354
+ import type { GetServerSideProps } from "heliumts/server";
355
+
356
+ export const getServerSideProps: GetServerSideProps = async (req, ctx) => {
357
+ const user = await getUser(req.headers);
358
+ return { user };
359
+ };
360
+ ```
361
+
362
+ Props are injected into the HTML as `window.__HELIUM_SSR_DATA__` and passed to the component. React hydrates the page client-side without a second server round-trip.
363
+
364
+ **`isSSR()` utility** — use this in layouts to skip client-only guards (e.g. auth redirects) during server rendering while still providing required context providers:
365
+
366
+ ```tsx
367
+ import { isSSR } from "heliumts/client";
368
+
369
+ export default function AppLayout({ children }: { children: React.ReactNode }) {
370
+ const { isPending, data } = useSession();
371
+
372
+ if (!isSSR()) {
373
+ if (isPending) return null;
374
+ if (!data?.session) return null;
375
+ }
376
+
377
+ return <Providers>{children}</Providers>;
378
+ }
379
+ ```
380
+
381
+ See [SSR Documentation](./docs/ssr.md) for detailed information including sidecar files, layout guards, browser-only dependencies, and how hydration works.
382
+
383
+ ## 4. CLI Reference
335
384
 
336
385
  - `helium dev`: Starts Vite in development mode.
337
386
  - `helium build`:
@@ -351,6 +400,7 @@ See [SSG Documentation](./docs/ssg.md) for detailed information including limita
351
400
  - [Routing & useRouter](./docs/routing.md) - File-based routing, dynamic routes, navigation, and the useRouter hook
352
401
  - [Configuration](./docs/helium-config.md) - Configure RPC encoding, compression, security, and proxy settings
353
402
  - [Static Site Generation](./docs/ssg.md) - Pre-render pages at build time for better performance
403
+ - [Server-Side Rendering](./docs/ssr.md) - Render pages on the server per-request for SEO and dynamic data
354
404
  - [Route Groups](./docs/route-groups.md) - Organize routes with shared layouts without affecting URLs
355
405
  - [Background Workers](./docs/workers.md) - Long-running background processes for queues, scheduled tasks, and more
356
406
 
@@ -6,7 +6,7 @@ import fs from "fs";
6
6
  import path from "path";
7
7
  import { build as viteBuild } from "vite";
8
8
  import { log } from "../utils/logger.js";
9
- import { scanPageRoutePatterns, scanServerExports } from "../vite/scanner.js";
9
+ import { scanAppShell, scanPageRoutePatterns, scanServerExports, scanSSRPages } from "../vite/scanner.js";
10
10
  import { generateStaticPages } from "../vite/ssg.js";
11
11
  import { generateServerManifest } from "../vite/virtualServerModule.js";
12
12
  const cli = cac("helium");
@@ -79,7 +79,9 @@ cli.command("build", "Build for production").action(async () => {
79
79
  // Generate server entry
80
80
  const serverExports = scanServerExports(root);
81
81
  const pageRoutePatterns = scanPageRoutePatterns(root);
82
- const manifestCode = generateServerManifest(serverExports.methods, serverExports.httpHandlers, serverExports.seoMetadata, pageRoutePatterns, serverExports.middleware, serverExports.workers);
82
+ const ssrPages = scanSSRPages(root);
83
+ const appShell = scanAppShell(root);
84
+ const manifestCode = generateServerManifest(serverExports.methods, serverExports.httpHandlers, serverExports.seoMetadata, pageRoutePatterns, ssrPages, appShell, serverExports.middleware, serverExports.workers);
83
85
  // Create the main server module that will be imported after env is loaded
84
86
  const serverModuleCode = `
85
87
  import { startProdServer, loadConfig } from 'heliumts/server';
@@ -100,6 +102,8 @@ export async function start() {
100
102
  httpRouter.setMiddleware(middlewareHandler);
101
103
  }
102
104
  },
105
+ ssrPages,
106
+ appShell,
103
107
  workers
104
108
  });
105
109
  }
@@ -131,9 +135,122 @@ if (Object.keys(envVars).length > 0) {
131
135
  const entryPath = path.join(heliumDir, "server-entry.ts");
132
136
  const envLoaderPath = path.join(heliumDir, "env-loader.ts");
133
137
  const serverModuleSrcPath = path.join(heliumDir, "server-module.ts");
138
+ const ssrClientStubPath = path.join(heliumDir, "ssr-client-stub.ts");
139
+ const ssrTransitionsStubPath = path.join(heliumDir, "ssr-transitions-stub.ts");
140
+ const ssrPrefetchStubPath = path.join(heliumDir, "ssr-prefetch-stub.ts");
141
+ const ssrClientStubCode = `
142
+ import React from 'react';
143
+
144
+ export const RouterContext = React.createContext(null);
145
+
146
+ function getSSRRouterSnapshot() {
147
+ const snapshot = globalThis.__HELIUM_SSR_ROUTER__ as
148
+ | { path?: string; params?: Record<string, string | string[]>; search?: string }
149
+ | undefined;
150
+
151
+ if (!snapshot || typeof snapshot !== 'object') {
152
+ return {
153
+ path: '/',
154
+ params: {},
155
+ search: '',
156
+ };
157
+ }
158
+
159
+ return {
160
+ path: typeof snapshot.path === 'string' ? snapshot.path : '/',
161
+ params: snapshot.params && typeof snapshot.params === 'object' ? snapshot.params : {},
162
+ search: typeof snapshot.search === 'string' ? snapshot.search : '',
163
+ };
164
+ }
165
+
166
+ export function useRouter() {
167
+ const snapshot = getSSRRouterSnapshot();
168
+ return {
169
+ path: snapshot.path,
170
+ params: snapshot.params,
171
+ searchParams: new URLSearchParams(snapshot.search),
172
+ push: () => {},
173
+ replace: () => {},
174
+ on: () => () => {},
175
+ status: 200,
176
+ isNavigating: false,
177
+ isPending: false,
178
+ };
179
+ }
180
+
181
+ export function Link(props: { href?: string; children?: React.ReactNode } & Record<string, unknown>) {
182
+ const { href = '#', children, ...rest } = props || {};
183
+ return React.createElement('a', { href, ...rest }, children);
184
+ }
185
+
186
+ export function Redirect() {
187
+ return null;
188
+ }
189
+
190
+ export function AppRouter() {
191
+ return null;
192
+ }
193
+
194
+ export function useCall() {
195
+ return {
196
+ call: async () => null,
197
+ isCalling: false,
198
+ error: null,
199
+ };
200
+ }
201
+
202
+ export function useFetch() {
203
+ return {
204
+ data: null,
205
+ isLoading: false,
206
+ error: null,
207
+ refetch: async () => undefined,
208
+ };
209
+ }
210
+
211
+ export class RpcError extends Error {}
212
+
213
+ export function getRpcTransport() {
214
+ return 'websocket';
215
+ }
216
+
217
+ export function isAutoHttpOnMobileEnabled() {
218
+ return false;
219
+ }
220
+
221
+ export function preconnect() {}
222
+
223
+ export function isSSR() {
224
+ return true;
225
+ }
226
+ `;
227
+ const ssrTransitionsStubCode = `
228
+ import React from 'react';
229
+
230
+ export function useDeferredNavigation() {
231
+ return {
232
+ path: '/',
233
+ deferredPath: '/',
234
+ isStale: false,
235
+ isPending: false,
236
+ isTransitioning: false,
237
+ };
238
+ }
239
+
240
+ export function PageTransition({ children }: { children?: React.ReactNode }) {
241
+ return React.createElement(React.Fragment, null, children);
242
+ }
243
+ `;
244
+ const ssrPrefetchStubCode = `
245
+ export function prefetchRoute() {}
246
+ export function clearPrefetchCache() {}
247
+ `;
134
248
  fs.writeFileSync(entryPath, entryCode);
135
249
  fs.writeFileSync(envLoaderPath, envLoaderCode);
136
250
  fs.writeFileSync(serverModuleSrcPath, serverModuleCode);
251
+ fs.writeFileSync(ssrClientStubPath, ssrClientStubCode);
252
+ fs.writeFileSync(ssrTransitionsStubPath, ssrTransitionsStubCode);
253
+ fs.writeFileSync(ssrPrefetchStubPath, ssrPrefetchStubCode);
137
254
  // Bundle with esbuild
138
255
  try {
139
256
  await esbuild({
@@ -142,6 +259,18 @@ if (Object.keys(envVars).length > 0) {
142
259
  bundle: true,
143
260
  platform: "node",
144
261
  format: "esm",
262
+ jsx: "automatic",
263
+ jsxImportSource: "react",
264
+ plugins: [
265
+ {
266
+ name: "helium-ssr-client-alias",
267
+ setup(build) {
268
+ build.onResolve({ filter: /^heliumts\/client$/ }, () => ({ path: ssrClientStubPath }));
269
+ build.onResolve({ filter: /^heliumts\/client\/transitions$/ }, () => ({ path: ssrTransitionsStubPath }));
270
+ build.onResolve({ filter: /^heliumts\/client\/prefetch$/ }, () => ({ path: ssrPrefetchStubPath }));
271
+ },
272
+ },
273
+ ],
145
274
  external: [
146
275
  // External common database and heavy dependencies
147
276
  "mongodb",
@@ -1 +1 @@
1
- {"version":3,"file":"helium.js","sourceRoot":"","sources":["../../src/bin/helium.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,EAAE,GAAG,EAAE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AC;QACT,GAAG,CAAC,OAAO,EAAE,sBAAsB,EAAE,CAAC,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE;IAC9D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACxD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,GAAG,CAAC,OAAO,EAAE,mDAAmD,CAAC,CAAC;QAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,sEAAsE;IACtE,gDAAgD;IAChD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,EAAE;QACvC,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,IAAI;QACX,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;KACtE,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;QACxB,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,IAAI,EAAE,CAAC;AACX,GAAG,CAAC,KAAK,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { cac } from \"cac\";\nimport { spawn } from \"child_process\";\nimport { build as esbuild } from \"esbuild\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { build as viteBuild } from \"vite\";\n\nimport { log } from \"../utils/logger.js\";\nimport { scanPageRoutePatterns, scanServerExports } from \"../vite/scanner.js\";\nimport { generateStaticPages } from \"../vite/ssg.js\";\nimport { generateServerManifest } from \"../vite/virtualServerModule.js\";\n\nconst cli = cac(\"helium\");\nconst root = process.cwd();\n\ncli.command(\"dev\", \"Start development server\").action(async () => {\n const vite = spawn(\"vite\", [], { stdio: \"inherit\", shell: true });\n vite.on(\"close\", (code) => {\n process.exit(code || 0);\n });\n});\n\ncli.command(\"build\", \"Build for production\").action(async () => {\n log(\"info\", \"--------------------------------\");\n log(\"info\", \"Building client...\");\n\n try {\n const result = await viteBuild({\n root,\n logLevel: \"silent\",\n build: {\n outDir: \"dist\",\n },\n });\n\n // Display build output\n if (result && \"output\" in result) {\n const outputs = result.output;\n const zlib = await import(\"zlib\");\n\n for (const chunk of outputs) {\n if (chunk.type === \"asset\" || chunk.type === \"chunk\") {\n const fileName = chunk.fileName;\n const content = \"code\" in chunk ? chunk.code : chunk.source;\n const size = Buffer.byteLength(content, \"utf-8\");\n const sizeKB = (size / 1024).toFixed(2);\n\n // Calculate gzipped size\n const gzipped = zlib.gzipSync(content);\n const gzipSizeKB = (gzipped.length / 1024).toFixed(2);\n\n log(\"info\", ` ${fileName.padEnd(35)} ${sizeKB.padStart(8)} kB │ gzip: ${gzipSizeKB.padStart(7)} kB`);\n }\n }\n }\n\n log(\"info\", \"Client build complete.\");\n\n // Generate static pages for SSG\n log(\"info\", \"--------------------------------\");\n try {\n // Read the generated index.html as a template for SSG\n const distDir = path.join(root, \"dist\");\n const htmlPath = path.join(distDir, \"index.html\");\n\n if (fs.existsSync(htmlPath)) {\n let htmlTemplate = fs.readFileSync(htmlPath, \"utf-8\");\n\n // Clean up the template for SSG:\n // 1. Remove the build-time HELIUM_CONNECTION_TOKEN (SSG pages don't need it)\n htmlTemplate = htmlTemplate.replace(/<script>window\\.HELIUM_CONNECTION_TOKEN = \"build-time-placeholder\";<\\/script>/g, \"\");\n\n // 2. Clear any existing content in root div from SPA build\n htmlTemplate = htmlTemplate.replace(/<div\\s+id=\"root\"[^>]*>.*?<\\/div>/s, '<div id=\"root\"></div>');\n\n await generateStaticPages(null, root, htmlTemplate, distDir);\n } else {\n log(\"warn\", \"index.html not found in dist, skipping SSG\");\n }\n } catch (e) {\n log(\"warn\", \"SSG generation failed:\", e);\n // Don't fail the build if SSG fails\n }\n log(\"info\", \"--------------------------------\");\n } catch (e) {\n log(\"error\", \"Client build failed:\", e);\n process.exit(1);\n }\n\n log(\"info\", \"Building server...\");\n // Generate server entry\n const serverExports = scanServerExports(root);\n const pageRoutePatterns = scanPageRoutePatterns(root);\n const manifestCode = generateServerManifest(\n serverExports.methods,\n serverExports.httpHandlers,\n serverExports.seoMetadata,\n pageRoutePatterns,\n serverExports.middleware,\n serverExports.workers\n );\n\n // Create the main server module that will be imported after env is loaded\n const serverModuleCode = `\nimport { startProdServer, loadConfig } from 'heliumts/server';\n${manifestCode}\n\nexport async function start() {\n const config = await loadConfig();\n\n startProdServer({\n config,\n registerHandlers: (registry, httpRouter, seoRouter) => {\n registerAll(registry);\n httpRouter.registerRoutes(httpHandlers);\n seoRouter.registerRoutes(seoMetadataHandlers);\n seoRouter.setPageRoutePatterns(pageRoutePatterns);\n if (middlewareHandler) {\n registry.setMiddleware(middlewareHandler);\n httpRouter.setMiddleware(middlewareHandler);\n }\n },\n workers\n });\n}\n`;\n\n // Create the entry loader that loads env first, then imports the server module\n const entryCode = `\n// Load environment variables FIRST, before any other imports\nimport './env-loader.js';\n// Now import and start the server (this ensures handlers load after env)\nimport { start } from './server-module.js';\nawait start();\n`;\n\n const envLoaderCode = `\nimport { loadEnvFiles, injectEnvToProcess, log } from 'heliumts/server';\nconst envRoot = process.cwd();\nlog('info', \\`Loading .env files from: \\${envRoot}\\`);\nconst envVars = loadEnvFiles({ mode: 'production' });\ninjectEnvToProcess(envVars);\nif (Object.keys(envVars).length > 0) {\n log('info', \\`Loaded \\${Object.keys(envVars).length} environment variable(s) from .env files\\`);\n} else {\n log('info', 'No .env files found (using platform environment variables if available)');\n}\n`;\n\n const heliumDir = path.join(root, \"node_modules\", \".heliumts\");\n if (!fs.existsSync(heliumDir)) {\n fs.mkdirSync(heliumDir, { recursive: true });\n }\n const entryPath = path.join(heliumDir, \"server-entry.ts\");\n const envLoaderPath = path.join(heliumDir, \"env-loader.ts\");\n const serverModuleSrcPath = path.join(heliumDir, \"server-module.ts\");\n\n fs.writeFileSync(entryPath, entryCode);\n fs.writeFileSync(envLoaderPath, envLoaderCode);\n fs.writeFileSync(serverModuleSrcPath, serverModuleCode);\n\n // Bundle with esbuild\n try {\n await esbuild({\n entryPoints: [entryPath],\n outfile: path.join(root, \"dist\", \"server.js\"),\n bundle: true,\n platform: \"node\",\n format: \"esm\",\n external: [\n // External common database and heavy dependencies\n \"mongodb\",\n \"mongoose\",\n \"pg\",\n \"mysql\",\n \"mysql2\",\n \"sqlite3\",\n \"better-sqlite3\",\n \"redis\",\n // Node.js built-ins are automatically external, but let's be explicit\n \"crypto\",\n \"fs\",\n \"path\",\n \"http\",\n \"https\",\n \"stream\",\n \"zlib\",\n \"util\",\n ],\n target: \"node18\",\n metafile: true,\n banner: {\n js: \"import { createRequire } from 'module'; const require = createRequire(import.meta.url);\",\n },\n });\n\n // Display server build output\n const serverOutputPath = path.relative(root, path.join(root, \"dist\", \"server.js\"));\n const serverStats = fs.statSync(path.join(root, \"dist\", \"server.js\"));\n const serverSizeKB = (serverStats.size / 1024).toFixed(2);\n log(\"info\", ` ${serverOutputPath.padEnd(35)} ${serverSizeKB.padStart(8)} kB`);\n\n log(\"info\", \"Server build complete.\");\n\n // Transpile helium.config.ts to helium.config.js if it exists\n const configTsPath = path.join(root, \"helium.config.ts\");\n if (fs.existsSync(configTsPath)) {\n log(\"info\", \"Transpiling helium.config.ts...\");\n try {\n await esbuild({\n entryPoints: [configTsPath],\n outfile: path.join(root, \"dist\", \"helium.config.js\"),\n bundle: false,\n platform: \"node\",\n format: \"esm\",\n target: \"node18\",\n });\n log(\"info\", \"Config file transpiled to dist/helium.config.js\");\n } catch (e) {\n log(\"warn\", \"Failed to transpile config file:\", e);\n log(\"warn\", \"You may need to manually rename helium.config.ts to helium.config.js\");\n }\n } else {\n // Check if .js or .mjs config exists and copy it to dist\n const configJsPath = path.join(root, \"helium.config.js\");\n const configMjsPath = path.join(root, \"helium.config.mjs\");\n\n if (fs.existsSync(configJsPath)) {\n fs.copyFileSync(configJsPath, path.join(root, \"dist\", \"helium.config.js\"));\n log(\"info\", \"Copied helium.config.js to dist/\");\n } else if (fs.existsSync(configMjsPath)) {\n fs.copyFileSync(configMjsPath, path.join(root, \"dist\", \"helium.config.mjs\"));\n log(\"info\", \"Copied helium.config.mjs to dist/\");\n }\n }\n\n log(\"info\", \"--------------------------------\");\n log(\"info\", \"✓ Build finished successfully.\");\n log(\"info\", \"▶ Run 'helium start' to start the production server.\");\n\n // Exit cleanly after build completes\n process.exit(0);\n } catch (e) {\n log(\"error\", \"Server build failed:\", e);\n process.exit(1);\n }\n});\n\ncli.command(\"start\", \"Start production server\").action(async () => {\n const serverPath = path.join(root, \"dist\", \"server.js\");\n if (!fs.existsSync(serverPath)) {\n log(\"error\", 'Server build not found. Run \"helium build\" first.');\n process.exit(1);\n }\n\n // When running in production, look for config in dist directory first\n // This allows the transpiled config to be found\n const server = spawn(\"node\", [serverPath], {\n stdio: \"inherit\",\n shell: true,\n env: { ...process.env, HELIUM_CONFIG_DIR: path.join(root, \"dist\") },\n });\n server.on(\"close\", (code) => {\n process.exit(code || 0);\n });\n});\n\ncli.help();\ncli.parse();\n"]}
1
+ {"version":3,"file":"helium.js","sourceRoot":"","sources":["../../src/bin/helium.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAC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CAAC;AACP,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,IAAI,EAAE,CAAC;AACX,GAAG,CAAC,KAAK,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { cac } from \"cac\";\nimport { spawn } from \"child_process\";\nimport { build as esbuild } from \"esbuild\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { build as viteBuild } from \"vite\";\n\nimport { log } from \"../utils/logger.js\";\nimport { scanAppShell, scanPageRoutePatterns, scanServerExports, scanSSRPages } from \"../vite/scanner.js\";\nimport { generateStaticPages } from \"../vite/ssg.js\";\nimport { generateServerManifest } from \"../vite/virtualServerModule.js\";\n\nconst cli = cac(\"helium\");\nconst root = process.cwd();\n\ncli.command(\"dev\", \"Start development server\").action(async () => {\n const vite = spawn(\"vite\", [], { stdio: \"inherit\", shell: true });\n vite.on(\"close\", (code) => {\n process.exit(code || 0);\n });\n});\n\ncli.command(\"build\", \"Build for production\").action(async () => {\n log(\"info\", \"--------------------------------\");\n log(\"info\", \"Building client...\");\n\n try {\n const result = await viteBuild({\n root,\n logLevel: \"silent\",\n build: {\n outDir: \"dist\",\n },\n });\n\n // Display build output\n if (result && \"output\" in result) {\n const outputs = result.output;\n const zlib = await import(\"zlib\");\n\n for (const chunk of outputs) {\n if (chunk.type === \"asset\" || chunk.type === \"chunk\") {\n const fileName = chunk.fileName;\n const content = \"code\" in chunk ? chunk.code : chunk.source;\n const size = Buffer.byteLength(content, \"utf-8\");\n const sizeKB = (size / 1024).toFixed(2);\n\n // Calculate gzipped size\n const gzipped = zlib.gzipSync(content);\n const gzipSizeKB = (gzipped.length / 1024).toFixed(2);\n\n log(\"info\", ` ${fileName.padEnd(35)} ${sizeKB.padStart(8)} kB │ gzip: ${gzipSizeKB.padStart(7)} kB`);\n }\n }\n }\n\n log(\"info\", \"Client build complete.\");\n\n // Generate static pages for SSG\n log(\"info\", \"--------------------------------\");\n try {\n // Read the generated index.html as a template for SSG\n const distDir = path.join(root, \"dist\");\n const htmlPath = path.join(distDir, \"index.html\");\n\n if (fs.existsSync(htmlPath)) {\n let htmlTemplate = fs.readFileSync(htmlPath, \"utf-8\");\n\n // Clean up the template for SSG:\n // 1. Remove the build-time HELIUM_CONNECTION_TOKEN (SSG pages don't need it)\n htmlTemplate = htmlTemplate.replace(/<script>window\\.HELIUM_CONNECTION_TOKEN = \"build-time-placeholder\";<\\/script>/g, \"\");\n\n // 2. Clear any existing content in root div from SPA build\n htmlTemplate = htmlTemplate.replace(/<div\\s+id=\"root\"[^>]*>.*?<\\/div>/s, '<div id=\"root\"></div>');\n\n await generateStaticPages(null, root, htmlTemplate, distDir);\n } else {\n log(\"warn\", \"index.html not found in dist, skipping SSG\");\n }\n } catch (e) {\n log(\"warn\", \"SSG generation failed:\", e);\n // Don't fail the build if SSG fails\n }\n log(\"info\", \"--------------------------------\");\n } catch (e) {\n log(\"error\", \"Client build failed:\", e);\n process.exit(1);\n }\n\n log(\"info\", \"Building server...\");\n // Generate server entry\n const serverExports = scanServerExports(root);\n const pageRoutePatterns = scanPageRoutePatterns(root);\n const ssrPages = scanSSRPages(root);\n const appShell = scanAppShell(root);\n const manifestCode = generateServerManifest(\n serverExports.methods,\n serverExports.httpHandlers,\n serverExports.seoMetadata,\n pageRoutePatterns,\n ssrPages,\n appShell,\n serverExports.middleware,\n serverExports.workers\n );\n\n // Create the main server module that will be imported after env is loaded\n const serverModuleCode = `\nimport { startProdServer, loadConfig } from 'heliumts/server';\n${manifestCode}\n\nexport async function start() {\n const config = await loadConfig();\n\n startProdServer({\n config,\n registerHandlers: (registry, httpRouter, seoRouter) => {\n registerAll(registry);\n httpRouter.registerRoutes(httpHandlers);\n seoRouter.registerRoutes(seoMetadataHandlers);\n seoRouter.setPageRoutePatterns(pageRoutePatterns);\n if (middlewareHandler) {\n registry.setMiddleware(middlewareHandler);\n httpRouter.setMiddleware(middlewareHandler);\n }\n },\n ssrPages,\n appShell,\n workers\n });\n}\n`;\n\n // Create the entry loader that loads env first, then imports the server module\n const entryCode = `\n// Load environment variables FIRST, before any other imports\nimport './env-loader.js';\n// Now import and start the server (this ensures handlers load after env)\nimport { start } from './server-module.js';\nawait start();\n`;\n\n const envLoaderCode = `\nimport { loadEnvFiles, injectEnvToProcess, log } from 'heliumts/server';\nconst envRoot = process.cwd();\nlog('info', \\`Loading .env files from: \\${envRoot}\\`);\nconst envVars = loadEnvFiles({ mode: 'production' });\ninjectEnvToProcess(envVars);\nif (Object.keys(envVars).length > 0) {\n log('info', \\`Loaded \\${Object.keys(envVars).length} environment variable(s) from .env files\\`);\n} else {\n log('info', 'No .env files found (using platform environment variables if available)');\n}\n`;\n\n const heliumDir = path.join(root, \"node_modules\", \".heliumts\");\n if (!fs.existsSync(heliumDir)) {\n fs.mkdirSync(heliumDir, { recursive: true });\n }\n const entryPath = path.join(heliumDir, \"server-entry.ts\");\n const envLoaderPath = path.join(heliumDir, \"env-loader.ts\");\n const serverModuleSrcPath = path.join(heliumDir, \"server-module.ts\");\n const ssrClientStubPath = path.join(heliumDir, \"ssr-client-stub.ts\");\n const ssrTransitionsStubPath = path.join(heliumDir, \"ssr-transitions-stub.ts\");\n const ssrPrefetchStubPath = path.join(heliumDir, \"ssr-prefetch-stub.ts\");\n\n const ssrClientStubCode = `\nimport React from 'react';\n\nexport const RouterContext = React.createContext(null);\n\nfunction getSSRRouterSnapshot() {\n const snapshot = globalThis.__HELIUM_SSR_ROUTER__ as\n | { path?: string; params?: Record<string, string | string[]>; search?: string }\n | undefined;\n\n if (!snapshot || typeof snapshot !== 'object') {\n return {\n path: '/',\n params: {},\n search: '',\n };\n }\n\n return {\n path: typeof snapshot.path === 'string' ? snapshot.path : '/',\n params: snapshot.params && typeof snapshot.params === 'object' ? snapshot.params : {},\n search: typeof snapshot.search === 'string' ? snapshot.search : '',\n };\n}\n\nexport function useRouter() {\n const snapshot = getSSRRouterSnapshot();\n return {\n path: snapshot.path,\n params: snapshot.params,\n searchParams: new URLSearchParams(snapshot.search),\n push: () => {},\n replace: () => {},\n on: () => () => {},\n status: 200,\n isNavigating: false,\n isPending: false,\n };\n}\n\nexport function Link(props: { href?: string; children?: React.ReactNode } & Record<string, unknown>) {\n const { href = '#', children, ...rest } = props || {};\n return React.createElement('a', { href, ...rest }, children);\n}\n\nexport function Redirect() {\n return null;\n}\n\nexport function AppRouter() {\n return null;\n}\n\nexport function useCall() {\n return {\n call: async () => null,\n isCalling: false,\n error: null,\n };\n}\n\nexport function useFetch() {\n return {\n data: null,\n isLoading: false,\n error: null,\n refetch: async () => undefined,\n };\n}\n\nexport class RpcError extends Error {}\n\nexport function getRpcTransport() {\n return 'websocket';\n}\n\nexport function isAutoHttpOnMobileEnabled() {\n return false;\n}\n\nexport function preconnect() {}\n\nexport function isSSR() {\n return true;\n}\n`;\n\n const ssrTransitionsStubCode = `\nimport React from 'react';\n\nexport function useDeferredNavigation() {\n return {\n path: '/',\n deferredPath: '/',\n isStale: false,\n isPending: false,\n isTransitioning: false,\n };\n}\n\nexport function PageTransition({ children }: { children?: React.ReactNode }) {\n return React.createElement(React.Fragment, null, children);\n}\n`;\n\n const ssrPrefetchStubCode = `\nexport function prefetchRoute() {}\nexport function clearPrefetchCache() {}\n`;\n\n fs.writeFileSync(entryPath, entryCode);\n fs.writeFileSync(envLoaderPath, envLoaderCode);\n fs.writeFileSync(serverModuleSrcPath, serverModuleCode);\n fs.writeFileSync(ssrClientStubPath, ssrClientStubCode);\n fs.writeFileSync(ssrTransitionsStubPath, ssrTransitionsStubCode);\n fs.writeFileSync(ssrPrefetchStubPath, ssrPrefetchStubCode);\n\n // Bundle with esbuild\n try {\n await esbuild({\n entryPoints: [entryPath],\n outfile: path.join(root, \"dist\", \"server.js\"),\n bundle: true,\n platform: \"node\",\n format: \"esm\",\n jsx: \"automatic\",\n jsxImportSource: \"react\",\n plugins: [\n {\n name: \"helium-ssr-client-alias\",\n setup(build) {\n build.onResolve({ filter: /^heliumts\\/client$/ }, () => ({ path: ssrClientStubPath }));\n build.onResolve({ filter: /^heliumts\\/client\\/transitions$/ }, () => ({ path: ssrTransitionsStubPath }));\n build.onResolve({ filter: /^heliumts\\/client\\/prefetch$/ }, () => ({ path: ssrPrefetchStubPath }));\n },\n },\n ],\n external: [\n // External common database and heavy dependencies\n \"mongodb\",\n \"mongoose\",\n \"pg\",\n \"mysql\",\n \"mysql2\",\n \"sqlite3\",\n \"better-sqlite3\",\n \"redis\",\n // Node.js built-ins are automatically external, but let's be explicit\n \"crypto\",\n \"fs\",\n \"path\",\n \"http\",\n \"https\",\n \"stream\",\n \"zlib\",\n \"util\",\n ],\n target: \"node18\",\n metafile: true,\n banner: {\n js: \"import { createRequire } from 'module'; const require = createRequire(import.meta.url);\",\n },\n });\n\n // Display server build output\n const serverOutputPath = path.relative(root, path.join(root, \"dist\", \"server.js\"));\n const serverStats = fs.statSync(path.join(root, \"dist\", \"server.js\"));\n const serverSizeKB = (serverStats.size / 1024).toFixed(2);\n log(\"info\", ` ${serverOutputPath.padEnd(35)} ${serverSizeKB.padStart(8)} kB`);\n\n log(\"info\", \"Server build complete.\");\n\n // Transpile helium.config.ts to helium.config.js if it exists\n const configTsPath = path.join(root, \"helium.config.ts\");\n if (fs.existsSync(configTsPath)) {\n log(\"info\", \"Transpiling helium.config.ts...\");\n try {\n await esbuild({\n entryPoints: [configTsPath],\n outfile: path.join(root, \"dist\", \"helium.config.js\"),\n bundle: false,\n platform: \"node\",\n format: \"esm\",\n target: \"node18\",\n });\n log(\"info\", \"Config file transpiled to dist/helium.config.js\");\n } catch (e) {\n log(\"warn\", \"Failed to transpile config file:\", e);\n log(\"warn\", \"You may need to manually rename helium.config.ts to helium.config.js\");\n }\n } else {\n // Check if .js or .mjs config exists and copy it to dist\n const configJsPath = path.join(root, \"helium.config.js\");\n const configMjsPath = path.join(root, \"helium.config.mjs\");\n\n if (fs.existsSync(configJsPath)) {\n fs.copyFileSync(configJsPath, path.join(root, \"dist\", \"helium.config.js\"));\n log(\"info\", \"Copied helium.config.js to dist/\");\n } else if (fs.existsSync(configMjsPath)) {\n fs.copyFileSync(configMjsPath, path.join(root, \"dist\", \"helium.config.mjs\"));\n log(\"info\", \"Copied helium.config.mjs to dist/\");\n }\n }\n\n log(\"info\", \"--------------------------------\");\n log(\"info\", \"✓ Build finished successfully.\");\n log(\"info\", \"▶ Run 'helium start' to start the production server.\");\n\n // Exit cleanly after build completes\n process.exit(0);\n } catch (e) {\n log(\"error\", \"Server build failed:\", e);\n process.exit(1);\n }\n});\n\ncli.command(\"start\", \"Start production server\").action(async () => {\n const serverPath = path.join(root, \"dist\", \"server.js\");\n if (!fs.existsSync(serverPath)) {\n log(\"error\", 'Server build not found. Run \"helium build\" first.');\n process.exit(1);\n }\n\n // When running in production, look for config in dist directory first\n // This allows the transpiled config to be found\n const server = spawn(\"node\", [serverPath], {\n stdio: \"inherit\",\n shell: true,\n env: { ...process.env, HELIUM_CONFIG_DIR: path.join(root, \"dist\") },\n });\n server.on(\"close\", (code) => {\n process.exit(code || 0);\n });\n});\n\ncli.help();\ncli.parse();\n"]}
@@ -76,6 +76,7 @@ export declare function Link(props: LinkProps): import("react/jsx-runtime").JSX.
76
76
  export type AppShellProps<TPageProps extends Record<string, unknown> = Record<string, unknown>> = {
77
77
  Component: ComponentType<TPageProps>;
78
78
  pageProps: TPageProps;
79
+ children?: React.ReactNode;
79
80
  };
80
81
  export declare function AppRouter({ AppShell }: {
81
82
  AppShell?: ComponentType<AppShellProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../src/client/Router.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAuD,MAAM,OAAO,CAAC;AAS5E,KAAK,WAAW,GAAG,YAAY,GAAG,mBAAmB,CAAC;AACtD,KAAK,aAAa,GAAG,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,IAAI,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AAC;AAGF,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;CAAE,2CA0KlF"}
@@ -4,6 +4,38 @@ import { SEO_METADATA_RPC_METHOD } from "../runtime/internalMethods.js";
4
4
  import { isDevEnvironment } from "./env.js";
5
5
  import { buildRoutes } from "./routerManifest.js";
6
6
  import { isAutoHttpOnMobileEnabled, isMobileRpcDevice, rpcCallWithOptions } from "./rpcClient.js";
7
+ function getInitialSSRBootstrap() {
8
+ if (typeof window === "undefined") {
9
+ return null;
10
+ }
11
+ const globalWindow = window;
12
+ const payload = globalWindow.__HELIUM_SSR_DATA__;
13
+ if (!payload || typeof payload !== "object" || typeof payload.path !== "string" || typeof payload.props !== "object" || payload.props === null) {
14
+ return null;
15
+ }
16
+ return payload;
17
+ }
18
+ async function fetchSSRPageProps(path) {
19
+ try {
20
+ const response = await fetch(`/__helium__/page-props?path=${encodeURIComponent(path)}`, {
21
+ method: "GET",
22
+ headers: {
23
+ Accept: "application/json",
24
+ },
25
+ });
26
+ if (!response.ok) {
27
+ return null;
28
+ }
29
+ const payload = (await response.json());
30
+ if (!payload.ssr || !payload.props) {
31
+ return null;
32
+ }
33
+ return payload.props;
34
+ }
35
+ catch {
36
+ return null;
37
+ }
38
+ }
7
39
  class RouterEventEmitter {
8
40
  constructor() {
9
41
  this.listeners = new Map();
@@ -349,6 +381,17 @@ export function AppRouter({ AppShell }) {
349
381
  // Use useSyncExternalStore to subscribe to location changes
350
382
  // This ensures synchronous updates when location changes
351
383
  const state = useSyncExternalStore(subscribeToLocation, getLocationSnapshot, getServerSnapshot);
384
+ const [runtimeSSRProps, setRuntimeSSRProps] = React.useState(() => {
385
+ const payload = getInitialSSRBootstrap();
386
+ if (!payload) {
387
+ return {};
388
+ }
389
+ if (payload.path === window.location.pathname) {
390
+ return payload.props;
391
+ }
392
+ return {};
393
+ });
394
+ const [hydrationDone, setHydrationDone] = React.useState(false);
352
395
  const match = useMemo(() => matchRoute(state.path, routes), [state.path, routes]);
353
396
  // Use matched params, or fall back to re-extracting from path using global routes during HMR
354
397
  const currentParams = match?.params ?? (isDevEnvironment() ? extractParamsFromPath(state.path) : {});
@@ -374,6 +417,30 @@ export function AppRouter({ AppShell }) {
374
417
  isNavigating: state.isNavigating,
375
418
  isPending,
376
419
  };
420
+ React.useEffect(() => {
421
+ const targetPath = `${state.path}${window.location.search || ""}`;
422
+ // On first client render, if SSR payload already exists for this path, keep it.
423
+ if (!hydrationDone) {
424
+ const bootstrap = getInitialSSRBootstrap();
425
+ if (bootstrap && bootstrap.path === state.path) {
426
+ setHydrationDone(true);
427
+ return;
428
+ }
429
+ setHydrationDone(true);
430
+ }
431
+ let cancelled = false;
432
+ const load = async () => {
433
+ const props = await fetchSSRPageProps(targetPath);
434
+ if (cancelled) {
435
+ return;
436
+ }
437
+ setRuntimeSSRProps(props ?? {});
438
+ };
439
+ void load();
440
+ return () => {
441
+ cancelled = true;
442
+ };
443
+ }, [state.path, currentSearchParams.toString(), hydrationDone]);
377
444
  React.useEffect(() => {
378
445
  const controller = new AbortController();
379
446
  const targetPath = `${state.path}${window.location.search || ""}`;
@@ -406,6 +473,7 @@ export function AppRouter({ AppShell }) {
406
473
  }
407
474
  const Page = match.route.Component;
408
475
  const pageProps = {
476
+ ...runtimeSSRProps,
409
477
  params: match.params,
410
478
  searchParams: currentSearchParams,
411
479
  };
@@ -419,7 +487,7 @@ export function AppRouter({ AppShell }) {
419
487
  }
420
488
  return content;
421
489
  };
422
- const finalContent = AppShell ? _jsx(AppShell, { Component: WrappedPage, pageProps: {} }) : _jsx(WrappedPage, {});
490
+ const finalContent = AppShell ? (_jsx(AppShell, { Component: WrappedPage, pageProps: pageProps, children: _jsx(WrappedPage, {}) })) : (_jsx(WrappedPage, {}));
423
491
  return _jsx(RouterContext.Provider, { value: routerValue, children: finalContent });
424
492
  }
425
493
  function applyRouteMetadata(meta) {