@ecopages/react 0.2.0-rc.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/bundling/bundle.d.ts +2 -2
- package/src/bundling/bundle.js +7 -20
- package/src/client-graph/boundary-cache.js +1 -1
- package/src/hmr/hmr-strategy.d.ts +2 -3
- package/src/hmr/hmr-strategy.js +4 -5
- package/src/hmr/react-hmr-dev-transform-plugins.d.ts +1 -3
- package/src/hmr/react-hmr-dev-transform-plugins.js +2 -6
- package/src/mdx/mdx-loader-plugin.d.ts +1 -1
- package/src/plugin/react.plugin.d.ts +2 -7
- package/src/plugin/react.plugin.js +14 -20
- package/src/plugin/react.types.d.ts +10 -1
- package/src/render/component-ssr.d.ts +0 -21
- package/src/render/component-ssr.js +0 -28
- package/src/render/react-renderer.d.ts +0 -7
- package/src/render/react-renderer.js +8 -40
- package/src/hmr/hmr-scripts.d.ts +0 -18
- package/src/hmr/hmr-scripts.js +0 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/react",
|
|
3
|
-
"version": "0.2.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "React integration for Ecopages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -104,16 +104,16 @@
|
|
|
104
104
|
"directory": "packages/integrations/react"
|
|
105
105
|
},
|
|
106
106
|
"peerDependencies": {
|
|
107
|
-
"@ecopages/core": "0.2.0
|
|
107
|
+
"@ecopages/core": "0.2.0",
|
|
108
108
|
"@types/react": "^19",
|
|
109
109
|
"@types/react-dom": "^19",
|
|
110
110
|
"react": "^19",
|
|
111
111
|
"react-dom": "^19"
|
|
112
112
|
},
|
|
113
113
|
"dependencies": {
|
|
114
|
-
"@ecopages/file-system": "0.2.0
|
|
114
|
+
"@ecopages/file-system": "0.2.0",
|
|
115
115
|
"@ecopages/logger": "^0.2.3",
|
|
116
|
-
"@ecopages/mdx": "0.2.0
|
|
116
|
+
"@ecopages/mdx": "0.2.0",
|
|
117
117
|
"@mdx-js/mdx": "^3.1.1",
|
|
118
118
|
"oxc-parser": "^0.141.0",
|
|
119
119
|
"oxc-transform": "^0.141.0",
|
package/src/bundling/bundle.d.ts
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import type { EcoPagesAppConfig } from '@ecopages/core';
|
|
10
|
+
import type { EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
|
|
10
11
|
import type { AssetProcessingService } from '@ecopages/core/services/asset-processing-service';
|
|
11
12
|
import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
|
|
12
|
-
import type { CompileOptions } from '@mdx-js/mdx';
|
|
13
13
|
import { type ReactRuntimeImports } from './runtime-bundle.js';
|
|
14
14
|
import type { ResolvedReactPluginRuntimeModule } from './runtime-modules.js';
|
|
15
15
|
import type { ClientGraphBoundaryCache } from '../client-graph/boundary-cache.js';
|
|
@@ -22,7 +22,7 @@ export interface BundleServiceConfig {
|
|
|
22
22
|
hostIntegrationName: string;
|
|
23
23
|
routerAdapter?: ReactRouterAdapter;
|
|
24
24
|
runtimeModules?: ResolvedReactPluginRuntimeModule[];
|
|
25
|
-
|
|
25
|
+
getMdxLoaderPlugin?: () => EcoBuildPlugin;
|
|
26
26
|
clientGraphBoundaryCache?: ClientGraphBoundaryCache;
|
|
27
27
|
}
|
|
28
28
|
/**
|
package/src/bundling/bundle.js
CHANGED
|
@@ -11,7 +11,6 @@ import { getReactClientGraphAllowSpecifiers, getReactRuntimeExternalSpecifiers }
|
|
|
11
11
|
import { createBrowserRuntimePlugin } from '@ecopages/core/build/browser-runtime-plugin';
|
|
12
12
|
import { getHostScopedJsxOwnershipPlugins } from '@ecopages/core/build/jsx-ownership-plugins';
|
|
13
13
|
import { RuntimeBundleService } from './runtime-bundle.js';
|
|
14
|
-
import { createReactMdxLoaderPlugin } from '../mdx/mdx-loader-plugin.js';
|
|
15
14
|
import { isReactProductionRuntime } from './runtime-mode.js';
|
|
16
15
|
/**
|
|
17
16
|
* Manages bundle configuration and plugin creation for React page/component builds.
|
|
@@ -99,25 +98,13 @@ export class BundleService {
|
|
|
99
98
|
const runtimePlugins = bundleOptions.includeRuntime
|
|
100
99
|
? []
|
|
101
100
|
: [runtimeRewritePlugin].filter((plugin) => plugin !== null);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
graphBoundaryPlugin,
|
|
110
|
-
...runtimePlugins,
|
|
111
|
-
mdxPlugin,
|
|
112
|
-
];
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
options.plugins = [
|
|
116
|
-
...(foreignJsxOverridePlugin ? [foreignJsxOverridePlugin] : []),
|
|
117
|
-
graphBoundaryPlugin,
|
|
118
|
-
...runtimePlugins,
|
|
119
|
-
];
|
|
120
|
-
}
|
|
101
|
+
const mdxPlugin = isMdx ? this.config.getMdxLoaderPlugin?.() : undefined;
|
|
102
|
+
options.plugins = [
|
|
103
|
+
...(foreignJsxOverridePlugin ? [foreignJsxOverridePlugin] : []),
|
|
104
|
+
graphBoundaryPlugin,
|
|
105
|
+
...runtimePlugins,
|
|
106
|
+
...(mdxPlugin ? [mdxPlugin] : []),
|
|
107
|
+
];
|
|
121
108
|
return options;
|
|
122
109
|
}
|
|
123
110
|
}
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* during the transform is correctly grown on replay against a fresh
|
|
35
35
|
* registry as well.
|
|
36
36
|
*/
|
|
37
|
-
import { rapidhash } from '@ecopages/core/
|
|
37
|
+
import { rapidhash } from '@ecopages/core/hash';
|
|
38
38
|
const DEFAULT_MAX_ENTRIES = 5_000;
|
|
39
39
|
/**
|
|
40
40
|
* Clone a single rule value: `'*'` is a singleton, Sets get a shallow copy.
|
|
@@ -10,7 +10,6 @@ import { HmrStrategy, type HmrAction } from '@ecopages/core/hmr/hmr-strategy';
|
|
|
10
10
|
import type { EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
|
|
11
11
|
import type { BrowserRuntimeManifest } from '@ecopages/core/build/browser-runtime-manifest';
|
|
12
12
|
import type { DefaultHmrContext } from '@ecopages/core';
|
|
13
|
-
import type { CompileOptions } from '@mdx-js/mdx';
|
|
14
13
|
import { ClientGraphBoundaryCache } from '../client-graph/boundary-cache.js';
|
|
15
14
|
import type { HmrPageMetadataCache } from './page-metadata-cache.js';
|
|
16
15
|
export interface ReactHmrStrategyOptions {
|
|
@@ -18,7 +17,7 @@ export interface ReactHmrStrategyOptions {
|
|
|
18
17
|
projectRoot?: string;
|
|
19
18
|
pageMetadataCache: HmrPageMetadataCache;
|
|
20
19
|
runtimeManifest: BrowserRuntimeManifest;
|
|
21
|
-
|
|
20
|
+
getMdxLoaderPlugin?: () => EcoBuildPlugin;
|
|
22
21
|
ownedTemplateExtensions?: string[];
|
|
23
22
|
allTemplateExtensions?: string[];
|
|
24
23
|
/**
|
|
@@ -34,7 +33,7 @@ export interface ReactHmrStrategyOptions {
|
|
|
34
33
|
*/
|
|
35
34
|
export declare class ReactHmrStrategy extends HmrStrategy {
|
|
36
35
|
readonly type: 100;
|
|
37
|
-
private
|
|
36
|
+
private readonly getMdxLoaderPlugin?;
|
|
38
37
|
private readonly projectRoot;
|
|
39
38
|
private readonly ownedTemplateExtensions;
|
|
40
39
|
private readonly allTemplateExtensions;
|
package/src/hmr/hmr-strategy.js
CHANGED
|
@@ -25,7 +25,7 @@ const appLogger = new Logger('[ReactHmrStrategy]');
|
|
|
25
25
|
*/
|
|
26
26
|
export class ReactHmrStrategy extends HmrStrategy {
|
|
27
27
|
type = HmrStrategyType.INTEGRATION;
|
|
28
|
-
|
|
28
|
+
getMdxLoaderPlugin;
|
|
29
29
|
projectRoot;
|
|
30
30
|
ownedTemplateExtensions;
|
|
31
31
|
allTemplateExtensions;
|
|
@@ -39,8 +39,7 @@ export class ReactHmrStrategy extends HmrStrategy {
|
|
|
39
39
|
getDevTransformPluginOptions() {
|
|
40
40
|
return {
|
|
41
41
|
pageMetadataCache: this.pageMetadataCache,
|
|
42
|
-
|
|
43
|
-
projectRoot: this.projectRoot,
|
|
42
|
+
getMdxLoaderPlugin: this.getMdxLoaderPlugin,
|
|
44
43
|
getBuildPlugins: (declaredModules) => this.getBuildPlugins(declaredModules),
|
|
45
44
|
importNodePageModule: (entrypointPath) => this.importNodePageModule(entrypointPath),
|
|
46
45
|
};
|
|
@@ -52,7 +51,7 @@ export class ReactHmrStrategy extends HmrStrategy {
|
|
|
52
51
|
this.pageMetadataCache = options.pageMetadataCache;
|
|
53
52
|
this.runtimeManifest = options.runtimeManifest;
|
|
54
53
|
this.clientGraphBoundaryCache = options.clientGraphBoundaryCache ?? new ClientGraphBoundaryCache();
|
|
55
|
-
this.
|
|
54
|
+
this.getMdxLoaderPlugin = options.getMdxLoaderPlugin;
|
|
56
55
|
this.ownedTemplateExtensions = new Set(options.ownedTemplateExtensions ?? ['.tsx']);
|
|
57
56
|
this.allTemplateExtensions = [...(options.allTemplateExtensions ?? ['.tsx'])].sort((a, b) => b.length - a.length);
|
|
58
57
|
}
|
|
@@ -75,7 +74,7 @@ export class ReactHmrStrategy extends HmrStrategy {
|
|
|
75
74
|
}
|
|
76
75
|
isReactEntrypoint(filePath) {
|
|
77
76
|
if (filePath.endsWith('.mdx')) {
|
|
78
|
-
return this.
|
|
77
|
+
return this.getMdxLoaderPlugin !== undefined;
|
|
79
78
|
}
|
|
80
79
|
if (!filePath.endsWith('.tsx')) {
|
|
81
80
|
return false;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
|
|
2
2
|
import type { EcoComponentConfig } from '@ecopages/core';
|
|
3
|
-
import type { CompileOptions } from '@mdx-js/mdx';
|
|
4
3
|
import type { HmrPageMetadataCache } from './page-metadata-cache.js';
|
|
5
4
|
export type ReactHmrBuildTarget = {
|
|
6
5
|
entrypointPath: string;
|
|
@@ -14,8 +13,7 @@ type ImportedReactPageModule = {
|
|
|
14
13
|
};
|
|
15
14
|
export type ReactHmrDevTransformPluginOptions = {
|
|
16
15
|
pageMetadataCache: HmrPageMetadataCache;
|
|
17
|
-
|
|
18
|
-
projectRoot: string;
|
|
16
|
+
getMdxLoaderPlugin?: () => EcoBuildPlugin;
|
|
19
17
|
getBuildPlugins: (declaredModules?: readonly string[]) => EcoBuildPlugin[];
|
|
20
18
|
importNodePageModule: (entrypointPath: string) => Promise<ImportedReactPageModule>;
|
|
21
19
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { collectPageDeclaredModules, collectPageDeclaredModulesFromModule } from '../client-graph/declared-modules.js';
|
|
2
|
-
import { createReactMdxLoaderPlugin } from '../mdx/mdx-loader-plugin.js';
|
|
3
2
|
export async function resolveReactDeclaredModulesForEntrypoint(options, entrypointPath) {
|
|
4
3
|
const cached = options.pageMetadataCache.getDeclaredModules(entrypointPath);
|
|
5
4
|
if (cached) {
|
|
@@ -13,11 +12,8 @@ export async function resolveReactDeclaredModulesForEntrypoint(options, entrypoi
|
|
|
13
12
|
}
|
|
14
13
|
export function buildReactDevTransformPlugins(options, declaredModules, shouldEnableMdx) {
|
|
15
14
|
const plugins = options.getBuildPlugins(declaredModules);
|
|
16
|
-
if (shouldEnableMdx && options.
|
|
17
|
-
plugins.unshift(
|
|
18
|
-
compilerOptions: options.mdxCompilerOptions,
|
|
19
|
-
projectRoot: options.projectRoot,
|
|
20
|
-
}));
|
|
15
|
+
if (shouldEnableMdx && options.getMdxLoaderPlugin) {
|
|
16
|
+
plugins.unshift(options.getMdxLoaderPlugin());
|
|
21
17
|
}
|
|
22
18
|
return plugins;
|
|
23
19
|
}
|
|
@@ -3,4 +3,4 @@ export interface CreateReactMdxLoaderPluginOptions {
|
|
|
3
3
|
compilerOptions?: CompileOptions;
|
|
4
4
|
projectRoot: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function createReactMdxLoaderPlugin(options: CreateReactMdxLoaderPluginOptions): import("@ecopages/core/
|
|
6
|
+
export declare function createReactMdxLoaderPlugin(options: CreateReactMdxLoaderPluginOptions): import("@ecopages/core/plugins/processor").EcoBuildPlugin;
|
|
@@ -16,10 +16,9 @@ export declare const PLUGIN_NAME = "react";
|
|
|
16
16
|
export declare class ReactPlugin extends IntegrationPlugin<React.ReactNode> {
|
|
17
17
|
renderer: typeof ReactRenderer;
|
|
18
18
|
private readonly routerAdapter;
|
|
19
|
-
private readonly mdxEnabled;
|
|
20
|
-
private readonly mdxCompilerOptions?;
|
|
21
19
|
private readonly mdxExtensions;
|
|
22
20
|
private mdxLoaderPlugin;
|
|
21
|
+
private readonly getMdxLoaderPlugin?;
|
|
23
22
|
private readonly runtimeBundleService;
|
|
24
23
|
private readonly hmrPageMetadataCache;
|
|
25
24
|
private readonly clientGraphBoundaryCache;
|
|
@@ -48,11 +47,7 @@ export declare class ReactPlugin extends IntegrationPlugin<React.ReactNode> {
|
|
|
48
47
|
private resolveEffectiveRuntimeModules;
|
|
49
48
|
get plugins(): EcoBuildPlugin[];
|
|
50
49
|
get browserRuntimeManifest(): BrowserRuntimeManifest;
|
|
51
|
-
|
|
52
|
-
* Ensures the optional React MDX loader exists before either config-time
|
|
53
|
-
* manifest sealing or runtime setup needs it.
|
|
54
|
-
*/
|
|
55
|
-
private ensureMdxLoaderPlugin;
|
|
50
|
+
private createMdxLoaderPlugin;
|
|
56
51
|
/**
|
|
57
52
|
* Prepares React's build-facing loader contributions before config build seals
|
|
58
53
|
* the app manifest.
|
|
@@ -42,7 +42,6 @@ const resolveReactPluginOptions = (options) => {
|
|
|
42
42
|
const rendererConfig = {
|
|
43
43
|
routerAdapter: router,
|
|
44
44
|
runtimeModules: resolvedRuntimeModules,
|
|
45
|
-
mdxCompilerOptions: mdxEnabled && mdx ? resolveReactMdxCompilerOptions(mdx) : undefined,
|
|
46
45
|
mdxExtensions,
|
|
47
46
|
hmrPageMetadataCache: new HmrPageMetadataCache(),
|
|
48
47
|
forceBrowserGraph: explicitGraph ?? false,
|
|
@@ -51,6 +50,7 @@ const resolveReactPluginOptions = (options) => {
|
|
|
51
50
|
...baseConfig,
|
|
52
51
|
extensions,
|
|
53
52
|
integrationDependencies: dependencies,
|
|
53
|
+
mdxCompilerOptions: mdxEnabled && mdx ? resolveReactMdxCompilerOptions(mdx) : undefined,
|
|
54
54
|
rendererConfig,
|
|
55
55
|
};
|
|
56
56
|
};
|
|
@@ -61,10 +61,9 @@ const resolveReactPluginOptions = (options) => {
|
|
|
61
61
|
export class ReactPlugin extends IntegrationPlugin {
|
|
62
62
|
renderer = ReactRenderer;
|
|
63
63
|
routerAdapter;
|
|
64
|
-
mdxEnabled;
|
|
65
|
-
mdxCompilerOptions;
|
|
66
64
|
mdxExtensions;
|
|
67
65
|
mdxLoaderPlugin;
|
|
66
|
+
getMdxLoaderPlugin;
|
|
68
67
|
runtimeBundleService;
|
|
69
68
|
hmrPageMetadataCache;
|
|
70
69
|
clientGraphBoundaryCache;
|
|
@@ -80,7 +79,7 @@ export class ReactPlugin extends IntegrationPlugin {
|
|
|
80
79
|
rendererConfig;
|
|
81
80
|
constructor(options) {
|
|
82
81
|
const config = resolveReactPluginOptions(options);
|
|
83
|
-
const { extensions, rendererConfig, integrationDependencies, ...baseConfig } = config;
|
|
82
|
+
const { extensions, rendererConfig, integrationDependencies, mdxCompilerOptions, ...baseConfig } = config;
|
|
84
83
|
super({
|
|
85
84
|
name: PLUGIN_NAME,
|
|
86
85
|
extensions,
|
|
@@ -89,20 +88,22 @@ export class ReactPlugin extends IntegrationPlugin {
|
|
|
89
88
|
...baseConfig,
|
|
90
89
|
});
|
|
91
90
|
this.routerAdapter = rendererConfig.routerAdapter;
|
|
92
|
-
this.
|
|
93
|
-
|
|
91
|
+
this.getMdxLoaderPlugin = mdxCompilerOptions
|
|
92
|
+
? () => (this.mdxLoaderPlugin ??= this.createMdxLoaderPlugin(mdxCompilerOptions))
|
|
93
|
+
: undefined;
|
|
94
94
|
this.mdxExtensions = rendererConfig.mdxExtensions ?? ['.mdx'];
|
|
95
95
|
this.hmrPageMetadataCache = rendererConfig.hmrPageMetadataCache ?? new HmrPageMetadataCache();
|
|
96
96
|
this.clientGraphBoundaryCache = new ClientGraphBoundaryCache();
|
|
97
97
|
this.forceBrowserGraph = rendererConfig.forceBrowserGraph ?? false;
|
|
98
98
|
this.rendererConfig = {
|
|
99
99
|
...rendererConfig,
|
|
100
|
+
getMdxLoaderPlugin: this.getMdxLoaderPlugin,
|
|
100
101
|
mdxExtensions: this.mdxExtensions,
|
|
101
102
|
hmrPageMetadataCache: this.hmrPageMetadataCache,
|
|
102
103
|
forceBrowserGraph: this.forceBrowserGraph,
|
|
103
104
|
clientGraphBoundaryCache: this.clientGraphBoundaryCache,
|
|
104
105
|
};
|
|
105
|
-
if (
|
|
106
|
+
if (mdxCompilerOptions) {
|
|
106
107
|
appLogger.debug('MDX mode enabled with React jsx runtime');
|
|
107
108
|
}
|
|
108
109
|
this.runtimeBundleService = new RuntimeBundleService({
|
|
@@ -167,19 +168,12 @@ export class ReactPlugin extends IntegrationPlugin {
|
|
|
167
168
|
this.ensureRuntimeDependencies();
|
|
168
169
|
return this.runtimeBundleService.getRuntimeManifest();
|
|
169
170
|
}
|
|
170
|
-
|
|
171
|
-
* Ensures the optional React MDX loader exists before either config-time
|
|
172
|
-
* manifest sealing or runtime setup needs it.
|
|
173
|
-
*/
|
|
174
|
-
async ensureMdxLoaderPlugin() {
|
|
175
|
-
if (!this.mdxEnabled || !this.mdxCompilerOptions || this.mdxLoaderPlugin) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
171
|
+
createMdxLoaderPlugin(compilerOptions) {
|
|
178
172
|
if (!this.appConfig?.rootDir) {
|
|
179
173
|
throw new Error('[ReactPlugin] Cannot create MDX loader: appConfig.rootDir is required.');
|
|
180
174
|
}
|
|
181
|
-
|
|
182
|
-
compilerOptions
|
|
175
|
+
return createReactMdxLoaderPlugin({
|
|
176
|
+
compilerOptions,
|
|
183
177
|
projectRoot: this.appConfig.rootDir,
|
|
184
178
|
});
|
|
185
179
|
}
|
|
@@ -189,7 +183,7 @@ export class ReactPlugin extends IntegrationPlugin {
|
|
|
189
183
|
*/
|
|
190
184
|
async prepareBuildContributions() {
|
|
191
185
|
this.ensureRuntimeDependencies();
|
|
192
|
-
|
|
186
|
+
this.getMdxLoaderPlugin?.();
|
|
193
187
|
}
|
|
194
188
|
/**
|
|
195
189
|
* Performs runtime-only React setup after build contributions are already
|
|
@@ -197,7 +191,7 @@ export class ReactPlugin extends IntegrationPlugin {
|
|
|
197
191
|
*/
|
|
198
192
|
async setup() {
|
|
199
193
|
this.ensureRuntimeDependencies();
|
|
200
|
-
|
|
194
|
+
this.getMdxLoaderPlugin?.();
|
|
201
195
|
await super.setup();
|
|
202
196
|
}
|
|
203
197
|
/**
|
|
@@ -229,7 +223,7 @@ export class ReactPlugin extends IntegrationPlugin {
|
|
|
229
223
|
projectRoot: this.appConfig.rootDir,
|
|
230
224
|
pageMetadataCache: this.hmrPageMetadataCache,
|
|
231
225
|
runtimeManifest: this.runtimeBundleService.getRuntimeManifest('development'),
|
|
232
|
-
|
|
226
|
+
getMdxLoaderPlugin: this.getMdxLoaderPlugin,
|
|
233
227
|
ownedTemplateExtensions: this.extensions,
|
|
234
228
|
allTemplateExtensions: this.appConfig.templatesExt,
|
|
235
229
|
clientGraphBoundaryCache: this.clientGraphBoundaryCache,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AssetDefinition } from '@ecopages/core/services/asset-processing-service';
|
|
2
|
+
import type { EcoBuildPlugin } from '@ecopages/core/plugins/integration-plugin';
|
|
2
3
|
import type { CompileOptions } from '@mdx-js/mdx';
|
|
3
4
|
import type { ReactRouterAdapter } from '../contracts/router-adapter.js';
|
|
4
5
|
import type { HmrPageMetadataCache } from '../hmr/page-metadata-cache.js';
|
|
@@ -149,7 +150,15 @@ export type ReactPluginOptions = {
|
|
|
149
150
|
export type ReactRendererConfig = {
|
|
150
151
|
routerAdapter?: ReactRouterAdapter;
|
|
151
152
|
runtimeModules?: ResolvedReactPluginRuntimeModule[];
|
|
152
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Returns the plugin-owned MDX loader, creating it on first call. Set only
|
|
155
|
+
* when MDX is enabled.
|
|
156
|
+
*
|
|
157
|
+
* @remarks
|
|
158
|
+
* Server builds, browser bundles and HMR rebuilds all use this one loader, so
|
|
159
|
+
* they share its compile cache.
|
|
160
|
+
*/
|
|
161
|
+
getMdxLoaderPlugin?: () => EcoBuildPlugin;
|
|
153
162
|
mdxExtensions?: string[];
|
|
154
163
|
hmrPageMetadataCache?: HmrPageMetadataCache;
|
|
155
164
|
/** Persistent React-plugin-owned cache shared by bundles and HMR transforms. */
|
|
@@ -66,19 +66,6 @@ export declare function renderQueuedChildrenToHtml(options: {
|
|
|
66
66
|
normalizeUnresolvedMarkerArtifactHtml: (html: string) => string;
|
|
67
67
|
resolveQueuedTokens: (html: string, queuedResolutionsByToken: Map<string, ReactForeignSubtreeResolutionContext['queuedResolutions'][number]>, resolveToken: (token: string) => Promise<string>) => Promise<string>;
|
|
68
68
|
}): Promise<string | undefined>;
|
|
69
|
-
export declare function renderReactQueuedForeignSubtreeChildren(options: {
|
|
70
|
-
children: unknown;
|
|
71
|
-
currentRuntimeContext: ReactForeignSubtreeResolutionContext;
|
|
72
|
-
queuedResolutionsByToken: Map<string, ReactForeignSubtreeResolutionContext['queuedResolutions'][number]>;
|
|
73
|
-
resolveToken: (token: string) => Promise<string>;
|
|
74
|
-
runtime: ReactRuntimeModules;
|
|
75
|
-
integrationName: string;
|
|
76
|
-
normalizeUnresolvedMarkerArtifactHtml: (html: string) => string;
|
|
77
|
-
resolveQueuedTokens: (html: string, queuedResolutionsByToken: Map<string, ReactForeignSubtreeResolutionContext['queuedResolutions'][number]>, resolveToken: (token: string) => Promise<string>) => Promise<string>;
|
|
78
|
-
}): Promise<{
|
|
79
|
-
assets: ProcessedAsset[];
|
|
80
|
-
html?: string;
|
|
81
|
-
}>;
|
|
82
69
|
export declare function renderForeignComponentWithSerializedHtml(options: {
|
|
83
70
|
input: ComponentRenderInput;
|
|
84
71
|
runtimeContext: ReactForeignSubtreeResolutionContext | undefined;
|
|
@@ -120,11 +107,3 @@ export declare function renderReactManagedComponent(options: {
|
|
|
120
107
|
hydrationAssetService: HydrationAssetService;
|
|
121
108
|
canBuildIslandAssets: boolean;
|
|
122
109
|
}): Promise<ComponentRenderResult>;
|
|
123
|
-
/**
|
|
124
|
-
* Creates the per-render state used to resolve foreign child subtrees without
|
|
125
|
-
* leaking renderer caches or instance identity into another render.
|
|
126
|
-
*/
|
|
127
|
-
export declare function createForeignSubtreeRuntimeContext(options: {
|
|
128
|
-
rendererCache: Map<string, IntegrationRenderer<any>>;
|
|
129
|
-
componentInstanceScope?: string;
|
|
130
|
-
}): ReactForeignSubtreeResolutionContext;
|
|
@@ -87,20 +87,6 @@ export async function renderQueuedChildrenToHtml(options) {
|
|
|
87
87
|
html = restoreRuntimeChildHtml(html, runtimeContext);
|
|
88
88
|
return await resolveQueuedTokens(html, queuedResolutionsByToken, resolveToken);
|
|
89
89
|
}
|
|
90
|
-
export async function renderReactQueuedForeignSubtreeChildren(options) {
|
|
91
|
-
const { currentRuntimeContext, ...rest } = options;
|
|
92
|
-
const renderedHtml = await renderQueuedChildrenToHtml({
|
|
93
|
-
...rest,
|
|
94
|
-
runtimeContext: currentRuntimeContext,
|
|
95
|
-
});
|
|
96
|
-
if (renderedHtml === undefined) {
|
|
97
|
-
return { assets: [] };
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
assets: [],
|
|
101
|
-
html: renderedHtml,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
90
|
export async function renderForeignComponentWithSerializedHtml(options) {
|
|
105
91
|
const { input, runtimeContext, integrationName, canResolveAssets, processComponentDependencies, dedupeProcessedAssets, getRootTagName, resolveQueuedForeignSubtreeHtml, } = options;
|
|
106
92
|
let props = input.props;
|
|
@@ -182,17 +168,3 @@ export async function renderReactManagedComponent(options) {
|
|
|
182
168
|
assets: mergedAssets.length > 0 ? mergedAssets : undefined,
|
|
183
169
|
};
|
|
184
170
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Creates the per-render state used to resolve foreign child subtrees without
|
|
187
|
-
* leaking renderer caches or instance identity into another render.
|
|
188
|
-
*/
|
|
189
|
-
export function createForeignSubtreeRuntimeContext(options) {
|
|
190
|
-
return {
|
|
191
|
-
rendererCache: options.rendererCache,
|
|
192
|
-
componentInstanceScope: options.componentInstanceScope,
|
|
193
|
-
nextForeignSubtreeId: 0,
|
|
194
|
-
queuedResolutions: [],
|
|
195
|
-
rawChildrenToken: undefined,
|
|
196
|
-
rawChildrenHtml: undefined,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
@@ -19,7 +19,6 @@ 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
21
|
import { type DocumentShellLayoutInput } from '@ecopages/core/route-renderer/orchestration/document-shell/document-shell-render.service';
|
|
22
|
-
import type { ForeignChildRuntime } from '@ecopages/core/route-renderer/orchestration/foreign-child/component-render-context';
|
|
23
22
|
import { type ReactRuntimeModules } from './react-runtime.js';
|
|
24
23
|
export type { ReactRendererConfig } from '../plugin/react.types.js';
|
|
25
24
|
export { BundleError, ReactRenderError } from './errors.js';
|
|
@@ -35,7 +34,6 @@ export declare class ReactRenderer extends IntegrationRenderer<ReactNode> {
|
|
|
35
34
|
componentDirectory: string;
|
|
36
35
|
private reactRuntimeModules?;
|
|
37
36
|
private readonly routerAdapter?;
|
|
38
|
-
private readonly mdxCompilerOptions?;
|
|
39
37
|
private readonly mdxExtensions;
|
|
40
38
|
private readonly hmrPageMetadataCache?;
|
|
41
39
|
/**
|
|
@@ -64,7 +62,6 @@ export declare class ReactRenderer extends IntegrationRenderer<ReactNode> {
|
|
|
64
62
|
* HTML transformer state.
|
|
65
63
|
*/
|
|
66
64
|
private appendHydrationAssetsForFile;
|
|
67
|
-
private resolveOwningRenderer;
|
|
68
65
|
private resolveReactQueuedForeignSubtreeHtml;
|
|
69
66
|
/**
|
|
70
67
|
* Renders a React component for component-level orchestration.
|
|
@@ -81,10 +78,6 @@ export declare class ReactRenderer extends IntegrationRenderer<ReactNode> {
|
|
|
81
78
|
* deterministic mount target per component instance.
|
|
82
79
|
*/
|
|
83
80
|
renderComponent(input: ComponentRenderInput): Promise<ComponentRenderResult>;
|
|
84
|
-
protected createForeignChildRuntime(options: {
|
|
85
|
-
renderInput: ComponentRenderInput;
|
|
86
|
-
rendererCache: Map<string, IntegrationRenderer<any>>;
|
|
87
|
-
}): ForeignChildRuntime;
|
|
88
81
|
/**
|
|
89
82
|
* Checks if the given file path corresponds to an MDX file based on configured extensions.
|
|
90
83
|
* @param filePath - The file path to check
|
|
@@ -23,9 +23,8 @@ import { PagePayloadService } from '../hydration/page-payload.js';
|
|
|
23
23
|
import { HydrationAssetService } from '../hydration/hydration-asset.js';
|
|
24
24
|
import { composeDocumentShell, finalizeDocumentShellHtml, renderPageDocumentShell, } from '@ecopages/core/route-renderer/orchestration/document-shell/document-shell-render.service';
|
|
25
25
|
import { mergePageBrowserGraph } from '@ecopages/core/route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils';
|
|
26
|
-
import { getForeignSubtreeResolutionContextKey, getForeignSubtreeTokenPrefix, resolveOwningIntegrationRenderer, } from '@ecopages/core/route-renderer/orchestration/foreign-child/owning-renderer-resolution';
|
|
27
26
|
import { asReactComponent, getComponentRequires, isReactManagedComponent } from './component-ownership.js';
|
|
28
|
-
import {
|
|
27
|
+
import { renderForeignComponentWithSerializedHtml, renderReactManagedComponent, renderQueuedChildrenToHtml, } from './component-ssr.js';
|
|
29
28
|
import { BundleError, ReactRenderError } from './errors.js';
|
|
30
29
|
import { resolveReactRuntimeModules } from './react-runtime.js';
|
|
31
30
|
import { composeReactLayoutPageChildren, resolveComposeChildren } from './unified-layout-composition.js';
|
|
@@ -39,7 +38,6 @@ export class ReactRenderer extends IntegrationRenderer {
|
|
|
39
38
|
componentDirectory = RESOLVED_ASSETS_DIR;
|
|
40
39
|
reactRuntimeModules;
|
|
41
40
|
routerAdapter;
|
|
42
|
-
mdxCompilerOptions;
|
|
43
41
|
mdxExtensions;
|
|
44
42
|
hmrPageMetadataCache;
|
|
45
43
|
/**
|
|
@@ -63,7 +61,6 @@ export class ReactRenderer extends IntegrationRenderer {
|
|
|
63
61
|
const { reactConfig, ...rendererOptions } = options;
|
|
64
62
|
super(rendererOptions);
|
|
65
63
|
this.routerAdapter = reactConfig?.routerAdapter;
|
|
66
|
-
this.mdxCompilerOptions = reactConfig?.mdxCompilerOptions;
|
|
67
64
|
this.mdxExtensions = reactConfig?.mdxExtensions ?? ['.mdx'];
|
|
68
65
|
this.hmrPageMetadataCache = reactConfig?.hmrPageMetadataCache;
|
|
69
66
|
this.forceBrowserGraph = reactConfig?.forceBrowserGraph ?? false;
|
|
@@ -73,7 +70,7 @@ export class ReactRenderer extends IntegrationRenderer {
|
|
|
73
70
|
hostIntegrationName: this.name,
|
|
74
71
|
routerAdapter: this.routerAdapter,
|
|
75
72
|
runtimeModules: reactConfig?.runtimeModules,
|
|
76
|
-
|
|
73
|
+
getMdxLoaderPlugin: reactConfig?.getMdxLoaderPlugin,
|
|
77
74
|
clientGraphBoundaryCache: reactConfig?.clientGraphBoundaryCache,
|
|
78
75
|
});
|
|
79
76
|
this.pageModuleService = new PageModuleService({
|
|
@@ -127,28 +124,11 @@ export class ReactRenderer extends IntegrationRenderer {
|
|
|
127
124
|
const { pagePackage } = mergePageBrowserGraph(this.htmlTransformer.getPagePackage(), this.htmlTransformer.getProcessedDependencies(), pageBrowserGraph);
|
|
128
125
|
this.htmlTransformer.setPagePackage(pagePackage);
|
|
129
126
|
}
|
|
130
|
-
resolveOwningRenderer(integrationName, rendererCache) {
|
|
131
|
-
return resolveOwningIntegrationRenderer({
|
|
132
|
-
appConfig: this.appConfig,
|
|
133
|
-
runtimeOrigin: this.runtimeOrigin,
|
|
134
|
-
currentIntegrationName: this.name,
|
|
135
|
-
currentRenderer: this,
|
|
136
|
-
integrationName,
|
|
137
|
-
cache: rendererCache,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
127
|
resolveReactQueuedForeignSubtreeHtml(html, runtimeContext) {
|
|
141
|
-
return this.
|
|
142
|
-
|
|
143
|
-
html,
|
|
144
|
-
runtimeContext,
|
|
145
|
-
queueLabel: 'React',
|
|
146
|
-
getOwningRenderer: (integrationName, rendererCache) => this.resolveOwningRenderer(integrationName, rendererCache),
|
|
147
|
-
applyAttributesToFirstElement: (resolvedHtml, attributes) => this.htmlTransformer.applyAttributesToFirstElement(resolvedHtml, attributes),
|
|
148
|
-
dedupeProcessedAssets: (assets) => this.htmlTransformer.dedupeProcessedAssets(assets),
|
|
149
|
-
renderQueuedChildren: (children, currentRuntimeContext, queuedResolutionsByToken, resolveToken) => renderReactQueuedForeignSubtreeChildren({
|
|
128
|
+
return this.resolveQueuedForeignSubtrees(html, runtimeContext, async (children, currentRuntimeContext, queuedResolutionsByToken, resolveToken) => ({
|
|
129
|
+
html: await renderQueuedChildrenToHtml({
|
|
150
130
|
children,
|
|
151
|
-
currentRuntimeContext,
|
|
131
|
+
runtimeContext: currentRuntimeContext,
|
|
152
132
|
queuedResolutionsByToken,
|
|
153
133
|
resolveToken,
|
|
154
134
|
runtime: this.getReactRuntimeModules(),
|
|
@@ -156,7 +136,7 @@ export class ReactRenderer extends IntegrationRenderer {
|
|
|
156
136
|
normalizeUnresolvedMarkerArtifactHtml: (value) => this.normalizeUnresolvedMarkerArtifactHtml(value),
|
|
157
137
|
resolveQueuedTokens: (value, tokens, resolve) => this.foreignSubtreeExecutionService.resolveQueuedTokens(value, tokens, resolve),
|
|
158
138
|
}),
|
|
159
|
-
});
|
|
139
|
+
}));
|
|
160
140
|
}
|
|
161
141
|
/**
|
|
162
142
|
* Renders a React component for component-level orchestration.
|
|
@@ -173,7 +153,7 @@ export class ReactRenderer extends IntegrationRenderer {
|
|
|
173
153
|
* deterministic mount target per component instance.
|
|
174
154
|
*/
|
|
175
155
|
async renderComponent(input) {
|
|
176
|
-
const runtimeContext = this.
|
|
156
|
+
const runtimeContext = this.getQueuedForeignSubtreeContext(input);
|
|
177
157
|
if (!isReactManagedComponent(input.component, this.name)) {
|
|
178
158
|
return renderForeignComponentWithSerializedHtml({
|
|
179
159
|
input,
|
|
@@ -199,18 +179,6 @@ export class ReactRenderer extends IntegrationRenderer {
|
|
|
199
179
|
canBuildIslandAssets: Boolean(this.assetProcessingService),
|
|
200
180
|
});
|
|
201
181
|
}
|
|
202
|
-
createForeignChildRuntime(options) {
|
|
203
|
-
return this.foreignSubtreeExecutionService.createQueuedRuntime({
|
|
204
|
-
renderInput: options.renderInput,
|
|
205
|
-
rendererCache: options.rendererCache,
|
|
206
|
-
runtimeContextKey: getForeignSubtreeResolutionContextKey(this.name),
|
|
207
|
-
tokenPrefix: getForeignSubtreeTokenPrefix(this.name),
|
|
208
|
-
createRuntimeContext: (integrationContext, rendererCache) => createForeignSubtreeRuntimeContext({
|
|
209
|
-
rendererCache: rendererCache,
|
|
210
|
-
componentInstanceScope: integrationContext.componentInstanceId,
|
|
211
|
-
}),
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
182
|
/**
|
|
215
183
|
* Checks if the given file path corresponds to an MDX file based on configured extensions.
|
|
216
184
|
* @param filePath - The file path to check
|
|
@@ -270,7 +238,7 @@ export class ReactRenderer extends IntegrationRenderer {
|
|
|
270
238
|
integrationName: this.name,
|
|
271
239
|
normalizeUnresolvedMarkerArtifactHtml: (html) => this.normalizeUnresolvedMarkerArtifactHtml(html),
|
|
272
240
|
getRootTagName: (html) => this.getRootTagName(html),
|
|
273
|
-
getQueuedForeignSubtreeResolutionContext: (input) => this.
|
|
241
|
+
getQueuedForeignSubtreeResolutionContext: (input) => this.getQueuedForeignSubtreeContext(input),
|
|
274
242
|
resolveQueuedForeignSubtreeHtml: (html, runtimeContext) => this.resolveReactQueuedForeignSubtreeHtml(html, runtimeContext),
|
|
275
243
|
});
|
|
276
244
|
}
|
package/src/hmr/hmr-scripts.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HMR script utilities for React components.
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Checks if code has already been processed with HMR marker.
|
|
7
|
-
* @param code - The bundled code to check
|
|
8
|
-
* @returns True if the code already contains the HMR marker
|
|
9
|
-
*/
|
|
10
|
-
export declare function hasHmrMarker(code: string): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Injects HMR acceptance handler into bundled code.
|
|
13
|
-
* When a module with React exports changes, it triggers a full invalidation
|
|
14
|
-
* to ensure the parent module re-imports and re-renders with the updated component.
|
|
15
|
-
* @param code - The bundled code to wrap
|
|
16
|
-
* @returns Code with HMR handler injected
|
|
17
|
-
*/
|
|
18
|
-
export declare function injectHmrHandler(code: string): string;
|
package/src/hmr/hmr-scripts.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HMR script utilities for React components.
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
/** Marker comment to identify already-processed HMR code */
|
|
6
|
-
const HMR_MARKER = '/* [ecopages] react-hmr */';
|
|
7
|
-
/**
|
|
8
|
-
* Checks if code has already been processed with HMR marker.
|
|
9
|
-
* @param code - The bundled code to check
|
|
10
|
-
* @returns True if the code already contains the HMR marker
|
|
11
|
-
*/
|
|
12
|
-
export function hasHmrMarker(code) {
|
|
13
|
-
return code.includes(HMR_MARKER);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Injects HMR acceptance handler into bundled code.
|
|
17
|
-
* When a module with React exports changes, it triggers a full invalidation
|
|
18
|
-
* to ensure the parent module re-imports and re-renders with the updated component.
|
|
19
|
-
* @param code - The bundled code to wrap
|
|
20
|
-
* @returns Code with HMR handler injected
|
|
21
|
-
*/
|
|
22
|
-
export function injectHmrHandler(code) {
|
|
23
|
-
return `${HMR_MARKER}
|
|
24
|
-
${code}
|
|
25
|
-
if (import.meta.hot) {
|
|
26
|
-
import.meta.hot.accept((newModule) => {
|
|
27
|
-
if (newModule) {
|
|
28
|
-
const exports = Object.keys(newModule);
|
|
29
|
-
const hasReactExport = exports.some(key => {
|
|
30
|
-
const value = newModule[key];
|
|
31
|
-
return value && (
|
|
32
|
-
typeof value === 'function' ||
|
|
33
|
-
(typeof value === 'object' && value.$$typeof)
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (hasReactExport) {
|
|
38
|
-
import.meta.hot.invalidate();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
`;
|
|
44
|
-
}
|