@ecopages/react 0.2.0-beta.25 → 0.2.0-beta.27

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 (98) hide show
  1. package/README.md +17 -9
  2. package/package.json +42 -34
  3. package/src/{services/react-bundle.service.d.ts → bundling/bundle.d.ts} +7 -7
  4. package/src/{services/react-bundle.service.js → bundling/bundle.js} +9 -11
  5. package/src/{utils → bundling}/discover-layout-runtime-modules.js +2 -2
  6. package/src/{utils/react-runtime-alias-map.d.ts → bundling/runtime-alias-map.d.ts} +3 -3
  7. package/src/{services/react-runtime-bundle.service.d.ts → bundling/runtime-bundle.d.ts} +5 -5
  8. package/src/{services/react-runtime-bundle.service.js → bundling/runtime-bundle.js} +4 -4
  9. package/src/bundling/runtime-mode.d.ts +9 -0
  10. package/src/bundling/runtime-mode.js +6 -0
  11. package/src/{utils/client-graph-ast-transform.d.ts → client-graph/ast-transform.d.ts} +1 -1
  12. package/src/{utils/client-graph-ast-transform.js → client-graph/ast-transform.js} +1 -1
  13. package/src/{utils/client-graph-boundary-cache.d.ts → client-graph/boundary-cache.d.ts} +0 -5
  14. package/src/{utils/client-graph-boundary-cache.js → client-graph/boundary-cache.js} +1 -3
  15. package/src/{utils/client-graph-boundary-plugin.d.ts → client-graph/boundary-plugin.d.ts} +1 -1
  16. package/src/{utils/client-graph-boundary-plugin.js → client-graph/boundary-plugin.js} +3 -3
  17. package/src/{utils/client-graph-reachability.d.ts → client-graph/specifier-classification.d.ts} +1 -1
  18. package/src/{react-hmr-strategy.d.ts → hmr/hmr-strategy.d.ts} +3 -6
  19. package/src/{react-hmr-strategy.js → hmr/hmr-strategy.js} +11 -20
  20. package/src/{services/react-hmr-page-metadata-cache.d.ts → hmr/page-metadata-cache.d.ts} +5 -1
  21. package/src/{services/react-hmr-page-metadata-cache.js → hmr/page-metadata-cache.js} +8 -2
  22. package/src/{services/react-hydration-asset.service.d.ts → hydration/hydration-asset.d.ts} +33 -33
  23. package/src/{services/react-hydration-asset.service.js → hydration/hydration-asset.js} +45 -52
  24. package/src/{utils → hydration}/hydration-scripts.d.ts +33 -41
  25. package/src/hydration/hydration-scripts.js +353 -0
  26. package/src/{utils → hydration}/hydration-scripts.test.browser.js +6 -4
  27. package/src/hydration/page-data-manifest.d.ts +58 -0
  28. package/src/hydration/page-data-manifest.js +53 -0
  29. package/src/hydration/page-data-reader.d.ts +31 -0
  30. package/src/hydration/page-data-reader.js +64 -0
  31. package/src/hydration/page-payload.d.ts +67 -0
  32. package/src/hydration/page-payload.js +104 -0
  33. package/src/hydration/serialize-page-data-script.d.ts +27 -0
  34. package/src/hydration/serialize-page-data-script.js +31 -0
  35. package/src/{services/react-mdx-config-dependency.service.d.ts → mdx/mdx-config-dependency.d.ts} +5 -5
  36. package/src/{services/react-mdx-config-dependency.service.js → mdx/mdx-config-dependency.js} +3 -3
  37. package/src/{services/react-page-module.service.d.ts → page/page-module.d.ts} +4 -7
  38. package/src/{services/react-page-module.service.js → page/page-module.js} +5 -9
  39. package/src/{react.plugin.d.ts → plugin/react.plugin.d.ts} +7 -3
  40. package/src/{react.plugin.js → plugin/react.plugin.js} +32 -30
  41. package/src/{react.types.d.ts → plugin/react.types.d.ts} +23 -8
  42. package/src/render/component-ownership.d.ts +50 -0
  43. package/src/render/component-ownership.js +23 -0
  44. package/src/render/component-ssr.d.ts +113 -0
  45. package/src/render/component-ssr.js +202 -0
  46. package/src/render/errors.d.ts +16 -0
  47. package/src/render/errors.js +18 -0
  48. package/src/{layout-compose.d.ts → render/layout-compose.d.ts} +8 -0
  49. package/src/{layout-compose.js → render/layout-compose.js} +14 -6
  50. package/src/render/react-renderer.d.ts +137 -0
  51. package/src/render/react-renderer.js +444 -0
  52. package/src/render/react-runtime.d.ts +13 -0
  53. package/src/render/react-runtime.js +21 -0
  54. package/src/render/unified-layout-composition.d.ts +53 -0
  55. package/src/render/unified-layout-composition.js +89 -0
  56. package/src/react-renderer.d.ts +0 -254
  57. package/src/react-renderer.js +0 -726
  58. package/src/serialize-page-data-script.d.ts +0 -8
  59. package/src/serialize-page-data-script.js +0 -10
  60. package/src/services/pages-index.d.ts +0 -64
  61. package/src/services/pages-index.js +0 -73
  62. package/src/services/react-page-payload.service.d.ts +0 -46
  63. package/src/services/react-page-payload.service.js +0 -67
  64. package/src/utils/hydration-scripts.js +0 -371
  65. /package/src/{utils → app}/client-only.d.ts +0 -0
  66. /package/src/{utils → app}/client-only.js +0 -0
  67. /package/src/{utils → app}/dynamic.d.ts +0 -0
  68. /package/src/{utils → app}/dynamic.js +0 -0
  69. /package/src/{utils → app}/dynamic.test.browser.d.ts +0 -0
  70. /package/src/{utils → app}/dynamic.test.browser.js +0 -0
  71. /package/src/{utils → bundling}/discover-layout-runtime-modules.d.ts +0 -0
  72. /package/src/{utils/react-runtime-alias-map.js → bundling/runtime-alias-map.js} +0 -0
  73. /package/src/{utils/react-dom-runtime-interop-plugin.d.ts → bundling/runtime-interop-plugin.d.ts} +0 -0
  74. /package/src/{utils/react-dom-runtime-interop-plugin.js → bundling/runtime-interop-plugin.js} +0 -0
  75. /package/src/{utils/react-plugin-runtime-modules.d.ts → bundling/runtime-modules.d.ts} +0 -0
  76. /package/src/{utils/react-plugin-runtime-modules.js → bundling/runtime-modules.js} +0 -0
  77. /package/src/{utils → client-graph}/component-config-traversal.d.ts +0 -0
  78. /package/src/{utils → client-graph}/component-config-traversal.js +0 -0
  79. /package/src/{utils → client-graph}/declared-modules.d.ts +0 -0
  80. /package/src/{utils → client-graph}/declared-modules.js +0 -0
  81. /package/src/{utils → client-graph}/reachability-analyzer.d.ts +0 -0
  82. /package/src/{utils → client-graph}/reachability-analyzer.js +0 -0
  83. /package/src/{utils/client-graph-reachability.js → client-graph/specifier-classification.js} +0 -0
  84. /package/src/{declarations.d.ts → contracts/declarations.d.ts} +0 -0
  85. /package/src/{router-adapter.d.ts → contracts/router-adapter.d.ts} +0 -0
  86. /package/src/{router-adapter.js → contracts/router-adapter.js} +0 -0
  87. /package/src/{utils → hmr}/hmr-scripts.d.ts +0 -0
  88. /package/src/{utils → hmr}/hmr-scripts.js +0 -0
  89. /package/src/{utils → hydration}/hydration-scripts.test.browser.d.ts +0 -0
  90. /package/src/{utils/react-mdx-loader-plugin.d.ts → mdx/mdx-loader-plugin.d.ts} +0 -0
  91. /package/src/{utils/react-mdx-loader-plugin.js → mdx/mdx-loader-plugin.js} +0 -0
  92. /package/src/{react.constants.d.ts → plugin/react.constants.d.ts} +0 -0
  93. /package/src/{react.constants.js → plugin/react.constants.js} +0 -0
  94. /package/src/{react.types.js → plugin/react.types.js} +0 -0
  95. /package/src/{eco-embed.d.ts → render/eco-embed.d.ts} +0 -0
  96. /package/src/{eco-embed.js → render/eco-embed.js} +0 -0
  97. /package/src/{utils → render}/html-boundary.d.ts +0 -0
  98. /package/src/{utils → render}/html-boundary.js +0 -0
package/README.md CHANGED
@@ -109,6 +109,14 @@ Think about each React page as two related graphs:
109
109
 
110
110
  The React integration builds the client graph conservatively. If a server-only module becomes reachable from the hydrated render path, the build should fail rather than silently shipping unsafe code.
111
111
 
112
+ ### `explicitGraph` option
113
+
114
+ `reactPlugin({ explicitGraph: true })` forces the page browser graph (hydration assets) to emit for every React page, even when the page does not declare `dependencies.modules` and no router is configured.
115
+
116
+ It does **not** disable the client-graph AST boundary. Server-only `eco.page(...)` options such as `middleware` and `requires` are still stripped from browser bundles. With a router adapter, page hydration is already always on, so the option is redundant for SPA apps.
117
+
118
+ The option name is historical — it forces hydration asset emission, it does not mean “skip graph transforms.”
119
+
112
120
  ### What Stays and What Goes
113
121
 
114
122
  The client bundle keeps:
@@ -131,7 +139,7 @@ Important:
131
139
 
132
140
  ### AST Pipeline Order
133
141
 
134
- The browser-bound transform in [src/utils/client-graph-boundary-plugin.ts](src/utils/client-graph-boundary-plugin.ts) follows this order:
142
+ The browser-bound transform in [src/client-graph/boundary-plugin.ts](src/client-graph/boundary-plugin.ts) follows this order:
135
143
 
136
144
  1. Parse the module and build a reachability view of the client render graph.
137
145
  2. Remove imports that are not allowed or not reachable from the client graph.
@@ -166,7 +174,7 @@ The fix is to strip server-only `eco.page(...)` options after import pruning, wh
166
174
 
167
175
  The browser must not receive arbitrary request-scoped data.
168
176
 
169
- The React renderer in [src/react-renderer.ts](src/react-renderer.ts) serializes only the top-level `locals` keys explicitly declared by `Page.requires`. If a page does not declare `requires`, no `locals` are serialized for hydration.
177
+ The React renderer in [src/render/react-renderer.ts](src/render/react-renderer.ts) serializes only the top-level `locals` keys explicitly declared by `Page.requires`. If a page does not declare `requires`, no `locals` are serialized for hydration.
170
178
 
171
179
  Example:
172
180
 
@@ -191,7 +199,7 @@ Hydration must rebuild the same tree the server rendered.
191
199
 
192
200
  That applies to both:
193
201
 
194
- - non-router hydration scripts in [src/utils/hydration-scripts.ts](src/utils/hydration-scripts.ts)
202
+ - non-router hydration scripts in [src/hydration/hydration-scripts.ts](src/hydration/hydration-scripts.ts)
195
203
  - router-backed hydration in [../../react-router/src/router.ts](../../react-router/src/router.ts)
196
204
 
197
205
  If the page render receives `locals` on the server and the layout also depends on those values, the client must pass the same serialized `locals` into the layout during hydration. Otherwise React will detect a mismatch.
@@ -200,9 +208,9 @@ If the page render receives `locals` on the server and the layout also depends o
200
208
 
201
209
  The main regression coverage lives in:
202
210
 
203
- - [src/utils/client-graph-boundary-plugin.test.ts](src/utils/client-graph-boundary-plugin.test.ts): verifies server-only `eco.page(...)` options are stripped from browser bundles.
204
- - [src/react-renderer.locals.test.ts](src/react-renderer.locals.test.ts): verifies only declared `requires` keys are serialized into hydration payloads.
205
- - [src/utils/hydration-scripts.test.ts](src/utils/hydration-scripts.test.ts): verifies non-router hydration passes serialized `locals` into layouts.
211
+ - [src/client-graph/boundary-plugin.test.ts](src/client-graph/boundary-plugin.test.ts): verifies server-only `eco.page(...)` options are stripped from browser bundles.
212
+ - [src/render/react-renderer.locals.test.ts](src/render/react-renderer.locals.test.ts): verifies only declared `requires` keys are serialized into hydration payloads.
213
+ - [src/hydration/hydration-scripts.test.ts](src/hydration/hydration-scripts.test.ts): verifies non-router hydration passes serialized `locals` into layouts.
206
214
  - [../../react-router/test/hmr-reload.test.browser.ts](../../react-router/test/hmr-reload.test.browser.ts): verifies router-backed layout hydration receives `locals` with `persistLayouts` both enabled and disabled.
207
215
 
208
216
  If you change the AST transform or hydration flow, update the corresponding tests in the same change.
@@ -215,7 +223,7 @@ During SSR, `ReactRenderer` passes the app-resolved React runtime into `composeL
215
223
 
216
224
  Layout prop factories receive `LayoutPropsContext` (`params`, `query`, `locals`). Route-scoped `locals` are passed to layout tiers via document-shell props during SSR; serialized `pageProps.locals` follow `Page.requires` and are intended for the page component.
217
225
 
218
- - [src/layout-compose.ts](src/layout-compose.ts): shared client/SSR tree builder.
226
+ - [src/render/layout-compose.ts](src/render/layout-compose.ts): shared client/SSR tree builder.
219
227
  - [src/test/react-ssr-hydration-parity.test.tsx](src/test/react-ssr-hydration-parity.test.tsx): nested tier order parity between SSR and `composeLayoutPageTree`.
220
228
  - [src/test/react-ssr-unified.test.tsx](src/test/react-ssr-unified.test.tsx): provider context through nested SSR layouts.
221
229
 
@@ -333,8 +341,8 @@ Manual entries **override** auto-discovered entries for the same specifier.
333
341
 
334
342
  #### Tests
335
343
 
336
- - [src/utils/discover-layout-runtime-modules.test.ts](src/utils/discover-layout-runtime-modules.test.ts): discovery modes, provider scoping, tsconfig aliases, stacked layouts.
337
- - [src/services/react-runtime-bundle.service.test.ts](src/services/react-runtime-bundle.service.test.ts): vendor registration and manifest paths.
344
+ - [src/bundling/discover-layout-runtime-modules.test.ts](src/bundling/discover-layout-runtime-modules.test.ts): discovery modes, provider scoping, tsconfig aliases, stacked layouts.
345
+ - [src/bundling/runtime-bundle.test.ts](src/bundling/runtime-bundle.test.ts): vendor registration and manifest paths.
338
346
  - [../../core/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.test.ts](../../core/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.test.ts): ESM entry resolution and default-export policy for React vs TanStack Query.
339
347
 
340
348
  ### Client-only code in SSR trees
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/react",
3
- "version": "0.2.0-beta.25",
3
+ "version": "0.2.0-beta.27",
4
4
  "description": "React integration for Ecopages",
5
5
  "keywords": [
6
6
  "ecopages",
@@ -8,75 +8,83 @@
8
8
  "plugin"
9
9
  ],
10
10
  "license": "MIT",
11
- "main": "./src/react.plugin.js",
12
- "types": "./src/react.plugin.d.ts",
11
+ "main": "./src/plugin/react.plugin.js",
12
+ "types": "./src/plugin/react.plugin.d.ts",
13
13
  "type": "module",
14
14
  "exports": {
15
15
  ".": {
16
- "default": "./src/react.plugin.js",
17
- "types": "./src/react.plugin.d.ts"
16
+ "default": "./src/plugin/react.plugin.js",
17
+ "types": "./src/plugin/react.plugin.d.ts"
18
18
  },
19
19
  "./eco-embed": {
20
- "default": "./src/eco-embed.js",
21
- "types": "./src/eco-embed.d.ts"
20
+ "default": "./src/render/eco-embed.js",
21
+ "types": "./src/render/eco-embed.d.ts"
22
22
  },
23
23
  "./declarations": {
24
- "types": "./src/declarations.d.ts"
24
+ "types": "./src/contracts/declarations.d.ts"
25
25
  },
26
26
  "./utils/dynamic": {
27
- "types": "./src/utils/dynamic.d.ts",
28
- "default": "./src/utils/dynamic.js"
27
+ "types": "./src/app/dynamic.d.ts",
28
+ "default": "./src/app/dynamic.js"
29
29
  },
30
30
  "./utils/client-only": {
31
- "types": "./src/utils/client-only.d.ts",
32
- "default": "./src/utils/client-only.js"
31
+ "types": "./src/app/client-only.d.ts",
32
+ "default": "./src/app/client-only.js"
33
33
  },
34
34
  "./runtime/use-sync-external-store-with-selector": {
35
35
  "types": "./src/runtime/use-sync-external-store-with-selector.d.ts",
36
36
  "default": "./src/runtime/use-sync-external-store-with-selector.js"
37
37
  },
38
38
  "./router-adapter": {
39
- "types": "./src/router-adapter.d.ts",
40
- "default": "./src/router-adapter.js"
39
+ "types": "./src/contracts/router-adapter.d.ts",
40
+ "default": "./src/contracts/router-adapter.js"
41
41
  },
42
42
  "./layout-compose": {
43
- "types": "./src/layout-compose.d.ts",
44
- "default": "./src/layout-compose.js"
43
+ "types": "./src/render/layout-compose.d.ts",
44
+ "default": "./src/render/layout-compose.js"
45
45
  },
46
46
  "./serialize-page-data-script": {
47
- "types": "./src/serialize-page-data-script.d.ts",
48
- "default": "./src/serialize-page-data-script.js"
47
+ "types": "./src/hydration/serialize-page-data-script.d.ts",
48
+ "default": "./src/hydration/serialize-page-data-script.js"
49
+ },
50
+ "./page-data-reader": {
51
+ "types": "./src/hydration/page-data-reader.d.ts",
52
+ "default": "./src/hydration/page-data-reader.js"
49
53
  },
50
54
  "./eco-embed.ts": {
51
- "default": "./src/eco-embed.js",
52
- "types": "./src/eco-embed.d.ts"
55
+ "default": "./src/render/eco-embed.js",
56
+ "types": "./src/render/eco-embed.d.ts"
53
57
  },
54
58
  "./declarations.ts": {
55
- "types": "./src/declarations.d.ts"
59
+ "types": "./src/contracts/declarations.d.ts"
56
60
  },
57
61
  "./utils/dynamic.ts": {
58
- "types": "./src/utils/dynamic.d.ts",
59
- "default": "./src/utils/dynamic.js"
62
+ "types": "./src/app/dynamic.d.ts",
63
+ "default": "./src/app/dynamic.js"
60
64
  },
61
65
  "./utils/client-only.ts": {
62
- "types": "./src/utils/client-only.d.ts",
63
- "default": "./src/utils/client-only.js"
66
+ "types": "./src/app/client-only.d.ts",
67
+ "default": "./src/app/client-only.js"
64
68
  },
65
69
  "./runtime/use-sync-external-store-with-selector.ts": {
66
70
  "types": "./src/runtime/use-sync-external-store-with-selector.d.ts",
67
71
  "default": "./src/runtime/use-sync-external-store-with-selector.js"
68
72
  },
69
73
  "./router-adapter.ts": {
70
- "types": "./src/router-adapter.d.ts",
71
- "default": "./src/router-adapter.js"
74
+ "types": "./src/contracts/router-adapter.d.ts",
75
+ "default": "./src/contracts/router-adapter.js"
72
76
  },
73
77
  "./layout-compose.ts": {
74
- "types": "./src/layout-compose.d.ts",
75
- "default": "./src/layout-compose.js"
78
+ "types": "./src/render/layout-compose.d.ts",
79
+ "default": "./src/render/layout-compose.js"
76
80
  },
77
81
  "./serialize-page-data-script.ts": {
78
- "types": "./src/serialize-page-data-script.d.ts",
79
- "default": "./src/serialize-page-data-script.js"
82
+ "types": "./src/hydration/serialize-page-data-script.d.ts",
83
+ "default": "./src/hydration/serialize-page-data-script.js"
84
+ },
85
+ "./page-data-reader.ts": {
86
+ "types": "./src/hydration/page-data-reader.d.ts",
87
+ "default": "./src/hydration/page-data-reader.js"
80
88
  }
81
89
  },
82
90
  "repository": {
@@ -85,16 +93,16 @@
85
93
  "directory": "packages/integrations/react"
86
94
  },
87
95
  "peerDependencies": {
88
- "@ecopages/core": "0.2.0-beta.25",
96
+ "@ecopages/core": "0.2.0-beta.27",
89
97
  "@types/react": "^19",
90
98
  "@types/react-dom": "^19",
91
99
  "react": "^19",
92
100
  "react-dom": "^19"
93
101
  },
94
102
  "dependencies": {
95
- "@ecopages/file-system": "0.2.0-beta.25",
103
+ "@ecopages/file-system": "0.2.0-beta.27",
96
104
  "@ecopages/logger": "^0.2.3",
97
- "@ecopages/mdx": "0.2.0-beta.25",
105
+ "@ecopages/mdx": "0.2.0-beta.27",
98
106
  "@mdx-js/mdx": "^3.1.1",
99
107
  "oxc-parser": "^0.124.0",
100
108
  "oxc-transform": "^0.124.0",
@@ -7,14 +7,14 @@
7
7
  * @module
8
8
  */
9
9
  import type { EcoPagesAppConfig } from '@ecopages/core';
10
- import type { ReactRouterAdapter } from '../router-adapter.js';
10
+ import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
11
11
  import type { CompileOptions } from '@mdx-js/mdx';
12
- import { type ReactRuntimeImports } from './react-runtime-bundle.service.js';
13
- import type { ResolvedReactPluginRuntimeModule } from '../utils/react-plugin-runtime-modules.js';
12
+ import { type ReactRuntimeImports } from './runtime-bundle.js';
13
+ import type { ResolvedReactPluginRuntimeModule } from './runtime-modules.js';
14
14
  /**
15
- * Configuration for the ReactBundleService.
15
+ * Configuration for the BundleService.
16
16
  */
17
- export interface ReactBundleServiceConfig {
17
+ export interface BundleServiceConfig {
18
18
  rootDir: string;
19
19
  appConfig: EcoPagesAppConfig;
20
20
  hostIntegrationName: string;
@@ -39,10 +39,10 @@ export interface ReactClientBundleOptions {
39
39
  /**
40
40
  * Manages bundle configuration and plugin creation for React page/component builds.
41
41
  */
42
- export declare class ReactBundleService {
42
+ export declare class BundleService {
43
43
  private readonly runtimeBundleService;
44
44
  private readonly config;
45
- constructor(config: ReactBundleServiceConfig);
45
+ constructor(config: BundleServiceConfig);
46
46
  /**
47
47
  * Returns resolved runtime import paths for the React runtime.
48
48
  */
@@ -1,18 +1,16 @@
1
- import { createClientGraphBoundaryPlugin } from "../utils/client-graph-boundary-plugin.js";
2
- import {
3
- getReactClientGraphAllowSpecifiers,
4
- getReactRuntimeExternalSpecifiers
5
- } from "../utils/react-runtime-alias-map.js";
1
+ import { createClientGraphBoundaryPlugin } from "../client-graph/boundary-plugin.js";
2
+ import { getReactClientGraphAllowSpecifiers, getReactRuntimeExternalSpecifiers } from "./runtime-alias-map.js";
6
3
  import { createBrowserRuntimePlugin } from "@ecopages/core/build/browser-runtime-plugin";
7
4
  import { getHostScopedJsxOwnershipPlugins } from "@ecopages/core/build/jsx-ownership-plugins";
8
- import { ReactRuntimeBundleService } from "./react-runtime-bundle.service.js";
9
- import { createReactMdxLoaderPlugin } from "../utils/react-mdx-loader-plugin.js";
10
- class ReactBundleService {
5
+ import { RuntimeBundleService } from "./runtime-bundle.js";
6
+ import { createReactMdxLoaderPlugin } from "../mdx/mdx-loader-plugin.js";
7
+ import { isReactProductionRuntime } from "./runtime-mode.js";
8
+ class BundleService {
11
9
  runtimeBundleService;
12
10
  config;
13
11
  constructor(config) {
14
12
  this.config = config;
15
- this.runtimeBundleService = new ReactRuntimeBundleService({
13
+ this.runtimeBundleService = new RuntimeBundleService({
16
14
  rootDir: config.rootDir,
17
15
  routerAdapter: config.routerAdapter,
18
16
  runtimeModules: config.runtimeModules
@@ -41,7 +39,7 @@ class ReactBundleService {
41
39
  const options = {
42
40
  mainFields: ["module", "browser", "main"],
43
41
  naming: `${componentName}.[ext]`,
44
- ...import.meta.env?.NODE_ENV === "production" && {
42
+ ...isReactProductionRuntime() && {
45
43
  minify: true,
46
44
  treeshaking: true
47
45
  },
@@ -96,5 +94,5 @@ class ReactBundleService {
96
94
  }
97
95
  }
98
96
  export {
99
- ReactBundleService
97
+ BundleService
100
98
  };
@@ -4,8 +4,8 @@ import {
4
4
  isBarePackageImportSpecifier,
5
5
  resolveProjectModulePath
6
6
  } from "@ecopages/core/plugins/tsconfig-import-resolver";
7
- import { analyzeReachability } from "./reachability-analyzer.js";
8
- import { REACT_RUNTIME_SPECIFIERS } from "./react-runtime-alias-map.js";
7
+ import { analyzeReachability } from "../client-graph/reachability-analyzer.js";
8
+ import { REACT_RUNTIME_SPECIFIERS } from "./runtime-alias-map.js";
9
9
  const MODULE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
10
10
  const AUTO_RUNTIME_EXCLUDED_SPECIFIERS = /* @__PURE__ */ new Set([
11
11
  ...REACT_RUNTIME_SPECIFIERS,
@@ -1,6 +1,6 @@
1
- import type { ReactRouterAdapter } from '../router-adapter.js';
2
- import type { ReactRuntimeImports } from '../services/react-runtime-bundle.service.js';
3
- import type { ResolvedReactPluginRuntimeModule } from './react-plugin-runtime-modules.js';
1
+ import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
2
+ import type { ReactRuntimeImports } from './runtime-bundle.js';
3
+ import type { ResolvedReactPluginRuntimeModule } from './runtime-modules.js';
4
4
  import { type BrowserRuntimeAssetDeclaration, type BrowserRuntimeManifest } from '@ecopages/core/build/browser-runtime-manifest';
5
5
  export declare const REACT_RUNTIME_SPECIFIERS: readonly ["react", "react-dom", "react/jsx-runtime", "react/jsx-dev-runtime", "react-dom/client"];
6
6
  export declare function buildReactRuntimeAliasMap(runtimeImports: ReactRuntimeImports): Record<string, string>;
@@ -8,8 +8,8 @@
8
8
  */
9
9
  import type { EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
10
10
  import { type AssetDefinition } from '@ecopages/core/services/asset-processing-service';
11
- import type { ReactRouterAdapter } from '../router-adapter.js';
12
- import type { ResolvedReactPluginRuntimeModule } from '../utils/react-plugin-runtime-modules.js';
11
+ import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
12
+ import type { ResolvedReactPluginRuntimeModule } from './runtime-modules.js';
13
13
  import { type BrowserRuntimeManifest } from '@ecopages/core/build/browser-runtime-manifest';
14
14
  export type ReactRuntimeImports = {
15
15
  react: string;
@@ -20,16 +20,16 @@ export type ReactRuntimeImports = {
20
20
  useSyncExternalStoreWithSelector: string;
21
21
  router?: string;
22
22
  };
23
- export interface ReactRuntimeBundleServiceConfig {
23
+ export interface RuntimeBundleServiceConfig {
24
24
  routerAdapter?: ReactRouterAdapter;
25
25
  runtimeModules?: ResolvedReactPluginRuntimeModule[];
26
26
  rootDir?: string;
27
27
  workDir?: string;
28
28
  }
29
29
  type RuntimeMode = 'development' | 'production';
30
- export declare class ReactRuntimeBundleService {
30
+ export declare class RuntimeBundleService {
31
31
  private readonly config;
32
- constructor(config: ReactRuntimeBundleServiceConfig);
32
+ constructor(config: RuntimeBundleServiceConfig);
33
33
  setRootDir(rootDir: string | undefined): void;
34
34
  setWorkDir(workDir: string | undefined): void;
35
35
  setRuntimeModules(runtimeModules: ResolvedReactPluginRuntimeModule[]): void;
@@ -5,16 +5,16 @@ import {
5
5
  createBrowserRuntimeModuleAsset,
6
6
  createBrowserRuntimeScriptAsset
7
7
  } from "@ecopages/core/services/asset-processing-service";
8
- import { createReactDomRuntimeInteropPlugin } from "../utils/react-dom-runtime-interop-plugin.js";
8
+ import { createReactDomRuntimeInteropPlugin } from "./runtime-interop-plugin.js";
9
9
  import {
10
10
  buildReactRuntimeAliasMap,
11
11
  buildReactRuntimeManifest,
12
12
  getReactRuntimeExternalSpecifiers
13
- } from "../utils/react-runtime-alias-map.js";
13
+ } from "./runtime-alias-map.js";
14
14
  import {
15
15
  createBrowserRuntimeManifest
16
16
  } from "@ecopages/core/build/browser-runtime-manifest";
17
- class ReactRuntimeBundleService {
17
+ class RuntimeBundleService {
18
18
  config;
19
19
  constructor(config) {
20
20
  this.config = config;
@@ -234,5 +234,5 @@ class ReactRuntimeBundleService {
234
234
  }
235
235
  }
236
236
  export {
237
- ReactRuntimeBundleService
237
+ RuntimeBundleService
238
238
  };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Production runtime check for React bundle and hydration policy.
3
+ *
4
+ * @remarks
5
+ * Matches core `isProductionRuntime` (`NODE_ENV === 'production'`) without a new
6
+ * `@ecopages/core` export. Keeping this boundary shared ensures hosted-development
7
+ * runtime imports and production bundle optimizations use the same definition.
8
+ */
9
+ export declare function isReactProductionRuntime(): boolean;
@@ -0,0 +1,6 @@
1
+ function isReactProductionRuntime() {
2
+ return process.env.NODE_ENV === "production";
3
+ }
4
+ export {
5
+ isReactProductionRuntime
6
+ };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * AST transforms for the client graph boundary plugin.
3
3
  */
4
- import type { RequestedExportRules } from './client-graph-boundary-cache.js';
4
+ import type { RequestedExportRules } from './boundary-cache.js';
5
5
  /**
6
6
  * Parses a module using Oxc AST and surgically removes forbidden imports.
7
7
  * Filters down to the exact specifiers requested via `{namedImport}` syntax.
@@ -11,7 +11,7 @@ import {
11
11
  normalizeRequestedExportsKey,
12
12
  resolveRequestedExportsKey,
13
13
  mergeRequestedExportRules
14
- } from "./client-graph-reachability.js";
14
+ } from "./specifier-classification.js";
15
15
  const SERVER_ONLY_ECO_PAGE_OPTION_KEYS = /* @__PURE__ */ new Set([
16
16
  "cache",
17
17
  "middleware",
@@ -101,8 +101,3 @@ export declare class ClientGraphBoundaryCache {
101
101
  hitRate: number;
102
102
  };
103
103
  }
104
- /**
105
- * Default shared cache. The React plugin owns one of these; tests can
106
- * create their own.
107
- */
108
- export declare const clientGraphBoundaryCache: ClientGraphBoundaryCache;
@@ -105,12 +105,10 @@ class ClientGraphBoundaryCache {
105
105
  };
106
106
  }
107
107
  }
108
- const clientGraphBoundaryCache = new ClientGraphBoundaryCache();
109
108
  function hashAllowList(specifiers) {
110
109
  const sorted = Array.from(specifiers).sort();
111
110
  return rapidhash(sorted.join("\n"));
112
111
  }
113
112
  export {
114
- ClientGraphBoundaryCache,
115
- clientGraphBoundaryCache
113
+ ClientGraphBoundaryCache
116
114
  };
@@ -4,7 +4,7 @@
4
4
  * Build plugin securing the Ecopages isomorphic compilation pipeline.
5
5
  */
6
6
  import type { EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
7
- import { ClientGraphBoundaryCache } from './client-graph-boundary-cache.js';
7
+ import { ClientGraphBoundaryCache } from './boundary-cache.js';
8
8
  /**
9
9
  * Configuration options for the Client Graph Boundary build plugin.
10
10
  *
@@ -1,14 +1,14 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { dirname, extname, resolve } from "node:path";
3
- import { ClientGraphBoundaryCache } from "./client-graph-boundary-cache.js";
3
+ import { ClientGraphBoundaryCache } from "./boundary-cache.js";
4
4
  import {
5
5
  parseDeclaredModules,
6
6
  toModuleBaseSpecifier,
7
7
  mergeRequestedExportRules,
8
8
  snapshotRegistry,
9
9
  diffRequestedExportRules
10
- } from "./client-graph-reachability.js";
11
- import { transformModuleImports } from "./client-graph-ast-transform.js";
10
+ } from "./specifier-classification.js";
11
+ import { transformModuleImports } from "./ast-transform.js";
12
12
  const SOURCE_FILE_FILTER = /\.(tsx?|jsx?)$/;
13
13
  function createClientGraphBoundaryPlugin(options) {
14
14
  return {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Specifier classification and requested-export registry helpers for the client graph boundary.
3
3
  */
4
- import type { RequestedExportRules } from './client-graph-boundary-cache.js';
4
+ import type { RequestedExportRules } from './boundary-cache.js';
5
5
  export declare function isBareSpecifier(specifier: string): boolean;
6
6
  export declare function isProjectAliasSpecifier(specifier: string, projectRoot?: string): boolean;
7
7
  /**
@@ -10,16 +10,15 @@ import { HmrStrategy, type HmrAction } from '@ecopages/core/hmr/hmr-strategy';
10
10
  import type { BrowserRuntimeManifest } from '@ecopages/core/build/browser-runtime-manifest';
11
11
  import type { DefaultHmrContext } from '@ecopages/core';
12
12
  import type { CompileOptions } from '@mdx-js/mdx';
13
- import { ClientGraphBoundaryCache } from './utils/client-graph-boundary-cache.js';
14
- import type { ReactHmrPageMetadataCache } from './services/react-hmr-page-metadata-cache.js';
13
+ import { ClientGraphBoundaryCache } from '../client-graph/boundary-cache.js';
14
+ import type { HmrPageMetadataCache } from './page-metadata-cache.js';
15
15
  export interface ReactHmrStrategyOptions {
16
16
  context: DefaultHmrContext;
17
- pageMetadataCache: ReactHmrPageMetadataCache;
17
+ pageMetadataCache: HmrPageMetadataCache;
18
18
  runtimeManifest: BrowserRuntimeManifest;
19
19
  mdxCompilerOptions?: CompileOptions;
20
20
  ownedTemplateExtensions?: string[];
21
21
  allTemplateExtensions?: string[];
22
- explicitGraphEnabled?: boolean;
23
22
  /**
24
23
  * Per-app cache for client-graph-boundary transform results. Owned by
25
24
  * the React plugin for the app's lifetime. When omitted, the strategy
@@ -82,10 +81,8 @@ export declare class ReactHmrStrategy extends HmrStrategy {
82
81
  */
83
82
  private context;
84
83
  private pageMetadataCache;
85
- private explicitGraphEnabled;
86
84
  private readonly runtimeManifest;
87
85
  private readonly clientGraphBoundaryCache;
88
- private readonly pagesIndex;
89
86
  constructor(options: ReactHmrStrategyOptions);
90
87
  /**
91
88
  * Returns build plugins for React HMR bundling.
@@ -4,14 +4,13 @@ import { RESOLVED_ASSETS_DIR } from "@ecopages/core/constants";
4
4
  import { createBrowserRuntimePlugin } from "@ecopages/core/build/browser-runtime-plugin";
5
5
  import { FileNotFoundError, fileSystem } from "@ecopages/file-system";
6
6
  import { Logger } from "@ecopages/logger";
7
- import { injectHmrHandler } from "./utils/hmr-scripts.js";
8
- import { createClientGraphBoundaryPlugin } from "./utils/client-graph-boundary-plugin.js";
9
- import { ClientGraphBoundaryCache } from "./utils/client-graph-boundary-cache.js";
10
- import { collectPageDeclaredModules, collectPageDeclaredModulesFromModule } from "./utils/declared-modules.js";
11
- import { someInConfigTree } from "./utils/component-config-traversal.js";
12
- import { createReactMdxLoaderPlugin } from "./utils/react-mdx-loader-plugin.js";
13
- import { getReactClientGraphAllowSpecifiers } from "./utils/react-runtime-alias-map.js";
14
- import { PagesIndex } from "./services/pages-index.js";
7
+ import { injectHmrHandler } from "./hmr-scripts.js";
8
+ import { createClientGraphBoundaryPlugin } from "../client-graph/boundary-plugin.js";
9
+ import { ClientGraphBoundaryCache } from "../client-graph/boundary-cache.js";
10
+ import { collectPageDeclaredModules, collectPageDeclaredModulesFromModule } from "../client-graph/declared-modules.js";
11
+ import { someInConfigTree } from "../client-graph/component-config-traversal.js";
12
+ import { createReactMdxLoaderPlugin } from "../mdx/mdx-loader-plugin.js";
13
+ import { getReactClientGraphAllowSpecifiers } from "../bundling/runtime-alias-map.js";
15
14
  const appLogger = new Logger("[ReactHmrStrategy]");
16
15
  class ReactHmrStrategy extends HmrStrategy {
17
16
  type = HmrStrategyType.INTEGRATION;
@@ -28,22 +27,14 @@ class ReactHmrStrategy extends HmrStrategy {
28
27
  */
29
28
  context;
30
29
  pageMetadataCache;
31
- explicitGraphEnabled;
32
30
  runtimeManifest;
33
31
  clientGraphBoundaryCache;
34
- pagesIndex;
35
32
  constructor(options) {
36
33
  super();
37
34
  this.context = options.context;
38
35
  this.pageMetadataCache = options.pageMetadataCache;
39
36
  this.runtimeManifest = options.runtimeManifest;
40
- this.explicitGraphEnabled = options.explicitGraphEnabled ?? false;
41
37
  this.clientGraphBoundaryCache = options.clientGraphBoundaryCache ?? new ClientGraphBoundaryCache();
42
- this.pagesIndex = new PagesIndex({
43
- pagesDir: this.context.getPagesDir(),
44
- extensions: options.allTemplateExtensions,
45
- isPageEntrypoint: (file) => this.isPageEntrypoint(file)
46
- });
47
38
  this.mdxCompilerOptions = options.mdxCompilerOptions;
48
39
  this.ownedTemplateExtensions = new Set(options.ownedTemplateExtensions ?? [".tsx"]);
49
40
  this.allTemplateExtensions = [...options.allTemplateExtensions ?? [".tsx"]].sort(
@@ -218,11 +209,11 @@ class ReactHmrStrategy extends HmrStrategy {
218
209
  return path.basename(encodedPath);
219
210
  }
220
211
  async collectReactPageBuildTargets() {
221
- await this.pagesIndex.refresh();
222
- const indexed = this.pagesIndex.list();
223
212
  const targets = /* @__PURE__ */ new Map();
224
- for (const entrypointPath of indexed) {
225
- this.pageMetadataCache.markOwnedEntrypoint(entrypointPath);
213
+ for (const entrypointPath of this.pageMetadataCache.getOwnedEntrypoints()) {
214
+ if (!this.isPageEntrypoint(entrypointPath)) {
215
+ continue;
216
+ }
226
217
  targets.set(entrypointPath, {
227
218
  entrypointPath,
228
219
  outputUrl: this.getEntrypointOutput(entrypointPath).outputUrl
@@ -4,7 +4,7 @@
4
4
  * This keeps React Fast Refresh optimizations local to the React integration so
5
5
  * core HMR interfaces do not need React-specific metadata hooks.
6
6
  */
7
- export declare class ReactHmrPageMetadataCache {
7
+ export declare class HmrPageMetadataCache {
8
8
  private readonly declaredModulesByEntrypoint;
9
9
  private readonly ownedEntrypoints;
10
10
  /**
@@ -19,6 +19,10 @@ export declare class ReactHmrPageMetadataCache {
19
19
  * Returns the last known declared browser modules for a page entrypoint.
20
20
  */
21
21
  getDeclaredModules(entrypointPath: string): string[] | undefined;
22
+ /**
23
+ * Returns React-owned page entrypoints discovered during development renders.
24
+ */
25
+ getOwnedEntrypoints(): string[];
22
26
  /**
23
27
  * Returns true when the watched entrypoint is owned by the React integration.
24
28
  */
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- class ReactHmrPageMetadataCache {
2
+ class HmrPageMetadataCache {
3
3
  declaredModulesByEntrypoint = /* @__PURE__ */ new Map();
4
4
  ownedEntrypoints = /* @__PURE__ */ new Set();
5
5
  /**
@@ -23,6 +23,12 @@ class ReactHmrPageMetadataCache {
23
23
  const declaredModules = this.declaredModulesByEntrypoint.get(path.resolve(entrypointPath));
24
24
  return declaredModules ? [...declaredModules] : void 0;
25
25
  }
26
+ /**
27
+ * Returns React-owned page entrypoints discovered during development renders.
28
+ */
29
+ getOwnedEntrypoints() {
30
+ return [...this.ownedEntrypoints].sort((left, right) => left.localeCompare(right));
31
+ }
26
32
  /**
27
33
  * Returns true when the watched entrypoint is owned by the React integration.
28
34
  */
@@ -31,5 +37,5 @@ class ReactHmrPageMetadataCache {
31
37
  }
32
38
  }
33
39
  export {
34
- ReactHmrPageMetadataCache
40
+ HmrPageMetadataCache
35
41
  };