@ecopages/react 0.2.0-beta.26 → 0.2.0-beta.28
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 +17 -9
- package/package.json +42 -34
- package/src/{services/react-bundle.service.d.ts → bundling/bundle.d.ts} +7 -7
- package/src/{services/react-bundle.service.js → bundling/bundle.js} +9 -11
- package/src/{utils → bundling}/discover-layout-runtime-modules.js +2 -2
- package/src/{utils/react-runtime-alias-map.d.ts → bundling/runtime-alias-map.d.ts} +3 -3
- package/src/{services/react-runtime-bundle.service.d.ts → bundling/runtime-bundle.d.ts} +5 -5
- package/src/{services/react-runtime-bundle.service.js → bundling/runtime-bundle.js} +4 -4
- package/src/bundling/runtime-mode.d.ts +9 -0
- package/src/bundling/runtime-mode.js +6 -0
- package/src/{utils/client-graph-ast-transform.d.ts → client-graph/ast-transform.d.ts} +1 -1
- package/src/{utils/client-graph-ast-transform.js → client-graph/ast-transform.js} +1 -1
- package/src/{utils/client-graph-boundary-cache.d.ts → client-graph/boundary-cache.d.ts} +0 -5
- package/src/{utils/client-graph-boundary-cache.js → client-graph/boundary-cache.js} +1 -3
- package/src/{utils/client-graph-boundary-plugin.d.ts → client-graph/boundary-plugin.d.ts} +1 -1
- package/src/{utils/client-graph-boundary-plugin.js → client-graph/boundary-plugin.js} +3 -3
- package/src/{utils/client-graph-reachability.d.ts → client-graph/specifier-classification.d.ts} +1 -1
- package/src/{react-hmr-strategy.d.ts → hmr/hmr-strategy.d.ts} +3 -6
- package/src/{react-hmr-strategy.js → hmr/hmr-strategy.js} +11 -20
- package/src/{services/react-hmr-page-metadata-cache.d.ts → hmr/page-metadata-cache.d.ts} +5 -1
- package/src/{services/react-hmr-page-metadata-cache.js → hmr/page-metadata-cache.js} +8 -2
- package/src/{services/react-hydration-asset.service.d.ts → hydration/hydration-asset.d.ts} +33 -33
- package/src/{services/react-hydration-asset.service.js → hydration/hydration-asset.js} +59 -54
- package/src/{utils → hydration}/hydration-scripts.d.ts +34 -41
- package/src/hydration/hydration-scripts.js +353 -0
- package/src/{utils → hydration}/hydration-scripts.test.browser.js +6 -4
- package/src/hydration/page-data-manifest.d.ts +58 -0
- package/src/hydration/page-data-manifest.js +53 -0
- package/src/hydration/page-data-reader.d.ts +31 -0
- package/src/hydration/page-data-reader.js +64 -0
- package/src/hydration/page-payload.d.ts +67 -0
- package/src/hydration/page-payload.js +104 -0
- package/src/hydration/serialize-page-data-script.d.ts +27 -0
- package/src/hydration/serialize-page-data-script.js +31 -0
- package/src/{services/react-mdx-config-dependency.service.d.ts → mdx/mdx-config-dependency.d.ts} +5 -5
- package/src/{services/react-mdx-config-dependency.service.js → mdx/mdx-config-dependency.js} +3 -3
- package/src/{services/react-page-module.service.d.ts → page/page-module.d.ts} +4 -7
- package/src/{services/react-page-module.service.js → page/page-module.js} +5 -9
- package/src/{react.plugin.d.ts → plugin/react.plugin.d.ts} +7 -3
- package/src/{react.plugin.js → plugin/react.plugin.js} +32 -30
- package/src/{react.types.d.ts → plugin/react.types.d.ts} +23 -8
- package/src/render/component-ownership.d.ts +50 -0
- package/src/render/component-ownership.js +23 -0
- package/src/render/component-ssr.d.ts +113 -0
- package/src/render/component-ssr.js +202 -0
- package/src/render/errors.d.ts +16 -0
- package/src/render/errors.js +18 -0
- package/src/{layout-compose.d.ts → render/layout-compose.d.ts} +8 -0
- package/src/{layout-compose.js → render/layout-compose.js} +14 -6
- package/src/render/react-renderer.d.ts +138 -0
- package/src/render/react-renderer.js +482 -0
- package/src/render/react-runtime.d.ts +13 -0
- package/src/render/react-runtime.js +21 -0
- package/src/render/unified-layout-composition.d.ts +53 -0
- package/src/render/unified-layout-composition.js +89 -0
- package/src/react-renderer.d.ts +0 -254
- package/src/react-renderer.js +0 -726
- package/src/serialize-page-data-script.d.ts +0 -8
- package/src/serialize-page-data-script.js +0 -10
- package/src/services/pages-index.d.ts +0 -64
- package/src/services/pages-index.js +0 -73
- package/src/services/react-page-payload.service.d.ts +0 -46
- package/src/services/react-page-payload.service.js +0 -67
- package/src/utils/hydration-scripts.js +0 -371
- /package/src/{utils → app}/client-only.d.ts +0 -0
- /package/src/{utils → app}/client-only.js +0 -0
- /package/src/{utils → app}/dynamic.d.ts +0 -0
- /package/src/{utils → app}/dynamic.js +0 -0
- /package/src/{utils → app}/dynamic.test.browser.d.ts +0 -0
- /package/src/{utils → app}/dynamic.test.browser.js +0 -0
- /package/src/{utils → bundling}/discover-layout-runtime-modules.d.ts +0 -0
- /package/src/{utils/react-runtime-alias-map.js → bundling/runtime-alias-map.js} +0 -0
- /package/src/{utils/react-dom-runtime-interop-plugin.d.ts → bundling/runtime-interop-plugin.d.ts} +0 -0
- /package/src/{utils/react-dom-runtime-interop-plugin.js → bundling/runtime-interop-plugin.js} +0 -0
- /package/src/{utils/react-plugin-runtime-modules.d.ts → bundling/runtime-modules.d.ts} +0 -0
- /package/src/{utils/react-plugin-runtime-modules.js → bundling/runtime-modules.js} +0 -0
- /package/src/{utils → client-graph}/component-config-traversal.d.ts +0 -0
- /package/src/{utils → client-graph}/component-config-traversal.js +0 -0
- /package/src/{utils → client-graph}/declared-modules.d.ts +0 -0
- /package/src/{utils → client-graph}/declared-modules.js +0 -0
- /package/src/{utils → client-graph}/reachability-analyzer.d.ts +0 -0
- /package/src/{utils → client-graph}/reachability-analyzer.js +0 -0
- /package/src/{utils/client-graph-reachability.js → client-graph/specifier-classification.js} +0 -0
- /package/src/{declarations.d.ts → contracts/declarations.d.ts} +0 -0
- /package/src/{router-adapter.d.ts → contracts/router-adapter.d.ts} +0 -0
- /package/src/{router-adapter.js → contracts/router-adapter.js} +0 -0
- /package/src/{utils → hmr}/hmr-scripts.d.ts +0 -0
- /package/src/{utils → hmr}/hmr-scripts.js +0 -0
- /package/src/{utils → hydration}/hydration-scripts.test.browser.d.ts +0 -0
- /package/src/{utils/react-mdx-loader-plugin.d.ts → mdx/mdx-loader-plugin.d.ts} +0 -0
- /package/src/{utils/react-mdx-loader-plugin.js → mdx/mdx-loader-plugin.js} +0 -0
- /package/src/{react.constants.d.ts → plugin/react.constants.d.ts} +0 -0
- /package/src/{react.constants.js → plugin/react.constants.js} +0 -0
- /package/src/{react.types.js → plugin/react.types.js} +0 -0
- /package/src/{eco-embed.d.ts → render/eco-embed.d.ts} +0 -0
- /package/src/{eco-embed.js → render/eco-embed.js} +0 -0
- /package/src/{utils → render}/html-boundary.d.ts +0 -0
- /package/src/{utils → render}/html-boundary.js +0 -0
|
@@ -9,51 +9,53 @@
|
|
|
9
9
|
import type { EcoComponentConfig } from '@ecopages/core';
|
|
10
10
|
import { type AssetDefinition, type ProcessedAsset } from '@ecopages/core/services/asset-processing-service';
|
|
11
11
|
import type { AssetProcessingService } from '@ecopages/core/services/asset-processing-service';
|
|
12
|
-
import type {
|
|
13
|
-
import type {
|
|
14
|
-
import type { ReactRouterAdapter } from '../router-adapter.js';
|
|
12
|
+
import type { BundleService } from '../bundling/bundle.js';
|
|
13
|
+
import type { HmrPageMetadataCache } from '../hmr/page-metadata-cache.js';
|
|
14
|
+
import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
|
|
15
15
|
/**
|
|
16
|
-
* Configuration for the
|
|
16
|
+
* Configuration for the HydrationAssetService.
|
|
17
17
|
*/
|
|
18
|
-
export interface
|
|
18
|
+
export interface HydrationAssetServiceConfig {
|
|
19
19
|
srcDir: string;
|
|
20
20
|
routerAdapter?: ReactRouterAdapter;
|
|
21
21
|
assetProcessingService: AssetProcessingService;
|
|
22
|
-
bundleService:
|
|
23
|
-
hmrPageMetadataCache?:
|
|
22
|
+
bundleService: BundleService;
|
|
23
|
+
hmrPageMetadataCache?: HmrPageMetadataCache;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
type PageDependencyOptions = {
|
|
26
|
+
pagePath: string;
|
|
27
|
+
componentName: string;
|
|
28
|
+
importPath: string;
|
|
29
|
+
pageModuleUrlExpression: string;
|
|
30
|
+
bundleOptions: Record<string, unknown>;
|
|
31
|
+
hmrEnabled: boolean;
|
|
32
|
+
useBrowserRuntimeImports: boolean;
|
|
33
|
+
isMdx: boolean;
|
|
34
|
+
};
|
|
35
|
+
export declare function getIslandComponentKey(componentFile: string, config?: EcoComponentConfig): string;
|
|
26
36
|
/**
|
|
27
37
|
* Manages the creation of client-side hydration assets for React pages and component islands.
|
|
28
38
|
*/
|
|
29
|
-
export declare class
|
|
39
|
+
export declare class HydrationAssetService {
|
|
30
40
|
private readonly config;
|
|
31
41
|
private static readonly ROUTER_PAGE_GROUPED_BUNDLE_ID;
|
|
32
|
-
constructor(config:
|
|
42
|
+
constructor(config: HydrationAssetServiceConfig);
|
|
33
43
|
private getIslandBundleName;
|
|
34
44
|
private getIslandHydrationName;
|
|
35
45
|
private getRouterPageGroupedEntryName;
|
|
36
46
|
/**
|
|
37
47
|
* Resolves the browser import path used for a React-owned page or island module.
|
|
38
|
-
* Uses HMR manager for development or constructs static path for production.
|
|
39
48
|
*
|
|
40
|
-
* @
|
|
41
|
-
*
|
|
42
|
-
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* When HMR is enabled, registers the source file as an HMR entrypoint and returns
|
|
51
|
+
* that URL. Otherwise returns the static resolved-assets path for the generated
|
|
52
|
+
* asset name.
|
|
43
53
|
*/
|
|
44
54
|
resolveAssetImportPath(pagePath: string, assetName: string): Promise<string>;
|
|
45
55
|
/**
|
|
46
56
|
* Creates the page-owned route entry asset for hydration and client navigation.
|
|
47
|
-
*
|
|
48
|
-
* @param pagePath - Absolute path to the page source file
|
|
49
|
-
* @param componentName - Generated unique component name
|
|
50
|
-
* @param importPath - Resolved browser import path used by development HMR
|
|
51
|
-
* @param bundleOptions - Bundle configuration options
|
|
52
|
-
* @param isDevelopment - Whether running in development mode with HMR
|
|
53
|
-
* @param isMdx - Whether the source file is an MDX file
|
|
54
|
-
* @returns One page-owned asset definition for processing
|
|
55
57
|
*/
|
|
56
|
-
createPageDependencies(
|
|
58
|
+
createPageDependencies(options: PageDependencyOptions): AssetDefinition[];
|
|
57
59
|
/**
|
|
58
60
|
* Builds client-side assets for a React component island.
|
|
59
61
|
*
|
|
@@ -65,20 +67,18 @@ export declare class ReactHydrationAssetService {
|
|
|
65
67
|
*/
|
|
66
68
|
buildComponentRenderAssets(componentFile: string, config?: EcoComponentConfig): Promise<ProcessedAsset[]>;
|
|
67
69
|
/**
|
|
68
|
-
* Creates the
|
|
70
|
+
* Creates the page browser graph dependency declarations for a React page.
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* Chooses shared vendor import URLs when HMR is on, when running a non-production
|
|
74
|
+
* hosted runtime with HMR off, or when a router adapter is configured (router
|
|
75
|
+
* pages always externalize to shared runtimes). Production non-router pages
|
|
76
|
+
* may inline React into the page bundle instead.
|
|
69
77
|
*
|
|
70
78
|
* @param pagePath - Absolute file path of the page
|
|
71
79
|
* @param isMdx - Whether the page is an MDX file
|
|
72
80
|
* @param declaredModules - Explicitly declared browser module specifiers
|
|
73
|
-
* @returns Declarative assets for core-owned processing
|
|
74
81
|
*/
|
|
75
82
|
createPageBrowserGraphDependencies(pagePath: string, isMdx: boolean, declaredModules: string[]): Promise<AssetDefinition[]>;
|
|
76
|
-
/**
|
|
77
|
-
* Builds the Page Browser Graph assets for a React page.
|
|
78
|
-
*
|
|
79
|
-
* @remarks
|
|
80
|
-
* Kept as a compatibility wrapper while callers migrate to core-owned page
|
|
81
|
-
* graph assembly.
|
|
82
|
-
*/
|
|
83
|
-
buildPageBrowserGraphAssets(pagePath: string, isMdx: boolean, declaredModules: string[]): Promise<ProcessedAsset[]>;
|
|
84
83
|
}
|
|
84
|
+
export {};
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { rapidhash } from "@ecopages/core/hash";
|
|
3
3
|
import { RESOLVED_ASSETS_DIR } from "@ecopages/core/constants";
|
|
4
|
+
import { isReactProductionRuntime } from "../bundling/runtime-mode.js";
|
|
4
5
|
import {
|
|
5
6
|
AssetFactory
|
|
6
7
|
} from "@ecopages/core/services/asset-processing-service";
|
|
7
|
-
import { createHydrationScript, createIslandHydrationScript } from "
|
|
8
|
-
import { collectDeclaredModulesInConfig } from "../
|
|
9
|
-
function
|
|
8
|
+
import { createHydrationScript, createIslandHydrationScript } from "./hydration-scripts.js";
|
|
9
|
+
import { collectDeclaredModulesInConfig } from "../client-graph/declared-modules.js";
|
|
10
|
+
function getIslandComponentKey(componentFile, config) {
|
|
10
11
|
return rapidhash(`${componentFile}:${config?.__eco?.id ?? ""}`).toString();
|
|
11
12
|
}
|
|
12
|
-
class
|
|
13
|
+
class HydrationAssetService {
|
|
13
14
|
config;
|
|
14
15
|
static ROUTER_PAGE_GROUPED_BUNDLE_ID = "ecopages-react-router-pages";
|
|
15
16
|
constructor(config) {
|
|
@@ -27,11 +28,11 @@ class ReactHydrationAssetService {
|
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* Resolves the browser import path used for a React-owned page or island module.
|
|
30
|
-
* Uses HMR manager for development or constructs static path for production.
|
|
31
31
|
*
|
|
32
|
-
* @
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* When HMR is enabled, registers the source file as an HMR entrypoint and returns
|
|
34
|
+
* that URL. Otherwise returns the static resolved-assets path for the generated
|
|
35
|
+
* asset name.
|
|
35
36
|
*/
|
|
36
37
|
async resolveAssetImportPath(pagePath, assetName) {
|
|
37
38
|
const hmrManager = this.config.assetProcessingService?.getHmrManager();
|
|
@@ -42,40 +43,54 @@ class ReactHydrationAssetService {
|
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
44
45
|
* Creates the page-owned route entry asset for hydration and client navigation.
|
|
45
|
-
*
|
|
46
|
-
* @param pagePath - Absolute path to the page source file
|
|
47
|
-
* @param componentName - Generated unique component name
|
|
48
|
-
* @param importPath - Resolved browser import path used by development HMR
|
|
49
|
-
* @param bundleOptions - Bundle configuration options
|
|
50
|
-
* @param isDevelopment - Whether running in development mode with HMR
|
|
51
|
-
* @param isMdx - Whether the source file is an MDX file
|
|
52
|
-
* @returns One page-owned asset definition for processing
|
|
53
46
|
*/
|
|
54
|
-
createPageDependencies(
|
|
47
|
+
createPageDependencies(options) {
|
|
48
|
+
const {
|
|
49
|
+
pagePath,
|
|
50
|
+
componentName,
|
|
51
|
+
importPath,
|
|
52
|
+
pageModuleUrlExpression,
|
|
53
|
+
bundleOptions,
|
|
54
|
+
hmrEnabled,
|
|
55
|
+
useBrowserRuntimeImports,
|
|
56
|
+
isMdx
|
|
57
|
+
} = options;
|
|
55
58
|
const runtimeImports = this.config.bundleService.getRuntimeImports();
|
|
56
|
-
const groupedBundle = this.config.routerAdapter ? {
|
|
57
|
-
id:
|
|
59
|
+
const groupedBundle = !hmrEnabled && this.config.routerAdapter ? {
|
|
60
|
+
id: HydrationAssetService.ROUTER_PAGE_GROUPED_BUNDLE_ID,
|
|
58
61
|
entryName: this.getRouterPageGroupedEntryName(pagePath)
|
|
59
62
|
} : void 0;
|
|
63
|
+
const existingExternal = Array.isArray(bundleOptions.external) ? bundleOptions.external.filter((value) => typeof value === "string") : [];
|
|
64
|
+
const pageBootstrapBundleOptions = hmrEnabled ? {
|
|
65
|
+
...bundleOptions,
|
|
66
|
+
external: [.../* @__PURE__ */ new Set([...existingExternal, importPath])]
|
|
67
|
+
} : bundleOptions;
|
|
60
68
|
return [
|
|
61
69
|
AssetFactory.createContentScript({
|
|
62
70
|
position: "head",
|
|
63
71
|
content: createHydrationScript({
|
|
64
|
-
importPath:
|
|
72
|
+
importPath: hmrEnabled ? importPath : pagePath,
|
|
65
73
|
pageModuleUrlExpression,
|
|
66
74
|
reactImportPath: useBrowserRuntimeImports ? runtimeImports.react : "react",
|
|
67
75
|
reactDomClientImportPath: useBrowserRuntimeImports ? runtimeImports.reactDomClient : "react-dom/client",
|
|
68
76
|
routerImportPath: useBrowserRuntimeImports ? runtimeImports.router : this.config.routerAdapter?.bundle.importPath,
|
|
69
|
-
|
|
77
|
+
hmrEnabled,
|
|
70
78
|
isMdx,
|
|
71
79
|
router: this.config.routerAdapter,
|
|
72
80
|
scriptId: componentName
|
|
73
81
|
}),
|
|
74
82
|
name: componentName,
|
|
75
83
|
packageRole: "page-script",
|
|
76
|
-
|
|
84
|
+
/**
|
|
85
|
+
* @remarks
|
|
86
|
+
* Always bundle page bootstraps. Unbundled HMR entries are evaluated as
|
|
87
|
+
* native browser ESM and cannot resolve bare package imports such as
|
|
88
|
+
* `@ecopages/core/eco/page-layout-normalization` or
|
|
89
|
+
* `@ecopages/react/layout-compose`.
|
|
90
|
+
*/
|
|
91
|
+
bundle: true,
|
|
77
92
|
groupedBundle,
|
|
78
|
-
bundleOptions,
|
|
93
|
+
bundleOptions: pageBootstrapBundleOptions,
|
|
79
94
|
attributes: {
|
|
80
95
|
type: "module",
|
|
81
96
|
defer: "",
|
|
@@ -98,11 +113,11 @@ class ReactHydrationAssetService {
|
|
|
98
113
|
*/
|
|
99
114
|
async buildComponentRenderAssets(componentFile, config) {
|
|
100
115
|
const componentName = this.getIslandBundleName(componentFile);
|
|
101
|
-
const componentKey =
|
|
116
|
+
const componentKey = getIslandComponentKey(componentFile, config);
|
|
102
117
|
const hydrationName = this.getIslandHydrationName(componentName, componentKey);
|
|
103
118
|
const hmrManager = this.config.assetProcessingService?.getHmrManager();
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
119
|
+
const hmrEnabled = hmrManager?.isEnabled() ?? false;
|
|
120
|
+
if (hmrEnabled) {
|
|
106
121
|
this.config.hmrPageMetadataCache?.markOwnedEntrypoint(componentFile);
|
|
107
122
|
}
|
|
108
123
|
const importPath = await this.resolveAssetImportPath(componentFile, componentName);
|
|
@@ -138,7 +153,7 @@ class ReactHydrationAssetService {
|
|
|
138
153
|
targetSelector: `[data-eco-component-key="${componentKey}"]`,
|
|
139
154
|
componentRef: config?.__eco?.id,
|
|
140
155
|
componentFile,
|
|
141
|
-
|
|
156
|
+
minify: !hmrEnabled
|
|
142
157
|
}),
|
|
143
158
|
name: hydrationName,
|
|
144
159
|
packageRole: "keep-separate",
|
|
@@ -158,60 +173,50 @@ class ReactHydrationAssetService {
|
|
|
158
173
|
return this.config.assetProcessingService.processDependencies(dependencies, componentName);
|
|
159
174
|
}
|
|
160
175
|
/**
|
|
161
|
-
* Creates the
|
|
176
|
+
* Creates the page browser graph dependency declarations for a React page.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* Chooses shared vendor import URLs when HMR is on, when running a non-production
|
|
180
|
+
* hosted runtime with HMR off, or when a router adapter is configured (router
|
|
181
|
+
* pages always externalize to shared runtimes). Production non-router pages
|
|
182
|
+
* may inline React into the page bundle instead.
|
|
162
183
|
*
|
|
163
184
|
* @param pagePath - Absolute file path of the page
|
|
164
185
|
* @param isMdx - Whether the page is an MDX file
|
|
165
186
|
* @param declaredModules - Explicitly declared browser module specifiers
|
|
166
|
-
* @returns Declarative assets for core-owned processing
|
|
167
187
|
*/
|
|
168
188
|
async createPageBrowserGraphDependencies(pagePath, isMdx, declaredModules) {
|
|
169
189
|
const componentName = `ecopages-react-${rapidhash(pagePath)}`;
|
|
170
190
|
const hmrManager = this.config.assetProcessingService?.getHmrManager();
|
|
171
|
-
const
|
|
172
|
-
const
|
|
191
|
+
const hmrEnabled = hmrManager?.isEnabled() ?? false;
|
|
192
|
+
const productionRuntime = isReactProductionRuntime();
|
|
173
193
|
const usesRouterRuntime = Boolean(this.config.routerAdapter);
|
|
174
|
-
const useBrowserRuntimeImports =
|
|
175
|
-
if (
|
|
194
|
+
const useBrowserRuntimeImports = hmrEnabled || !productionRuntime || usesRouterRuntime;
|
|
195
|
+
if (hmrEnabled) {
|
|
176
196
|
this.config.hmrPageMetadataCache?.setDeclaredModules(pagePath, declaredModules);
|
|
177
197
|
}
|
|
178
198
|
const importPath = await this.resolveAssetImportPath(pagePath, componentName);
|
|
179
|
-
const pageModuleUrlExpression =
|
|
199
|
+
const pageModuleUrlExpression = hmrEnabled ? JSON.stringify(importPath) : "import.meta.url";
|
|
180
200
|
const bundleOptions = await this.config.bundleService.createBundleOptions(
|
|
181
201
|
componentName,
|
|
182
202
|
isMdx,
|
|
183
203
|
declaredModules,
|
|
184
204
|
{ includeRuntime: !useBrowserRuntimeImports, splitting: usesRouterRuntime }
|
|
185
205
|
);
|
|
186
|
-
const dependencies = this.createPageDependencies(
|
|
206
|
+
const dependencies = this.createPageDependencies({
|
|
187
207
|
pagePath,
|
|
188
208
|
componentName,
|
|
189
209
|
importPath,
|
|
190
210
|
pageModuleUrlExpression,
|
|
191
211
|
bundleOptions,
|
|
192
|
-
|
|
212
|
+
hmrEnabled,
|
|
193
213
|
useBrowserRuntimeImports,
|
|
194
214
|
isMdx
|
|
195
|
-
);
|
|
215
|
+
});
|
|
196
216
|
return dependencies;
|
|
197
217
|
}
|
|
198
|
-
/**
|
|
199
|
-
* Builds the Page Browser Graph assets for a React page.
|
|
200
|
-
*
|
|
201
|
-
* @remarks
|
|
202
|
-
* Kept as a compatibility wrapper while callers migrate to core-owned page
|
|
203
|
-
* graph assembly.
|
|
204
|
-
*/
|
|
205
|
-
async buildPageBrowserGraphAssets(pagePath, isMdx, declaredModules) {
|
|
206
|
-
const componentName = `ecopages-react-${rapidhash(pagePath)}`;
|
|
207
|
-
const dependencies = await this.createPageBrowserGraphDependencies(pagePath, isMdx, declaredModules);
|
|
208
|
-
if (!this.config.assetProcessingService) {
|
|
209
|
-
throw new Error("AssetProcessingService is not set");
|
|
210
|
-
}
|
|
211
|
-
return this.config.assetProcessingService.processDependencies(dependencies, componentName);
|
|
212
|
-
}
|
|
213
218
|
}
|
|
214
219
|
export {
|
|
215
|
-
|
|
216
|
-
|
|
220
|
+
HydrationAssetService,
|
|
221
|
+
getIslandComponentKey
|
|
217
222
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* These functions create the page entry modules that hydrate React routes.
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { ReactRouterAdapter } from '../router-adapter.js';
|
|
6
|
+
import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
|
|
7
7
|
/**
|
|
8
8
|
* Options for generating a hydration script.
|
|
9
9
|
*/
|
|
@@ -20,14 +20,30 @@ export type HydrationScriptOptions = {
|
|
|
20
20
|
reactDomClientImportPath: string;
|
|
21
21
|
/** Direct import path for router runtime module */
|
|
22
22
|
routerImportPath?: string;
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* When true, emit HMR registration and hot-reload handlers.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* Page bootstraps are always bundled so bare package imports resolve through
|
|
28
|
+
* the browser build pipeline. When false, this generator emits the same
|
|
29
|
+
* readable bootstrap without HMR hooks.
|
|
30
|
+
*/
|
|
31
|
+
hmrEnabled: boolean;
|
|
25
32
|
/** Whether the source file is an MDX file */
|
|
26
33
|
isMdx: boolean;
|
|
27
34
|
/** Optional router adapter for SPA navigation */
|
|
28
35
|
router?: ReactRouterAdapter;
|
|
29
36
|
/** Import path for shared layout composition helper */
|
|
30
37
|
layoutComposeImportPath?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Optional import path for the page-data reader.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* When omitted, hydration scripts inline the reader so native browser ESM /
|
|
43
|
+
* HMR entry evaluation does not depend on bare `@ecopages/react/*` imports.
|
|
44
|
+
* Browser unit tests that execute `data:` scripts may still pass a resolvable URL.
|
|
45
|
+
*/
|
|
46
|
+
pageDataReaderImportPath?: string;
|
|
31
47
|
};
|
|
32
48
|
export type IslandHydrationScriptOptions = {
|
|
33
49
|
/** Bundled browser module path for the island component. */
|
|
@@ -44,51 +60,28 @@ export type IslandHydrationScriptOptions = {
|
|
|
44
60
|
componentRef?: string;
|
|
45
61
|
/** Optional source file hint used as fallback for component resolution. */
|
|
46
62
|
componentFile?: string;
|
|
47
|
-
/**
|
|
48
|
-
|
|
63
|
+
/**
|
|
64
|
+
* When true, emit a compact source string.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Island bootstraps use `bundle: false`, so compact output must be generated
|
|
68
|
+
* here rather than delegated to the bundler.
|
|
69
|
+
*/
|
|
70
|
+
minify: boolean;
|
|
49
71
|
};
|
|
50
72
|
/**
|
|
51
|
-
* Creates a hydration
|
|
73
|
+
* Creates a page hydration entry module.
|
|
52
74
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* a compact public API while allowing each emitted script to stay focused.
|
|
57
|
-
*
|
|
58
|
-
* Selection rules:
|
|
59
|
-
* - development uses readable scripts with HMR hooks
|
|
60
|
-
* - production uses minified equivalents
|
|
61
|
-
* - router presence decides whether page updates flow through the router runtime
|
|
62
|
-
* or rebuild directly from the page module
|
|
63
|
-
*
|
|
64
|
-
* @param options - Configuration options for script generation
|
|
65
|
-
* @returns The generated hydration script as a string
|
|
75
|
+
* @remarks
|
|
76
|
+
* Always emits readable source. Production page assets set `bundle: true` so
|
|
77
|
+
* core's content-script processor minifies the result. Do not hand-minify here.
|
|
66
78
|
*/
|
|
67
79
|
export declare function createHydrationScript(options: HydrationScriptOptions): string;
|
|
68
80
|
/**
|
|
69
81
|
* Creates the client bootstrap for component-level React islands.
|
|
70
82
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* Rationale:
|
|
75
|
-
* - No synthetic wrapper element is introduced in SSR output.
|
|
76
|
-
* - DOM structure remains identical to authored component markup.
|
|
77
|
-
* - Runtime ownership is isolated per island instance.
|
|
78
|
-
*
|
|
79
|
-
* Generated script behavior:
|
|
80
|
-
* - resolves the component export by metadata (`componentRef`, `componentFile`)
|
|
81
|
-
* before falling back to default/first function export
|
|
82
|
-
* - selects island root using `targetSelector`
|
|
83
|
-
* - replaces the SSR host with a dedicated client-owned container
|
|
84
|
-
* - creates a fresh React root and renders with serialized `props`
|
|
85
|
-
*
|
|
86
|
-
* Why it remounts instead of hydrating:
|
|
87
|
-
* island SSR intentionally avoids synthetic wrapper elements. The runtime swaps
|
|
88
|
-
* the authored SSR node for a dedicated client-owned container before mounting
|
|
89
|
-
* so the server markup stays clean while the client still gets a stable root.
|
|
90
|
-
*
|
|
91
|
-
* @param options Island script generation options.
|
|
92
|
-
* @returns Browser-executable JavaScript module source.
|
|
83
|
+
* @remarks
|
|
84
|
+
* Island scripts use `bundle: false`, so compact output still needs a
|
|
85
|
+
* handwritten string.
|
|
93
86
|
*/
|
|
94
87
|
export declare function createIslandHydrationScript(options: IslandHydrationScriptOptions): string;
|