@octanejs/vite-plugin 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ client/server builds, and preview when an `octane.config.ts` declares routes.
7
7
  ## Install
8
8
 
9
9
  ```sh
10
- pnpm add octane @octanejs/vite-plugin @tsrx/oxc@0.20.0
10
+ pnpm add octane @octanejs/vite-plugin @tsrx/oxc@0.23.0
11
11
  pnpm add -D vite
12
12
  ```
13
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octanejs/vite-plugin",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -43,20 +43,25 @@
43
43
  "types": "./types/node.d.ts",
44
44
  "import": "./src/server/node-http.js",
45
45
  "default": "./src/server/node-http.js"
46
+ },
47
+ "./seeds": {
48
+ "types": "./types/seeds.d.ts",
49
+ "import": "./src/seeds.js",
50
+ "default": "./src/seeds.js"
46
51
  }
47
52
  },
48
53
  "dependencies": {
49
- "@octanejs/app-core": "0.2.0",
54
+ "@octanejs/app-core": "0.3.0",
50
55
  "@ripple-ts/adapter": "^0.4.0"
51
56
  },
52
57
  "peerDependencies": {
53
- "octane": "^0.16.0",
58
+ "octane": "^0.17.0",
54
59
  "vite": "^8.0.16"
55
60
  },
56
61
  "devDependencies": {
57
62
  "@types/jsdom": "30.0.0",
58
63
  "@types/node": "^24.13.3",
59
- "octane": "0.16.0",
64
+ "octane": "0.17.0",
60
65
  "playwright": "^1.61.1",
61
66
  "playwright-webkit": "1.63.0",
62
67
  "vite": "^8.1.5"
package/src/index.js CHANGED
@@ -67,6 +67,7 @@ export {
67
67
  handleRpcRequest,
68
68
  handleServerRoute,
69
69
  is_rpc_request,
70
+ routeSeed,
70
71
  runMiddlewareChain,
71
72
  } from '@octanejs/app-core';
72
73
  export {
@@ -381,7 +382,7 @@ function createIslandsShellWarnings(server, projectRoot) {
381
382
 
382
383
  /**
383
384
  * Every module path the server can name in #__octane_data — page entries,
384
- * layouts, the preHydrate hook, and root boundaries. The generated hydrate
385
+ * layouts, the preHydrate hook, the data module, and root boundaries. The generated hydrate
385
386
  * entry maps each as a LITERAL `() => import('/src/…')`. Production needs the
386
387
  * map so Rollup chunks and hashes the modules; dev needs it so the imports go
387
388
  * through Vite's import analysis and share URL identity with every other
@@ -397,6 +398,7 @@ function collect_hydrate_module_paths(config) {
397
398
  .filter((r) => r.type === 'render')
398
399
  .flatMap((r) => [get_route_entry_path(/** @type {RenderRoute} */ (r).entry), r.layout]);
399
400
  if (cfg.router.preHydrate) entries.push(cfg.router.preHydrate);
401
+ if (cfg.data) entries.push(cfg.data);
400
402
  entries.push(
401
403
  get_route_entry_path(cfg.rootBoundary.pending),
402
404
  get_route_entry_path(cfg.rootBoundary.catch),
@@ -449,8 +451,10 @@ async function hydrate_entry_features(context, config, entries, clientBuild, pro
449
451
  rootBoundary,
450
452
  independentHydration: clientBuild.metadata().capabilities.independentHydration,
451
453
  streamedSignals: clientBuild.hasStreamedSignals,
454
+ // A root boundary or the data module's DataRoot wraps the route in a body no proof covers.
452
455
  voidRoot:
453
456
  !rootBoundary &&
457
+ !config.data &&
454
458
  imports.length > 0 &&
455
459
  (await provenVoidImports(context, RESOLVED_VIRTUAL_HYDRATE_ID, imports)).length ===
456
460
  imports.length,
@@ -897,10 +901,10 @@ export function octane(inlineOptions = {}) {
897
901
  compilerPlugin.api.provenVoidImports,
898
902
  )
899
903
  : null;
900
- if (!isBuild) {
901
- const loaded = octaneConfig ?? (await loadStartupConfig(root))?.config ?? null;
902
- entries = collect_hydrate_module_paths(loaded);
903
- }
904
+ const loaded = isBuild
905
+ ? buildOctaneConfig
906
+ : (octaneConfig ?? (await loadStartupConfig(root))?.config ?? null);
907
+ if (!isBuild) entries = collect_hydrate_module_paths(loaded);
904
908
  const file = write_project_generated_file(
905
909
  config,
906
910
  'client-entry.js',
@@ -910,6 +914,7 @@ export function octane(inlineOptions = {}) {
910
914
  clientBuildId: clientBuild.buildId,
911
915
  devClientBuild: !isBuild,
912
916
  ...features,
917
+ data: Boolean(loaded?.data),
913
918
  }),
914
919
  );
915
920
  return fs.readFileSync(file, 'utf-8');
@@ -1324,6 +1329,8 @@ export function octane(inlineOptions = {}) {
1324
1329
  routes: cfg.router.routes,
1325
1330
  octaneConfigPath: getOctaneConfigPath(root),
1326
1331
  rootBoundary: cfg.rootBoundary,
1332
+ data: cfg.data,
1333
+ dataRootModuleId: requireFromPlugin.resolve('@octanejs/app-core/data-root'),
1327
1334
  rpcModulePaths: [...serverModuleModules],
1328
1335
  clientAssetMap,
1329
1336
  clientBuild: completedClientBuild,
@@ -1462,6 +1469,7 @@ export function octane(inlineOptions = {}) {
1462
1469
  * output?: 'js' | 'ts',
1463
1470
  * profile?: boolean | 'auto',
1464
1471
  * strong?: boolean,
1472
+ * strongDependencies?: import('octane/compiler/vite').OctaneVitePluginOptions['strongDependencies'],
1465
1473
  * textTypes?: import('octane/compiler/vite').OctaneVitePluginOptions['textTypes'],
1466
1474
  * knownAttributeSpreads?: import('octane/compiler/vite').OctaneVitePluginOptions['knownAttributeSpreads'],
1467
1475
  * domBindingFixedProps?: import('octane/compiler/vite').OctaneVitePluginOptions['domBindingFixedProps'],
@@ -1508,17 +1516,13 @@ export function octane(inlineOptions = {}) {
1508
1516
  if (typeof compilerConfigHook === 'function') {
1509
1517
  compilerPlugin.config = function compilerConfigWithAppOptions(userConfig, env) {
1510
1518
  const projectRoot = userConfig.root ? path.resolve(userConfig.root) : process.cwd();
1511
- // Both inline compiler options override app config independently. Preserve
1512
- // the synchronous path when neither needs to read octane.config.ts.
1513
- if (inlineOptions.renderers !== undefined && inlineOptions.strong !== undefined) {
1514
- compilerConfigWatchFiles.clear();
1515
- return compilerConfigHook.call(this, userConfig, env);
1516
- }
1517
-
1519
+ // Inline `renderers` and `strong` override app config independently.
1520
+ // `strongDependencies` comes only from octane.config.ts, so it is always read.
1518
1521
  const configPath = getOctaneConfigPath(projectRoot);
1519
1522
  if (!octaneConfigExists(projectRoot)) {
1520
1523
  if (inlineOptions.renderers === undefined) delete compilerOptions.renderers;
1521
1524
  if (inlineOptions.strong === undefined) delete compilerOptions.strong;
1525
+ delete compilerOptions.strongDependencies;
1522
1526
  compilerConfigWatchFiles.clear();
1523
1527
  // A new app config can introduce Strong mode or renderer rules.
1524
1528
  compilerConfigWatchFiles.add(path.resolve(configPath));
@@ -1533,6 +1537,7 @@ export function octane(inlineOptions = {}) {
1533
1537
  if (inlineOptions.strong === undefined) {
1534
1538
  compilerOptions.strong = config.config.compiler.strong;
1535
1539
  }
1540
+ compilerOptions.strongDependencies = config.config.compiler.strongDependencies;
1536
1541
  compilerConfigWatchFiles.clear();
1537
1542
  for (const file of [...config.dependencies, ...config.missingDependencies]) {
1538
1543
  compilerConfigWatchFiles.add(path.resolve(file));
package/src/seeds.js ADDED
@@ -0,0 +1 @@
1
+ export { readRouteSeed, routeSeed } from '@octanejs/app-core/seeds';
@@ -2,4 +2,5 @@ export {
2
2
  createLayoutWrapper,
3
3
  createPropsWrapper,
4
4
  createRootBoundaryWrapper,
5
+ provideRouteData,
5
6
  } from '@octanejs/app-core/production';
@@ -1 +1 @@
1
- export { composeHtmlStream } from '@octanejs/app-core/html';
1
+ export { composeHtmlStream, endRoute, routeEnding } from '@octanejs/app-core/html';
@@ -3,7 +3,8 @@ import { readFile } from 'node:fs/promises';
3
3
  import { randomUUID } from 'node:crypto';
4
4
  import { join } from 'node:path';
5
5
  import { createRpcRegistry } from '@octanejs/app-core';
6
- import { composeHtmlStream } from './html-stream.js';
6
+ import { createRequire } from 'node:module';
7
+ import { composeHtmlStream, endRoute, routeEnding } from './html-stream.js';
7
8
  import {
8
9
  getContextNonce,
9
10
  injectHydrationEntry,
@@ -16,6 +17,7 @@ import {
16
17
  createLayoutWrapper,
17
18
  createPropsWrapper,
18
19
  createRootBoundaryWrapper,
20
+ provideRouteData,
19
21
  } from './component-wrappers.js';
20
22
  import {
21
23
  get_component_export,
@@ -23,6 +25,9 @@ import {
23
25
  get_route_entry_path,
24
26
  } from '../routes.js';
25
27
 
28
+ /** App-core's `DataRoot`, compiled for the server through Vite's SSR loader. */
29
+ const DATA_ROOT_MODULE = createRequire(import.meta.url).resolve('@octanejs/app-core/data-root');
30
+
26
31
  /**
27
32
  * @typedef {import('@octanejs/vite-plugin').Context} Context
28
33
  * @typedef {import('@octanejs/vite-plugin').RenderRoute} RenderRoute
@@ -208,6 +213,16 @@ export async function handleRenderRoute(
208
213
  { pending: PendingComponent, catch: CatchComponent },
209
214
  /** @type {any} */ (serverRuntime),
210
215
  );
216
+ const dataPath = octaneConfig?.data;
217
+ if (dataPath) {
218
+ const dataModule = await vite.ssrLoadModule(dataPath);
219
+ const { DataRoot } = await vite.ssrLoadModule(DATA_ROOT_MODULE);
220
+ RootComponent = provideRouteData(
221
+ context,
222
+ { path: dataPath, open: dataModule.default, Root: DataRoot },
223
+ RootComponent,
224
+ );
225
+ }
211
226
  // Discovery runs while loading the page/layout above. Snapshot capability
212
227
  // afterwards; its live registry also resolves widgets compiled lazily later.
213
228
  const clientBuild = getClientBuild?.();
@@ -232,6 +247,7 @@ export async function handleRenderRoute(
232
247
  params: context.params,
233
248
  url: requestUrl,
234
249
  preHydrate: octaneConfig?.router.preHydrate ?? null,
250
+ data: octaneConfig?.data ?? null,
235
251
  rootBoundary: {
236
252
  pending: serializeComponentEntry(pendingEntry),
237
253
  catch: serializeComponentEntry(catchEntry),
@@ -314,10 +330,17 @@ export async function handleRenderRoute(
314
330
 
315
331
  // Feature-bearing documents activate after the complete shell and its
316
332
  // selection authority; open result channels must not hold input hostage.
317
- const body = composeHtmlStream(prefix, renderStream, suffix, preparedTemplate.afterShell);
333
+ const body = composeHtmlStream(
334
+ prefix,
335
+ renderStream,
336
+ suffix,
337
+ preparedTemplate.afterShell,
338
+ routeEnding(context, nonceAttribute(nonce)),
339
+ );
318
340
 
319
341
  return new Response(body, { status, headers });
320
342
  } catch (error) {
343
+ endRoute(context);
321
344
  console.error('[octane] SSR render error:', error);
322
345
 
323
346
  const errorHtml = generateErrorHtml(error, route);
@@ -0,0 +1 @@
1
+ export * from '@octanejs/app-core/seeds';