@ecopages/react 0.2.0-beta.27 → 0.2.0-beta.29
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/package.json +4 -4
- package/src/bundling/bootstrap-package-paths.d.ts +5 -0
- package/src/bundling/bootstrap-package-paths.js +6 -0
- package/src/bundling/runtime-bundle.d.ts +4 -0
- package/src/bundling/runtime-bundle.js +29 -1
- package/src/hydration/assert-no-bare-ecopages-imports.d.ts +4 -0
- package/src/hydration/assert-no-bare-ecopages-imports.js +7 -0
- package/src/hydration/bootstrap-imports.d.ts +25 -0
- package/src/hydration/bootstrap-imports.js +23 -0
- package/src/hydration/hydration-asset.js +18 -4
- package/src/hydration/hydration-scripts.d.ts +18 -4
- package/src/hydration/hydration-scripts.js +7 -10
- package/src/hydration/hydration-scripts.test.browser.js +5 -1
- package/src/hydration/page-payload.d.ts +1 -1
- package/src/render/component-ssr.d.ts +1 -1
- package/src/render/react-renderer.d.ts +3 -2
- package/src/render/react-renderer.js +50 -12
- package/src/render/unified-layout-composition.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/react",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.29",
|
|
4
4
|
"description": "React integration for Ecopages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -93,16 +93,16 @@
|
|
|
93
93
|
"directory": "packages/integrations/react"
|
|
94
94
|
},
|
|
95
95
|
"peerDependencies": {
|
|
96
|
-
"@ecopages/core": "0.2.0-beta.
|
|
96
|
+
"@ecopages/core": "0.2.0-beta.29",
|
|
97
97
|
"@types/react": "^19",
|
|
98
98
|
"@types/react-dom": "^19",
|
|
99
99
|
"react": "^19",
|
|
100
100
|
"react-dom": "^19"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@ecopages/file-system": "0.2.0-beta.
|
|
103
|
+
"@ecopages/file-system": "0.2.0-beta.29",
|
|
104
104
|
"@ecopages/logger": "^0.2.3",
|
|
105
|
-
"@ecopages/mdx": "0.2.0-beta.
|
|
105
|
+
"@ecopages/mdx": "0.2.0-beta.29",
|
|
106
106
|
"@mdx-js/mdx": "^3.1.1",
|
|
107
107
|
"oxc-parser": "^0.124.0",
|
|
108
108
|
"oxc-transform": "^0.124.0",
|
|
@@ -18,6 +18,8 @@ export type ReactRuntimeImports = {
|
|
|
18
18
|
reactJsxDevRuntime: string;
|
|
19
19
|
reactDom: string;
|
|
20
20
|
useSyncExternalStoreWithSelector: string;
|
|
21
|
+
pageLayoutNormalization: string;
|
|
22
|
+
layoutCompose: string;
|
|
21
23
|
router?: string;
|
|
22
24
|
};
|
|
23
25
|
export interface RuntimeBundleServiceConfig {
|
|
@@ -44,6 +46,8 @@ export declare class RuntimeBundleService {
|
|
|
44
46
|
getConfiguredRuntimeModuleSpecifiers(): string[];
|
|
45
47
|
private getRuntimeModuleBundleExternals;
|
|
46
48
|
private getUseSyncExternalStoreWithSelectorVendorFileName;
|
|
49
|
+
private getPageLayoutNormalizationVendorFileName;
|
|
50
|
+
private getLayoutComposeVendorFileName;
|
|
47
51
|
private createReactVendorImportRewritePlugin;
|
|
48
52
|
getRuntimeImports(mode?: RuntimeMode): ReactRuntimeImports;
|
|
49
53
|
getRuntimeAliasMap(mode?: RuntimeMode): Record<string, string>;
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import {
|
|
15
15
|
createBrowserRuntimeManifest
|
|
16
16
|
} from "@ecopages/core/build/browser-runtime-manifest";
|
|
17
|
+
import { LAYOUT_COMPOSE_PACKAGE, PAGE_LAYOUT_NORMALIZATION_PACKAGE } from "./bootstrap-package-paths.js";
|
|
17
18
|
class RuntimeBundleService {
|
|
18
19
|
config;
|
|
19
20
|
constructor(config) {
|
|
@@ -73,6 +74,12 @@ class RuntimeBundleService {
|
|
|
73
74
|
getUseSyncExternalStoreWithSelectorVendorFileName(mode) {
|
|
74
75
|
return mode === "development" ? "use-sync-external-store-with-selector.development.js" : "use-sync-external-store-with-selector.js";
|
|
75
76
|
}
|
|
77
|
+
getPageLayoutNormalizationVendorFileName(mode) {
|
|
78
|
+
return mode === "development" ? "page-layout-normalization.development.js" : "page-layout-normalization.js";
|
|
79
|
+
}
|
|
80
|
+
getLayoutComposeVendorFileName(mode) {
|
|
81
|
+
return mode === "development" ? "layout-compose.development.js" : "layout-compose.js";
|
|
82
|
+
}
|
|
76
83
|
createReactVendorImportRewritePlugin(mode) {
|
|
77
84
|
return createBrowserRuntimePlugin({
|
|
78
85
|
name: `react-plugin-vendor-runtime-import-rewrite-${mode}`,
|
|
@@ -97,7 +104,9 @@ class RuntimeBundleService {
|
|
|
97
104
|
reactDom: buildBrowserRuntimeAssetUrl(reactDomVendorFileName),
|
|
98
105
|
useSyncExternalStoreWithSelector: buildBrowserRuntimeAssetUrl(
|
|
99
106
|
this.getUseSyncExternalStoreWithSelectorVendorFileName(mode)
|
|
100
|
-
)
|
|
107
|
+
),
|
|
108
|
+
pageLayoutNormalization: buildBrowserRuntimeAssetUrl(this.getPageLayoutNormalizationVendorFileName(mode)),
|
|
109
|
+
layoutCompose: buildBrowserRuntimeAssetUrl(this.getLayoutComposeVendorFileName(mode))
|
|
101
110
|
};
|
|
102
111
|
if (this.config.routerAdapter) {
|
|
103
112
|
runtimeImports.router = buildBrowserRuntimeAssetUrl(this.getRouterVendorFileName(mode));
|
|
@@ -177,6 +186,25 @@ class RuntimeBundleService {
|
|
|
177
186
|
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
178
187
|
plugins: [reactVendorImportRewritePlugin]
|
|
179
188
|
}
|
|
189
|
+
}),
|
|
190
|
+
createBrowserRuntimeScriptAsset({
|
|
191
|
+
importPath: PAGE_LAYOUT_NORMALIZATION_PACKAGE,
|
|
192
|
+
name: "page-layout-normalization",
|
|
193
|
+
fileName: this.getPageLayoutNormalizationVendorFileName(mode),
|
|
194
|
+
bundleOptions: {
|
|
195
|
+
define: this.createRuntimeDefines(mode),
|
|
196
|
+
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME]
|
|
197
|
+
}
|
|
198
|
+
}),
|
|
199
|
+
createBrowserRuntimeScriptAsset({
|
|
200
|
+
importPath: LAYOUT_COMPOSE_PACKAGE,
|
|
201
|
+
name: "layout-compose",
|
|
202
|
+
fileName: this.getLayoutComposeVendorFileName(mode),
|
|
203
|
+
bundleOptions: {
|
|
204
|
+
define: this.createRuntimeDefines(mode),
|
|
205
|
+
excludeAppBuildPlugins: [DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME],
|
|
206
|
+
plugins: [reactVendorImportRewritePlugin]
|
|
207
|
+
}
|
|
180
208
|
})
|
|
181
209
|
);
|
|
182
210
|
if (this.config.routerAdapter) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves browser import paths for React page hydration bootstraps.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* When `useBrowserRuntimeImports` is true, helpers and runtimes resolve to shared
|
|
6
|
+
* `/assets/vendors/*.js` URLs so unbundled HMR bootstraps evaluate as native ESM.
|
|
7
|
+
* When false, bare package names are emitted for the production page bundler.
|
|
8
|
+
*/
|
|
9
|
+
import type { ReactRuntimeImports } from '../bundling/runtime-bundle.js';
|
|
10
|
+
export type HydrationBootstrapImportPaths = {
|
|
11
|
+
reactImportPath: string;
|
|
12
|
+
reactDomClientImportPath: string;
|
|
13
|
+
routerImportPath?: string;
|
|
14
|
+
layoutComposeImportPath: string;
|
|
15
|
+
pageLayoutNormalizationImportPath: string;
|
|
16
|
+
};
|
|
17
|
+
export type ResolveHydrationBootstrapImportsOptions = {
|
|
18
|
+
useBrowserRuntimeImports: boolean;
|
|
19
|
+
runtimeImports: ReactRuntimeImports;
|
|
20
|
+
routerAdapterImportPath?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Returns import paths for React page hydration scripts.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveHydrationBootstrapImports(options: ResolveHydrationBootstrapImportsOptions): HydrationBootstrapImportPaths;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LAYOUT_COMPOSE_PACKAGE, PAGE_LAYOUT_NORMALIZATION_PACKAGE } from "../bundling/bootstrap-package-paths.js";
|
|
2
|
+
function resolveHydrationBootstrapImports(options) {
|
|
3
|
+
const { useBrowserRuntimeImports, runtimeImports, routerAdapterImportPath } = options;
|
|
4
|
+
if (useBrowserRuntimeImports) {
|
|
5
|
+
return {
|
|
6
|
+
reactImportPath: runtimeImports.react,
|
|
7
|
+
reactDomClientImportPath: runtimeImports.reactDomClient,
|
|
8
|
+
...runtimeImports.router || routerAdapterImportPath ? { routerImportPath: runtimeImports.router ?? routerAdapterImportPath } : {},
|
|
9
|
+
layoutComposeImportPath: runtimeImports.layoutCompose,
|
|
10
|
+
pageLayoutNormalizationImportPath: runtimeImports.pageLayoutNormalization
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
reactImportPath: "react",
|
|
15
|
+
reactDomClientImportPath: "react-dom/client",
|
|
16
|
+
...routerAdapterImportPath ? { routerImportPath: routerAdapterImportPath } : {},
|
|
17
|
+
layoutComposeImportPath: LAYOUT_COMPOSE_PACKAGE,
|
|
18
|
+
pageLayoutNormalizationImportPath: PAGE_LAYOUT_NORMALIZATION_PACKAGE
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
resolveHydrationBootstrapImports
|
|
23
|
+
};
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
AssetFactory
|
|
7
7
|
} from "@ecopages/core/services/asset-processing-service";
|
|
8
8
|
import { createHydrationScript, createIslandHydrationScript } from "./hydration-scripts.js";
|
|
9
|
+
import { resolveHydrationBootstrapImports } from "./bootstrap-imports.js";
|
|
9
10
|
import { collectDeclaredModulesInConfig } from "../client-graph/declared-modules.js";
|
|
10
11
|
function getIslandComponentKey(componentFile, config) {
|
|
11
12
|
return rapidhash(`${componentFile}:${config?.__eco?.id ?? ""}`).toString();
|
|
@@ -56,19 +57,26 @@ class HydrationAssetService {
|
|
|
56
57
|
isMdx
|
|
57
58
|
} = options;
|
|
58
59
|
const runtimeImports = this.config.bundleService.getRuntimeImports();
|
|
59
|
-
const groupedBundle = this.config.routerAdapter ? {
|
|
60
|
+
const groupedBundle = !hmrEnabled && this.config.routerAdapter ? {
|
|
60
61
|
id: HydrationAssetService.ROUTER_PAGE_GROUPED_BUNDLE_ID,
|
|
61
62
|
entryName: this.getRouterPageGroupedEntryName(pagePath)
|
|
62
63
|
} : void 0;
|
|
64
|
+
const bootstrapImports = resolveHydrationBootstrapImports({
|
|
65
|
+
useBrowserRuntimeImports,
|
|
66
|
+
runtimeImports,
|
|
67
|
+
routerAdapterImportPath: this.config.routerAdapter?.bundle.importPath
|
|
68
|
+
});
|
|
63
69
|
return [
|
|
64
70
|
AssetFactory.createContentScript({
|
|
65
71
|
position: "head",
|
|
66
72
|
content: createHydrationScript({
|
|
67
73
|
importPath: hmrEnabled ? importPath : pagePath,
|
|
68
74
|
pageModuleUrlExpression,
|
|
69
|
-
reactImportPath:
|
|
70
|
-
reactDomClientImportPath:
|
|
71
|
-
routerImportPath:
|
|
75
|
+
reactImportPath: bootstrapImports.reactImportPath,
|
|
76
|
+
reactDomClientImportPath: bootstrapImports.reactDomClientImportPath,
|
|
77
|
+
routerImportPath: bootstrapImports.routerImportPath,
|
|
78
|
+
layoutComposeImportPath: bootstrapImports.layoutComposeImportPath,
|
|
79
|
+
pageLayoutNormalizationImportPath: bootstrapImports.pageLayoutNormalizationImportPath,
|
|
72
80
|
hmrEnabled,
|
|
73
81
|
isMdx,
|
|
74
82
|
router: this.config.routerAdapter,
|
|
@@ -76,6 +84,12 @@ class HydrationAssetService {
|
|
|
76
84
|
}),
|
|
77
85
|
name: componentName,
|
|
78
86
|
packageRole: "page-script",
|
|
87
|
+
/**
|
|
88
|
+
* @remarks
|
|
89
|
+
* HMR bootstraps stay unbundled write-through ESM. Helper imports must
|
|
90
|
+
* already be browser-resolvable vendor URLs from
|
|
91
|
+
* {@link resolveHydrationBootstrapImports}.
|
|
92
|
+
*/
|
|
79
93
|
bundle: !hmrEnabled,
|
|
80
94
|
groupedBundle,
|
|
81
95
|
bundleOptions,
|
|
@@ -24,16 +24,30 @@ export type HydrationScriptOptions = {
|
|
|
24
24
|
* When true, emit HMR registration and hot-reload handlers.
|
|
25
25
|
*
|
|
26
26
|
* @remarks
|
|
27
|
-
*
|
|
28
|
-
*
|
|
27
|
+
* HMR page bootstraps stay unbundled and evaluate as native browser ESM.
|
|
28
|
+
* Callers must supply browser-resolvable import paths (shared vendor URLs)
|
|
29
|
+
* so generated source does not emit bare `@ecopages/*` imports. When false,
|
|
30
|
+
* this generator emits the same readable bootstrap without HMR hooks.
|
|
29
31
|
*/
|
|
30
32
|
hmrEnabled: boolean;
|
|
31
33
|
/** Whether the source file is an MDX file */
|
|
32
34
|
isMdx: boolean;
|
|
33
35
|
/** Optional router adapter for SPA navigation */
|
|
34
36
|
router?: ReactRouterAdapter;
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Import path for shared layout composition helper.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* Required so callers (not this generator) decide vendor URL vs bare package.
|
|
42
|
+
*/
|
|
43
|
+
layoutComposeImportPath: string;
|
|
44
|
+
/**
|
|
45
|
+
* Import path for MDX page layout normalization helper.
|
|
46
|
+
*
|
|
47
|
+
* @remarks
|
|
48
|
+
* Required so callers (not this generator) decide vendor URL vs bare package.
|
|
49
|
+
*/
|
|
50
|
+
pageLayoutNormalizationImportPath: string;
|
|
37
51
|
/**
|
|
38
52
|
* Optional import path for the page-data reader.
|
|
39
53
|
*
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { getDevPageDataReaderBootstrapSource } from "./page-data-reader.js";
|
|
2
|
-
const DEFAULT_LAYOUT_COMPOSE_IMPORT_PATH = "@ecopages/react/layout-compose";
|
|
3
|
-
const PAGE_LAYOUT_NORMALIZATION_IMPORT = "@ecopages/core/eco/page-layout-normalization";
|
|
4
2
|
function getPageDataReaderSource(options) {
|
|
5
3
|
if (options.pageDataReaderImportPath) {
|
|
6
4
|
return `import { readPageDataDocument, getPageDataFromDocument as getPageData } from "${options.pageDataReaderImportPath}";`;
|
|
7
5
|
}
|
|
8
6
|
return getDevPageDataReaderBootstrapSource();
|
|
9
7
|
}
|
|
10
|
-
function
|
|
11
|
-
return options.layoutComposeImportPath ?? DEFAULT_LAYOUT_COMPOSE_IMPORT_PATH;
|
|
12
|
-
}
|
|
13
|
-
function getImportStatement(importPath, isMdx) {
|
|
8
|
+
function getImportStatement(importPath, isMdx, pageLayoutNormalizationImportPath) {
|
|
14
9
|
return isMdx ? `import * as MDXModule from "${importPath}";
|
|
15
|
-
import { ensurePageConfigLayouts } from "${
|
|
10
|
+
import { ensurePageConfigLayouts } from "${pageLayoutNormalizationImportPath}";
|
|
16
11
|
const Page = MDXModule.default;
|
|
17
12
|
if (MDXModule.config) {
|
|
18
13
|
Page.config = MDXModule.config;
|
|
@@ -137,6 +132,7 @@ function createScriptWithRouter(options) {
|
|
|
137
132
|
if (!routerImportPath) {
|
|
138
133
|
throw new Error("routerImportPath is required when router adapter is configured");
|
|
139
134
|
}
|
|
135
|
+
const pageLayoutNormalizationImportPath = options.pageLayoutNormalizationImportPath;
|
|
140
136
|
const hmrInit = hmrEnabled ? `window.__ECO_PAGES__.hmrHandlers = window.__ECO_PAGES__.hmrHandlers || {};
|
|
141
137
|
` : "";
|
|
142
138
|
const hmrHandler = hmrEnabled ? getRouterHmrHandlerScript({ importPath, isMdx }) : "";
|
|
@@ -145,7 +141,7 @@ import { hydrateRoot } from "${reactDomClientImportPath}";
|
|
|
145
141
|
import { createElement } from "${reactImportPath}";
|
|
146
142
|
import { ${components.router}, ${components.pageContent} } from "${routerImportPath}";
|
|
147
143
|
${getPageDataReaderSource(options)}
|
|
148
|
-
${getImportStatement(importPath, isMdx)}
|
|
144
|
+
${getImportStatement(importPath, isMdx, pageLayoutNormalizationImportPath)}
|
|
149
145
|
const pageModuleUrl = ${pageModuleUrlExpression};
|
|
150
146
|
export default Page;
|
|
151
147
|
export const config = Page.config;
|
|
@@ -212,7 +208,8 @@ if (document.readyState === "loading") {
|
|
|
212
208
|
function createScriptWithoutRouter(options) {
|
|
213
209
|
const { importPath, isMdx, reactImportPath, reactDomClientImportPath, scriptId, hmrEnabled } = options;
|
|
214
210
|
const pageModuleUrlExpression = options.pageModuleUrlExpression ?? "import.meta.url";
|
|
215
|
-
const layoutComposeImportPath =
|
|
211
|
+
const layoutComposeImportPath = options.layoutComposeImportPath;
|
|
212
|
+
const pageLayoutNormalizationImportPath = options.pageLayoutNormalizationImportPath;
|
|
216
213
|
const hmrInit = hmrEnabled ? `window.__ECO_PAGES__.hmrHandlers = window.__ECO_PAGES__.hmrHandlers || {};
|
|
217
214
|
` : "";
|
|
218
215
|
const hmrHandler = hmrEnabled ? getNonRouterHmrHandlerScript({ importPath, isMdx }) : "";
|
|
@@ -221,7 +218,7 @@ import { hydrateRoot } from "${reactDomClientImportPath}";
|
|
|
221
218
|
import { createElement } from "${reactImportPath}";
|
|
222
219
|
import { composeLayoutPageTree } from "${layoutComposeImportPath}";
|
|
223
220
|
${getPageDataReaderSource(options)}
|
|
224
|
-
${getImportStatement(importPath, isMdx)}
|
|
221
|
+
${getImportStatement(importPath, isMdx, pageLayoutNormalizationImportPath)}
|
|
225
222
|
const pageModuleUrl = ${pageModuleUrlExpression};
|
|
226
223
|
export default Page;
|
|
227
224
|
export const config = Page.config;
|
|
@@ -62,7 +62,11 @@ export function PageContent() {
|
|
|
62
62
|
importPath,
|
|
63
63
|
reactImportPath,
|
|
64
64
|
reactDomClientImportPath,
|
|
65
|
-
routerImportPath
|
|
65
|
+
routerImportPath,
|
|
66
|
+
layoutComposeImportPath: createModuleUrl("export function composeLayoutPageTree() { return null; }"),
|
|
67
|
+
pageLayoutNormalizationImportPath: createModuleUrl(
|
|
68
|
+
"export function ensurePageConfigLayouts(config) { return config; }"
|
|
69
|
+
)
|
|
66
70
|
};
|
|
67
71
|
}
|
|
68
72
|
describe("createHydrationScript browser execution", () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EcoComponentConfig, HtmlTemplateProps, IntegrationRendererRenderOptions, RequestLocals } from '@ecopages/core';
|
|
2
|
-
import type { HtmlDocumentContribution } from '@ecopages/core/route-renderer/integration-renderer';
|
|
2
|
+
import type { HtmlDocumentContribution } from '@ecopages/core/route-renderer/orchestration/integration-renderer';
|
|
3
3
|
import type { ReactNode } from 'react';
|
|
4
4
|
type PagePayloadOptions = {
|
|
5
5
|
pageProps?: HtmlTemplateProps['pageProps'];
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { ComponentRenderInput, ComponentRenderResult, EcoComponent, EcoPagesElement } from '@ecopages/core';
|
|
5
5
|
import type { ProcessedAsset } from '@ecopages/core/services/asset-processing-service';
|
|
6
|
-
import type { IntegrationRenderer } from '@ecopages/core/route-renderer/integration-renderer';
|
|
6
|
+
import type { IntegrationRenderer } from '@ecopages/core/route-renderer/orchestration/integration-renderer';
|
|
7
7
|
import type { ReactNode } from 'react';
|
|
8
8
|
import { type HydrationAssetService } from '../hydration/hydration-asset.js';
|
|
9
9
|
import { type SerializableProps } from './component-ownership.js';
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @module
|
|
10
10
|
*/
|
|
11
11
|
import type { ComponentRenderInput, ComponentRenderResult, EcoComponent, EcoPageFile, IntegrationRendererRenderOptions, PageMetadataProps, RouteRendererBody } from '@ecopages/core';
|
|
12
|
-
import { IntegrationRenderer, type HtmlDocumentContribution, type HtmlDocumentContributionContext, type PageBrowserGraphContributionContext, type RenderToResponseContext } from '@ecopages/core/route-renderer/integration-renderer';
|
|
12
|
+
import { IntegrationRenderer, type HtmlDocumentContribution, type HtmlDocumentContributionContext, type PageBrowserGraphContributionContext, type RenderToResponseContext } from '@ecopages/core/route-renderer/orchestration/integration-renderer';
|
|
13
13
|
import type { AssetDefinition, ProcessedAsset } from '@ecopages/core/services/asset-processing-service';
|
|
14
14
|
import type { ReactNode } from 'react';
|
|
15
15
|
import type { ReactRendererConfig } from '../plugin/react.types.js';
|
|
@@ -18,7 +18,7 @@ import { MdxConfigDependencyService } from '../mdx/mdx-config-dependency.js';
|
|
|
18
18
|
import { PageModuleService } from '../page/page-module.js';
|
|
19
19
|
import { PagePayloadService } from '../hydration/page-payload.js';
|
|
20
20
|
import { HydrationAssetService } from '../hydration/hydration-asset.js';
|
|
21
|
-
import { type DocumentShellLayoutInput } from '@ecopages/core/route-renderer/orchestration/document-shell-render.service';
|
|
21
|
+
import { type DocumentShellLayoutInput } from '@ecopages/core/route-renderer/orchestration/document-shell/document-shell-render.service';
|
|
22
22
|
import { type ReactRuntimeModules } from './react-runtime.js';
|
|
23
23
|
export type { ReactRendererConfig } from '../plugin/react.types.js';
|
|
24
24
|
export { BundleError, ReactRenderError } from './errors.js';
|
|
@@ -63,6 +63,7 @@ export declare class ReactRenderer extends IntegrationRenderer<ReactNode> {
|
|
|
63
63
|
* HTML transformer state.
|
|
64
64
|
*/
|
|
65
65
|
private appendHydrationAssetsForFile;
|
|
66
|
+
private resolveOwningRenderer;
|
|
66
67
|
private resolveReactQueuedForeignSubtreeHtml;
|
|
67
68
|
/**
|
|
68
69
|
* Renders a React component for component-level orchestration.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
IntegrationRenderer
|
|
3
|
-
} from "@ecopages/core/route-renderer/integration-renderer";
|
|
3
|
+
} from "@ecopages/core/route-renderer/orchestration/integration-renderer";
|
|
4
4
|
import { RESOLVED_ASSETS_DIR } from "@ecopages/core/constants";
|
|
5
5
|
import { ECO_DOCUMENT_OWNER_ATTRIBUTE } from "@ecopages/core/router/navigation-coordinator";
|
|
6
6
|
import { ensurePageConfigLayouts } from "@ecopages/core/eco/page-layout-normalization";
|
|
@@ -13,8 +13,15 @@ import { PagePayloadService } from "../hydration/page-payload.js";
|
|
|
13
13
|
import { HydrationAssetService } from "../hydration/hydration-asset.js";
|
|
14
14
|
import {
|
|
15
15
|
composeDocumentShell,
|
|
16
|
+
finalizeDocumentShellHtml,
|
|
16
17
|
renderPageDocumentShell
|
|
17
|
-
} from "@ecopages/core/route-renderer/orchestration/document-shell-render.service";
|
|
18
|
+
} from "@ecopages/core/route-renderer/orchestration/document-shell/document-shell-render.service";
|
|
19
|
+
import { mergePageBrowserGraph } from "@ecopages/core/route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils";
|
|
20
|
+
import {
|
|
21
|
+
getForeignSubtreeResolutionContextKey,
|
|
22
|
+
getForeignSubtreeTokenPrefix,
|
|
23
|
+
resolveOwningIntegrationRenderer
|
|
24
|
+
} from "@ecopages/core/route-renderer/orchestration/foreign-child/owning-renderer-resolution";
|
|
18
25
|
import { asReactComponent, getComponentRequires, isReactManagedComponent } from "./component-ownership.js";
|
|
19
26
|
import {
|
|
20
27
|
createForeignSubtreeRuntimeContext,
|
|
@@ -112,13 +119,36 @@ class ReactRenderer extends IntegrationRenderer {
|
|
|
112
119
|
return;
|
|
113
120
|
}
|
|
114
121
|
const pageBrowserGraph = await this.resolvePageBrowserGraphForFile(filePath);
|
|
115
|
-
|
|
122
|
+
if (!pageBrowserGraph) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const { pagePackage } = mergePageBrowserGraph(
|
|
126
|
+
this.htmlTransformer.getPagePackage(),
|
|
127
|
+
this.htmlTransformer.getProcessedDependencies(),
|
|
128
|
+
pageBrowserGraph
|
|
129
|
+
);
|
|
130
|
+
this.htmlTransformer.setPagePackage(pagePackage);
|
|
131
|
+
}
|
|
132
|
+
resolveOwningRenderer(integrationName, rendererCache) {
|
|
133
|
+
return resolveOwningIntegrationRenderer({
|
|
134
|
+
appConfig: this.appConfig,
|
|
135
|
+
runtimeOrigin: this.runtimeOrigin,
|
|
136
|
+
currentIntegrationName: this.name,
|
|
137
|
+
currentRenderer: this,
|
|
138
|
+
integrationName,
|
|
139
|
+
cache: rendererCache
|
|
140
|
+
});
|
|
116
141
|
}
|
|
117
142
|
resolveReactQueuedForeignSubtreeHtml(html, runtimeContext) {
|
|
118
|
-
return this.
|
|
143
|
+
return this.foreignSubtreeExecutionService.resolveQueuedHtml({
|
|
144
|
+
currentIntegrationName: this.name,
|
|
119
145
|
html,
|
|
120
146
|
runtimeContext,
|
|
121
|
-
|
|
147
|
+
queueLabel: "React",
|
|
148
|
+
getOwningRenderer: (integrationName, rendererCache) => this.resolveOwningRenderer(integrationName, rendererCache),
|
|
149
|
+
applyAttributesToFirstElement: (resolvedHtml, attributes) => this.htmlTransformer.applyAttributesToFirstElement(resolvedHtml, attributes),
|
|
150
|
+
dedupeProcessedAssets: (assets) => this.htmlTransformer.dedupeProcessedAssets(assets),
|
|
151
|
+
renderQueuedChildren: (children, currentRuntimeContext, queuedResolutionsByToken, resolveToken) => renderReactQueuedForeignSubtreeChildren({
|
|
122
152
|
children,
|
|
123
153
|
currentRuntimeContext,
|
|
124
154
|
queuedResolutionsByToken,
|
|
@@ -127,9 +157,8 @@ class ReactRenderer extends IntegrationRenderer {
|
|
|
127
157
|
integrationName: this.name,
|
|
128
158
|
normalizeUnresolvedMarkerArtifactHtml: (value) => this.normalizeUnresolvedMarkerArtifactHtml(value),
|
|
129
159
|
resolveQueuedTokens: (value, tokens, resolve) => this.foreignSubtreeExecutionService.resolveQueuedTokens(value, tokens, resolve)
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
);
|
|
160
|
+
})
|
|
161
|
+
});
|
|
133
162
|
}
|
|
134
163
|
/**
|
|
135
164
|
* Renders a React component for component-level orchestration.
|
|
@@ -146,7 +175,10 @@ class ReactRenderer extends IntegrationRenderer {
|
|
|
146
175
|
* deterministic mount target per component instance.
|
|
147
176
|
*/
|
|
148
177
|
async renderComponent(input) {
|
|
149
|
-
const runtimeContext = this.
|
|
178
|
+
const runtimeContext = this.foreignSubtreeExecutionService.getQueuedRuntimeContext(
|
|
179
|
+
input,
|
|
180
|
+
getForeignSubtreeResolutionContextKey(this.name)
|
|
181
|
+
);
|
|
150
182
|
if (!isReactManagedComponent(input.component, this.name)) {
|
|
151
183
|
return renderForeignComponentWithSerializedHtml({
|
|
152
184
|
input,
|
|
@@ -173,9 +205,11 @@ class ReactRenderer extends IntegrationRenderer {
|
|
|
173
205
|
});
|
|
174
206
|
}
|
|
175
207
|
createForeignChildRuntime(options) {
|
|
176
|
-
return this.
|
|
208
|
+
return this.foreignSubtreeExecutionService.createQueuedRuntime({
|
|
177
209
|
renderInput: options.renderInput,
|
|
178
210
|
rendererCache: options.rendererCache,
|
|
211
|
+
runtimeContextKey: getForeignSubtreeResolutionContextKey(this.name),
|
|
212
|
+
tokenPrefix: getForeignSubtreeTokenPrefix(this.name),
|
|
179
213
|
createRuntimeContext: (integrationContext, rendererCache) => createForeignSubtreeRuntimeContext({
|
|
180
214
|
rendererCache,
|
|
181
215
|
componentInstanceScope: integrationContext.componentInstanceId
|
|
@@ -245,7 +279,10 @@ class ReactRenderer extends IntegrationRenderer {
|
|
|
245
279
|
integrationName: this.name,
|
|
246
280
|
normalizeUnresolvedMarkerArtifactHtml: (html) => this.normalizeUnresolvedMarkerArtifactHtml(html),
|
|
247
281
|
getRootTagName: (html) => this.getRootTagName(html),
|
|
248
|
-
getQueuedForeignSubtreeResolutionContext: (input) => this.
|
|
282
|
+
getQueuedForeignSubtreeResolutionContext: (input) => this.foreignSubtreeExecutionService.getQueuedRuntimeContext(
|
|
283
|
+
input,
|
|
284
|
+
getForeignSubtreeResolutionContextKey(this.name)
|
|
285
|
+
),
|
|
249
286
|
resolveQueuedForeignSubtreeHtml: (html, runtimeContext) => this.resolveReactQueuedForeignSubtreeHtml(html, runtimeContext)
|
|
250
287
|
});
|
|
251
288
|
}
|
|
@@ -401,7 +438,8 @@ class ReactRenderer extends IntegrationRenderer {
|
|
|
401
438
|
}
|
|
402
439
|
}
|
|
403
440
|
);
|
|
404
|
-
|
|
441
|
+
this.appendProcessedDependencies(this.getRendererBootstrapDependencies(false));
|
|
442
|
+
const html = await finalizeDocumentShellHtml(this.htmlTransformer, {
|
|
405
443
|
html: `${this.DOC_TYPE}${documentHtml}`,
|
|
406
444
|
partial: false,
|
|
407
445
|
documentAttributes: this.getRouterDocumentAttributes(),
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import type { ComponentRenderInput, EcoComponent } from '@ecopages/core';
|
|
11
11
|
import type { ProcessedAsset } from '@ecopages/core/services/asset-processing-service';
|
|
12
|
-
import type { DocumentShellComposeChildrenContext, DocumentShellComposeChildrenResult, DocumentShellLayoutInput } from '@ecopages/core/route-renderer/orchestration/document-shell-render.service';
|
|
12
|
+
import type { DocumentShellComposeChildrenContext, DocumentShellComposeChildrenResult, DocumentShellLayoutInput } from '@ecopages/core/route-renderer/orchestration/document-shell/document-shell-render.service';
|
|
13
13
|
import type { ReactElement } from 'react';
|
|
14
14
|
import type { ReactForeignSubtreeResolutionContext } from './component-ssr.js';
|
|
15
15
|
import type { ReactRuntimeModules } from './react-runtime.js';
|