@ecopages/react 0.2.0-beta.31 → 0.2.0-beta.33

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 (57) hide show
  1. package/README.md +5 -1
  2. package/package.json +4 -4
  3. package/src/app/client-only.js +13 -17
  4. package/src/app/dynamic.js +7 -10
  5. package/src/app/dynamic.test.browser.js +27 -29
  6. package/src/bundling/bootstrap-package-paths.js +5 -6
  7. package/src/bundling/bundle.js +115 -114
  8. package/src/bundling/discover-layout-runtime-modules.js +166 -155
  9. package/src/bundling/runtime-alias-map.d.ts +4 -1
  10. package/src/bundling/runtime-alias-map.js +107 -95
  11. package/src/bundling/runtime-bundle.js +250 -274
  12. package/src/bundling/runtime-interop-plugin.js +31 -35
  13. package/src/bundling/runtime-mode.js +10 -5
  14. package/src/bundling/runtime-modules.js +46 -35
  15. package/src/client-graph/ast-transform.js +415 -305
  16. package/src/client-graph/boundary-cache.js +146 -104
  17. package/src/client-graph/boundary-plugin.js +122 -104
  18. package/src/client-graph/component-config-traversal.js +70 -49
  19. package/src/client-graph/declared-modules.js +63 -41
  20. package/src/client-graph/reachability-analyzer.js +506 -313
  21. package/src/client-graph/specifier-classification.js +209 -141
  22. package/src/contracts/router-adapter.js +6 -0
  23. package/src/dev-transform/react-dev-transform-contributor.d.ts +17 -0
  24. package/src/dev-transform/react-dev-transform-contributor.js +22 -0
  25. package/src/hmr/hmr-scripts.js +22 -9
  26. package/src/hmr/hmr-strategy.d.ts +12 -181
  27. package/src/hmr/hmr-strategy.js +321 -650
  28. package/src/hmr/page-metadata-cache.js +43 -40
  29. package/src/hmr/react-hmr-dev-transform-plugins.d.ts +23 -0
  30. package/src/hmr/react-hmr-dev-transform-plugins.js +20 -0
  31. package/src/hydration/assert-no-bare-ecopages-imports.js +6 -6
  32. package/src/hydration/bootstrap-imports.js +30 -20
  33. package/src/hydration/hydration-asset.js +216 -213
  34. package/src/hydration/hydration-scripts.d.ts +4 -0
  35. package/src/hydration/hydration-scripts.js +199 -66
  36. package/src/hydration/hydration-scripts.test.browser.js +163 -168
  37. package/src/hydration/page-data-manifest.js +89 -45
  38. package/src/hydration/page-data-reader.js +45 -32
  39. package/src/hydration/page-payload.js +101 -99
  40. package/src/hydration/serialize-page-data-script.js +27 -28
  41. package/src/mdx/mdx-config-dependency.js +108 -112
  42. package/src/mdx/mdx-loader-plugin.js +7 -10
  43. package/src/page/page-module.js +72 -66
  44. package/src/plugin/react.constants.js +1 -4
  45. package/src/plugin/react.plugin.d.ts +1 -0
  46. package/src/plugin/react.plugin.js +227 -216
  47. package/src/plugin/react.types.js +1 -0
  48. package/src/render/component-ownership.js +42 -18
  49. package/src/render/component-ssr.js +168 -190
  50. package/src/render/eco-embed.js +8 -10
  51. package/src/render/errors.js +21 -16
  52. package/src/render/html-boundary.js +55 -51
  53. package/src/render/layout-compose.js +122 -94
  54. package/src/render/react-renderer.js +433 -468
  55. package/src/render/react-runtime.js +25 -20
  56. package/src/render/unified-layout-composition.js +74 -85
  57. package/src/runtime/use-sync-external-store-with-selector.js +52 -54
@@ -1,72 +1,78 @@
1
- import path from "node:path";
2
- import { rapidhash } from "@ecopages/core/hash";
3
- import { fileSystem } from "@ecopages/file-system";
4
- import { someInConfigTree } from "../client-graph/component-config-traversal.js";
5
- import { collectPageDeclaredModulesFromModule } from "../client-graph/declared-modules.js";
6
- class PageModuleService {
7
- config;
8
- constructor(config) {
9
- this.config = config;
10
- }
11
- /**
12
- * Checks if the given file path corresponds to an MDX file based on configured extensions.
13
- */
14
- isMdxFile(filePath) {
15
- return this.config.mdxExtensions.some((ext) => filePath.endsWith(ext));
16
- }
17
- /**
18
- * Ensures that an EcoComponentConfig has proper `__eco` metadata attached.
19
- */
20
- ensureConfigFileMetadata(config, pagePath) {
21
- if (config.__eco?.file) {
22
- return config;
1
+ /**
2
+ * Page module loading and configuration resolution service for React integration.
3
+ *
4
+ * Handles component config metadata resolution and module hydration analysis.
5
+ * MDX page modules load through the core {@link PageModuleImportService} path
6
+ * using the React plugin's server build contributions.
7
+ *
8
+ * @module
9
+ */
10
+ import path from 'node:path';
11
+ import { rapidhash } from '@ecopages/core/hash';
12
+ import { fileSystem } from '@ecopages/file-system';
13
+ import { someInConfigTree } from '../client-graph/component-config-traversal.js';
14
+ import { collectPageDeclaredModulesFromModule } from '../client-graph/declared-modules.js';
15
+ /**
16
+ * Manages page module metadata resolution and hydration analysis for React pages.
17
+ */
18
+ export class PageModuleService {
19
+ config;
20
+ constructor(config) {
21
+ this.config = config;
23
22
  }
24
- const buildEcoMeta = (file) => ({
25
- id: config.__eco?.id ?? rapidhash(file).toString(36),
26
- integration: config.__eco?.integration ?? this.config.integrationName,
27
- file
28
- });
29
- const resolveDependencyValue = (value) => typeof value === "string" ? value : value.src;
30
- const dependencyPaths = [
31
- ...(config.dependencies?.stylesheets ?? []).map(resolveDependencyValue),
32
- ...(config.dependencies?.scripts ?? []).map(resolveDependencyValue)
33
- ].filter((value) => Boolean(value)).filter((value) => value.startsWith("./") || value.startsWith("../"));
34
- const candidateDirs = [this.config.layoutsDir, this.config.componentsDir, path.dirname(pagePath)].filter(
35
- (value) => typeof value === "string" && value.length > 0
36
- );
37
- for (const dependencyPath of dependencyPaths) {
38
- for (const candidateDir of candidateDirs) {
39
- const resolvedDependency = path.resolve(candidateDir, dependencyPath);
40
- if (fileSystem.exists(resolvedDependency)) {
41
- return {
23
+ /**
24
+ * Checks if the given file path corresponds to an MDX file based on configured extensions.
25
+ */
26
+ isMdxFile(filePath) {
27
+ return this.config.mdxExtensions.some((ext) => filePath.endsWith(ext));
28
+ }
29
+ /**
30
+ * Ensures that an EcoComponentConfig has proper `__eco` metadata attached.
31
+ */
32
+ ensureConfigFileMetadata(config, pagePath) {
33
+ if (config.__eco?.file) {
34
+ return config;
35
+ }
36
+ const buildEcoMeta = (file) => ({
37
+ id: config.__eco?.id ?? rapidhash(file).toString(36),
38
+ integration: config.__eco?.integration ?? this.config.integrationName,
39
+ file,
40
+ });
41
+ const resolveDependencyValue = (value) => typeof value === 'string' ? value : value.src;
42
+ const dependencyPaths = [
43
+ ...(config.dependencies?.stylesheets ?? []).map(resolveDependencyValue),
44
+ ...(config.dependencies?.scripts ?? []).map(resolveDependencyValue),
45
+ ]
46
+ .filter((value) => Boolean(value))
47
+ .filter((value) => value.startsWith('./') || value.startsWith('../'));
48
+ const candidateDirs = [this.config.layoutsDir, this.config.componentsDir, path.dirname(pagePath)].filter((value) => typeof value === 'string' && value.length > 0);
49
+ for (const dependencyPath of dependencyPaths) {
50
+ for (const candidateDir of candidateDirs) {
51
+ const resolvedDependency = path.resolve(candidateDir, dependencyPath);
52
+ if (fileSystem.exists(resolvedDependency)) {
53
+ return {
54
+ ...config,
55
+ __eco: buildEcoMeta(path.join(candidateDir, path.basename(pagePath))),
56
+ };
57
+ }
58
+ }
59
+ }
60
+ return {
42
61
  ...config,
43
- __eco: buildEcoMeta(path.join(candidateDir, path.basename(pagePath)))
44
- };
62
+ __eco: buildEcoMeta(pagePath),
63
+ };
64
+ }
65
+ hasModulesInConfig(config) {
66
+ return someInConfigTree(config, (node) => node.dependencies?.modules?.some((entry) => entry.trim().length > 0) ?? false);
67
+ }
68
+ shouldHydratePage(pageModule) {
69
+ if (this.config.hasRouterAdapter) {
70
+ return true;
45
71
  }
46
- }
72
+ const pageConfig = pageModule.default?.config;
73
+ return this.hasModulesInConfig(pageConfig) || this.hasModulesInConfig(pageModule.config);
47
74
  }
48
- return {
49
- ...config,
50
- __eco: buildEcoMeta(pagePath)
51
- };
52
- }
53
- hasModulesInConfig(config) {
54
- return someInConfigTree(
55
- config,
56
- (node) => node.dependencies?.modules?.some((entry) => entry.trim().length > 0) ?? false
57
- );
58
- }
59
- shouldHydratePage(pageModule) {
60
- if (this.config.hasRouterAdapter) {
61
- return true;
75
+ collectPageDeclaredModules(pageModule) {
76
+ return collectPageDeclaredModulesFromModule(pageModule);
62
77
  }
63
- const pageConfig = pageModule.default?.config;
64
- return this.hasModulesInConfig(pageConfig) || this.hasModulesInConfig(pageModule.config);
65
- }
66
- collectPageDeclaredModules(pageModule) {
67
- return collectPageDeclaredModulesFromModule(pageModule);
68
- }
69
78
  }
70
- export {
71
- PageModuleService
72
- };
@@ -1,4 +1 @@
1
- const REACT_PLUGIN_NAME = "react";
2
- export {
3
- REACT_PLUGIN_NAME
4
- };
1
+ export const REACT_PLUGIN_NAME = 'react';
@@ -72,6 +72,7 @@ export declare class ReactPlugin extends IntegrationPlugin<React.ReactNode> {
72
72
  *
73
73
  * @returns ReactHmrStrategy instance for handling React component updates
74
74
  */
75
+ setHmrManager(hmrManager: NonNullable<IntegrationPlugin['hmrManager']>): void;
75
76
  getHmrStrategy(): HmrStrategy | undefined;
76
77
  }
77
78
  /**
@@ -1,229 +1,240 @@
1
- import {
2
- IntegrationPlugin
3
- } from "@ecopages/core/plugins/integration-plugin";
4
- import { Logger } from "@ecopages/logger";
5
- import path from "node:path";
6
- import { REACT_PLUGIN_NAME } from "./react.constants.js";
7
- import { ReactRenderer } from "../render/react-renderer.js";
8
- import { ReactHmrStrategy } from "../hmr/hmr-strategy.js";
9
- import { RuntimeBundleService } from "../bundling/runtime-bundle.js";
10
- import { HmrPageMetadataCache } from "../hmr/page-metadata-cache.js";
11
- import { createReactMdxLoaderPlugin } from "../mdx/mdx-loader-plugin.js";
12
- import { appendMdxExtensions, resolveMdxCompilerOptions } from "@ecopages/mdx/core";
13
- import { ClientGraphBoundaryCache } from "../client-graph/boundary-cache.js";
14
- import { discoverLayoutRuntimeModuleSpecifiers } from "../bundling/discover-layout-runtime-modules.js";
15
- import { mergeReactPluginRuntimeModules, resolveReactPluginRuntimeModules } from "../bundling/runtime-modules.js";
16
- const appLogger = new Logger("[ReactPlugin]");
17
- const PLUGIN_NAME = REACT_PLUGIN_NAME;
18
- const resolveReactMdxCompilerOptions = (mdxOptions) => resolveMdxCompilerOptions(mdxOptions, { jsxImportSource: "react" });
1
+ import { IntegrationPlugin, } from '@ecopages/core/plugins/integration-plugin';
2
+ import { Logger } from '@ecopages/logger';
3
+ import path from 'node:path';
4
+ import { REACT_PLUGIN_NAME } from './react.constants.js';
5
+ import { ReactRenderer } from '../render/react-renderer.js';
6
+ import { ReactHmrStrategy } from '../hmr/hmr-strategy.js';
7
+ import { ReactDevTransformContributor } from '../dev-transform/react-dev-transform-contributor.js';
8
+ import { RuntimeBundleService } from '../bundling/runtime-bundle.js';
9
+ import { HmrPageMetadataCache } from '../hmr/page-metadata-cache.js';
10
+ import { createReactMdxLoaderPlugin } from '../mdx/mdx-loader-plugin.js';
11
+ import { appendMdxExtensions, resolveMdxCompilerOptions } from '@ecopages/mdx/core';
12
+ import { ClientGraphBoundaryCache } from '../client-graph/boundary-cache.js';
13
+ import { discoverLayoutRuntimeModuleSpecifiers } from '../bundling/discover-layout-runtime-modules.js';
14
+ import { mergeReactPluginRuntimeModules, resolveReactPluginRuntimeModules } from '../bundling/runtime-modules.js';
15
+ const appLogger = new Logger('[ReactPlugin]');
16
+ /**
17
+ * The name of the React plugin
18
+ */
19
+ export const PLUGIN_NAME = REACT_PLUGIN_NAME;
20
+ const resolveReactMdxCompilerOptions = (mdxOptions) => resolveMdxCompilerOptions(mdxOptions, { jsxImportSource: 'react' });
21
+ /**
22
+ * Resolves user-facing React plugin options into the internal plugin config.
23
+ *
24
+ * Defaults:
25
+ * - `extensions`: `['.tsx']`
26
+ * - `explicitGraph`: `false`
27
+ * - `mdx.enabled`: `false`
28
+ * - `mdx.extensions`: `['.mdx']`
29
+ */
19
30
  const resolveReactPluginOptions = (options) => {
20
- const {
21
- extensions: userExtensions,
22
- router,
23
- mdx,
24
- explicitGraph,
25
- dependencies,
26
- runtimeModules,
27
- ...baseConfig
28
- } = options ?? {};
29
- const extensions = [...userExtensions ?? [".tsx"]];
30
- const mdxEnabled = mdx?.enabled ?? false;
31
- const mdxExtensions = mdx?.extensions ?? [".mdx"];
32
- const resolvedRuntimeModules = resolveReactPluginRuntimeModules(runtimeModules);
33
- if (mdxEnabled) {
34
- appendMdxExtensions(extensions, mdxExtensions);
35
- } else if (mdx?.extensions?.length) {
36
- appLogger.warn(
37
- "MDX extensions provided but MDX is disabled. MDX files will not be processed. Set mdx.enabled to true to enable MDX support."
38
- );
39
- }
40
- const rendererConfig = {
41
- routerAdapter: router,
42
- runtimeModules: resolvedRuntimeModules,
43
- mdxCompilerOptions: mdxEnabled && mdx ? resolveReactMdxCompilerOptions(mdx) : void 0,
44
- mdxExtensions,
45
- hmrPageMetadataCache: new HmrPageMetadataCache(),
46
- forceBrowserGraph: explicitGraph ?? false
47
- };
48
- return {
49
- ...baseConfig,
50
- extensions,
51
- integrationDependencies: dependencies,
52
- rendererConfig
53
- };
54
- };
55
- class ReactPlugin extends IntegrationPlugin {
56
- renderer = ReactRenderer;
57
- routerAdapter;
58
- mdxEnabled;
59
- mdxCompilerOptions;
60
- mdxExtensions;
61
- mdxLoaderPlugin;
62
- runtimeBundleService;
63
- hmrPageMetadataCache;
64
- clientGraphBoundaryCache;
65
- hmrStrategy;
66
- runtimeDependenciesInitialized = false;
67
- /**
68
- * When true, always emit page browser graph / hydration assets.
69
- *
70
- * @remarks
71
- * Mapped from public `explicitGraph`. Does not skip client-graph AST stripping.
72
- */
73
- forceBrowserGraph;
74
- rendererConfig;
75
- constructor(options) {
76
- const config = resolveReactPluginOptions(options);
77
- const { extensions, rendererConfig, integrationDependencies, ...baseConfig } = config;
78
- super({
79
- name: PLUGIN_NAME,
80
- extensions,
81
- jsxImportSource: "react",
82
- integrationDependencies,
83
- ...baseConfig
84
- });
85
- this.routerAdapter = rendererConfig.routerAdapter;
86
- this.mdxCompilerOptions = rendererConfig.mdxCompilerOptions;
87
- this.mdxEnabled = Boolean(rendererConfig.mdxCompilerOptions);
88
- this.mdxExtensions = rendererConfig.mdxExtensions ?? [".mdx"];
89
- this.hmrPageMetadataCache = rendererConfig.hmrPageMetadataCache ?? new HmrPageMetadataCache();
90
- this.clientGraphBoundaryCache = new ClientGraphBoundaryCache();
91
- this.forceBrowserGraph = rendererConfig.forceBrowserGraph ?? false;
92
- this.rendererConfig = {
93
- ...rendererConfig,
94
- mdxExtensions: this.mdxExtensions,
95
- hmrPageMetadataCache: this.hmrPageMetadataCache,
96
- forceBrowserGraph: this.forceBrowserGraph
31
+ const { extensions: userExtensions, router, mdx, explicitGraph, dependencies, runtimeModules, ...baseConfig } = options ?? {};
32
+ const extensions = [...(userExtensions ?? ['.tsx'])];
33
+ const mdxEnabled = mdx?.enabled ?? false;
34
+ const mdxExtensions = mdx?.extensions ?? ['.mdx'];
35
+ const resolvedRuntimeModules = resolveReactPluginRuntimeModules(runtimeModules);
36
+ if (mdxEnabled) {
37
+ appendMdxExtensions(extensions, mdxExtensions);
38
+ }
39
+ else if (mdx?.extensions?.length) {
40
+ appLogger.warn('MDX extensions provided but MDX is disabled. MDX files will not be processed. Set mdx.enabled to true to enable MDX support.');
41
+ }
42
+ const rendererConfig = {
43
+ routerAdapter: router,
44
+ runtimeModules: resolvedRuntimeModules,
45
+ mdxCompilerOptions: mdxEnabled && mdx ? resolveReactMdxCompilerOptions(mdx) : undefined,
46
+ mdxExtensions,
47
+ hmrPageMetadataCache: new HmrPageMetadataCache(),
48
+ forceBrowserGraph: explicitGraph ?? false,
49
+ };
50
+ return {
51
+ ...baseConfig,
52
+ extensions,
53
+ integrationDependencies: dependencies,
54
+ rendererConfig,
97
55
  };
98
- if (this.mdxEnabled) {
99
- appLogger.debug("MDX mode enabled with React jsx runtime");
56
+ };
57
+ /**
58
+ * The React plugin class
59
+ * This plugin provides support for React components in Ecopages
60
+ */
61
+ export class ReactPlugin extends IntegrationPlugin {
62
+ renderer = ReactRenderer;
63
+ routerAdapter;
64
+ mdxEnabled;
65
+ mdxCompilerOptions;
66
+ mdxExtensions;
67
+ mdxLoaderPlugin;
68
+ runtimeBundleService;
69
+ hmrPageMetadataCache;
70
+ clientGraphBoundaryCache;
71
+ hmrStrategy;
72
+ runtimeDependenciesInitialized = false;
73
+ /**
74
+ * When true, always emit page browser graph / hydration assets.
75
+ *
76
+ * @remarks
77
+ * Mapped from public `explicitGraph`. Does not skip client-graph AST stripping.
78
+ */
79
+ forceBrowserGraph;
80
+ rendererConfig;
81
+ constructor(options) {
82
+ const config = resolveReactPluginOptions(options);
83
+ const { extensions, rendererConfig, integrationDependencies, ...baseConfig } = config;
84
+ super({
85
+ name: PLUGIN_NAME,
86
+ extensions,
87
+ jsxImportSource: 'react',
88
+ integrationDependencies,
89
+ ...baseConfig,
90
+ });
91
+ this.routerAdapter = rendererConfig.routerAdapter;
92
+ this.mdxCompilerOptions = rendererConfig.mdxCompilerOptions;
93
+ this.mdxEnabled = Boolean(rendererConfig.mdxCompilerOptions);
94
+ this.mdxExtensions = rendererConfig.mdxExtensions ?? ['.mdx'];
95
+ this.hmrPageMetadataCache = rendererConfig.hmrPageMetadataCache ?? new HmrPageMetadataCache();
96
+ this.clientGraphBoundaryCache = new ClientGraphBoundaryCache();
97
+ this.forceBrowserGraph = rendererConfig.forceBrowserGraph ?? false;
98
+ this.rendererConfig = {
99
+ ...rendererConfig,
100
+ mdxExtensions: this.mdxExtensions,
101
+ hmrPageMetadataCache: this.hmrPageMetadataCache,
102
+ forceBrowserGraph: this.forceBrowserGraph,
103
+ };
104
+ if (this.mdxEnabled) {
105
+ appLogger.debug('MDX mode enabled with React jsx runtime');
106
+ }
107
+ this.runtimeBundleService = new RuntimeBundleService({
108
+ routerAdapter: this.routerAdapter,
109
+ runtimeModules: this.rendererConfig.runtimeModules,
110
+ });
111
+ }
112
+ /**
113
+ * Creates a React renderer with instance-owned runtime configuration.
114
+ *
115
+ * React renderers depend on plugin-owned router, MDX, and HMR metadata state.
116
+ * Keeping that state on the instance avoids cross-plugin static mutation while
117
+ * preserving the same runtime services the base initializer wires up.
118
+ */
119
+ initializeRenderer(options) {
120
+ const renderer = new this.renderer({
121
+ ...this.createRendererOptions(options),
122
+ reactConfig: this.rendererConfig,
123
+ });
124
+ return this.attachRendererRuntimeServices(renderer);
100
125
  }
101
- this.runtimeBundleService = new RuntimeBundleService({
102
- routerAdapter: this.routerAdapter,
103
- runtimeModules: this.rendererConfig.runtimeModules
104
- });
105
- }
106
- /**
107
- * Creates a React renderer with instance-owned runtime configuration.
108
- *
109
- * React renderers depend on plugin-owned router, MDX, and HMR metadata state.
110
- * Keeping that state on the instance avoids cross-plugin static mutation while
111
- * preserving the same runtime services the base initializer wires up.
112
- */
113
- initializeRenderer(options) {
114
- const renderer = new this.renderer({
115
- ...this.createRendererOptions(options),
116
- reactConfig: this.rendererConfig
117
- });
118
- return this.attachRendererRuntimeServices(renderer);
119
- }
120
- ensureRuntimeDependencies() {
121
- if (this.runtimeDependenciesInitialized) {
122
- return;
126
+ ensureRuntimeDependencies() {
127
+ if (this.runtimeDependenciesInitialized) {
128
+ return;
129
+ }
130
+ this.runtimeBundleService.setRootDir(this.appConfig?.rootDir);
131
+ this.runtimeBundleService.setWorkDir(this.appConfig?.absolutePaths?.workDir ??
132
+ (this.appConfig?.rootDir
133
+ ? path.join(this.appConfig.rootDir, this.appConfig.workDir ?? '.eco')
134
+ : undefined));
135
+ this.runtimeBundleService.setRuntimeModules(this.resolveEffectiveRuntimeModules());
136
+ this.integrationDependencies.unshift(...this.runtimeBundleService.getDependencies());
137
+ this.runtimeDependenciesInitialized = true;
123
138
  }
124
- this.runtimeBundleService.setRootDir(this.appConfig?.rootDir);
125
- this.runtimeBundleService.setWorkDir(
126
- this.appConfig?.absolutePaths?.workDir ?? (this.appConfig?.rootDir ? path.join(this.appConfig.rootDir, this.appConfig.workDir ?? ".eco") : void 0)
127
- );
128
- this.runtimeBundleService.setRuntimeModules(this.resolveEffectiveRuntimeModules());
129
- this.integrationDependencies.unshift(...this.runtimeBundleService.getDependencies());
130
- this.runtimeDependenciesInitialized = true;
131
- }
132
- resolveEffectiveRuntimeModules() {
133
- const manualModules = this.rendererConfig.runtimeModules ?? [];
134
- if (!this.routerAdapter || !this.appConfig) {
135
- return manualModules;
139
+ resolveEffectiveRuntimeModules() {
140
+ const manualModules = this.rendererConfig.runtimeModules ?? [];
141
+ if (!this.routerAdapter || !this.appConfig) {
142
+ return manualModules;
143
+ }
144
+ const discovery = discoverLayoutRuntimeModuleSpecifiers({
145
+ searchDirs: [this.appConfig.absolutePaths.layoutsDir, this.appConfig.absolutePaths.componentsDir].filter(Boolean),
146
+ projectRoot: this.appConfig.absolutePaths.projectDir,
147
+ routerImportPath: this.routerAdapter.bundle.importPath,
148
+ });
149
+ const merged = mergeReactPluginRuntimeModules(manualModules, discovery.specifiers);
150
+ this.rendererConfig.runtimeModules = merged;
151
+ if (discovery.mode === 'provider-scoped-fallback') {
152
+ appLogger.debug('Layout runtime auto-vendoring is using provider-scoped fallback discovery. Set runtimeProvider: true on provider root layouts to scope discovery explicitly.');
153
+ }
154
+ if (discovery.specifiers.length > 0) {
155
+ appLogger.debug(`Auto-vendoring layout runtime modules for persisted SPA layouts: ${discovery.specifiers.join(', ')}`);
156
+ }
157
+ return merged;
136
158
  }
137
- const discovery = discoverLayoutRuntimeModuleSpecifiers({
138
- searchDirs: [this.appConfig.absolutePaths.layoutsDir, this.appConfig.absolutePaths.componentsDir].filter(
139
- Boolean
140
- ),
141
- projectRoot: this.appConfig.absolutePaths.projectDir,
142
- routerImportPath: this.routerAdapter.bundle.importPath
143
- });
144
- const merged = mergeReactPluginRuntimeModules(manualModules, discovery.specifiers);
145
- this.rendererConfig.runtimeModules = merged;
146
- if (discovery.mode === "provider-scoped-fallback") {
147
- appLogger.debug(
148
- "Layout runtime auto-vendoring is using provider-scoped fallback discovery. Set runtimeProvider: true on provider root layouts to scope discovery explicitly."
149
- );
159
+ get plugins() {
160
+ if (this.mdxLoaderPlugin) {
161
+ return [this.mdxLoaderPlugin];
162
+ }
163
+ return [];
150
164
  }
151
- if (discovery.specifiers.length > 0) {
152
- appLogger.debug(
153
- `Auto-vendoring layout runtime modules for persisted SPA layouts: ${discovery.specifiers.join(", ")}`
154
- );
165
+ get browserRuntimeManifest() {
166
+ this.ensureRuntimeDependencies();
167
+ return this.runtimeBundleService.getRuntimeManifest();
155
168
  }
156
- return merged;
157
- }
158
- get plugins() {
159
- if (this.mdxLoaderPlugin) {
160
- return [this.mdxLoaderPlugin];
169
+ /**
170
+ * Ensures the optional React MDX loader exists before either config-time
171
+ * manifest sealing or runtime setup needs it.
172
+ */
173
+ async ensureMdxLoaderPlugin() {
174
+ if (!this.mdxEnabled || !this.mdxCompilerOptions || this.mdxLoaderPlugin) {
175
+ return;
176
+ }
177
+ this.mdxLoaderPlugin = createReactMdxLoaderPlugin(this.mdxCompilerOptions);
161
178
  }
162
- return [];
163
- }
164
- get browserRuntimeManifest() {
165
- this.ensureRuntimeDependencies();
166
- return this.runtimeBundleService.getRuntimeManifest();
167
- }
168
- /**
169
- * Ensures the optional React MDX loader exists before either config-time
170
- * manifest sealing or runtime setup needs it.
171
- */
172
- async ensureMdxLoaderPlugin() {
173
- if (!this.mdxEnabled || !this.mdxCompilerOptions || this.mdxLoaderPlugin) {
174
- return;
179
+ /**
180
+ * Prepares React's build-facing loader contributions before config build seals
181
+ * the app manifest.
182
+ */
183
+ async prepareBuildContributions() {
184
+ this.ensureRuntimeDependencies();
185
+ await this.ensureMdxLoaderPlugin();
175
186
  }
176
- this.mdxLoaderPlugin = createReactMdxLoaderPlugin(this.mdxCompilerOptions);
177
- }
178
- /**
179
- * Prepares React's build-facing loader contributions before config build seals
180
- * the app manifest.
181
- */
182
- async prepareBuildContributions() {
183
- this.ensureRuntimeDependencies();
184
- await this.ensureMdxLoaderPlugin();
185
- }
186
- /**
187
- * Performs runtime-only React setup after build contributions are already
188
- * materialized.
189
- */
190
- async setup() {
191
- this.ensureRuntimeDependencies();
192
- await this.ensureMdxLoaderPlugin();
193
- await super.setup();
194
- }
195
- /**
196
- * Provides React-specific HMR strategy with Fast Refresh support.
197
- *
198
- * The strategy shares a React-only page metadata cache with the renderer so
199
- * save-time rebuilds can reuse declared-module analysis without expanding the
200
- * core HMR interfaces.
201
- *
202
- * @returns ReactHmrStrategy instance for handling React component updates
203
- */
204
- getHmrStrategy() {
205
- if (!this.hmrManager || !this.appConfig) {
206
- return void 0;
187
+ /**
188
+ * Performs runtime-only React setup after build contributions are already
189
+ * materialized.
190
+ */
191
+ async setup() {
192
+ this.ensureRuntimeDependencies();
193
+ await this.ensureMdxLoaderPlugin();
194
+ await super.setup();
207
195
  }
208
- if (!this.hmrStrategy) {
209
- this.hmrStrategy = new ReactHmrStrategy({
210
- context: this.hmrManager.getDefaultContext(),
211
- pageMetadataCache: this.hmrPageMetadataCache,
212
- runtimeManifest: this.runtimeBundleService.getRuntimeManifest("development"),
213
- mdxCompilerOptions: this.mdxCompilerOptions,
214
- ownedTemplateExtensions: this.extensions,
215
- allTemplateExtensions: this.appConfig.templatesExt,
216
- clientGraphBoundaryCache: this.clientGraphBoundaryCache
217
- });
196
+ /**
197
+ * Provides React-specific HMR strategy with Fast Refresh support.
198
+ *
199
+ * The strategy shares a React-only page metadata cache with the renderer so
200
+ * save-time rebuilds can reuse declared-module analysis without expanding the
201
+ * core HMR interfaces.
202
+ *
203
+ * @returns ReactHmrStrategy instance for handling React component updates
204
+ */
205
+ setHmrManager(hmrManager) {
206
+ super.setHmrManager(hmrManager);
207
+ const strategy = this.getHmrStrategy();
208
+ if (!strategy || !this.appConfig) {
209
+ return;
210
+ }
211
+ hmrManager.registerDevTransformContributor(new ReactDevTransformContributor({
212
+ strategy: strategy,
213
+ }));
214
+ }
215
+ getHmrStrategy() {
216
+ if (!this.hmrManager || !this.appConfig) {
217
+ return undefined;
218
+ }
219
+ if (!this.hmrStrategy) {
220
+ this.hmrStrategy = new ReactHmrStrategy({
221
+ context: this.hmrManager.getDefaultContext(),
222
+ pageMetadataCache: this.hmrPageMetadataCache,
223
+ runtimeManifest: this.runtimeBundleService.getRuntimeManifest('development'),
224
+ mdxCompilerOptions: this.mdxCompilerOptions,
225
+ ownedTemplateExtensions: this.extensions,
226
+ allTemplateExtensions: this.appConfig.templatesExt,
227
+ clientGraphBoundaryCache: this.clientGraphBoundaryCache,
228
+ });
229
+ }
230
+ return this.hmrStrategy;
218
231
  }
219
- return this.hmrStrategy;
220
- }
221
232
  }
222
- function reactPlugin(options) {
223
- return new ReactPlugin(options);
233
+ /**
234
+ * Factory function to create a React plugin instance
235
+ * @param options Configuration options for the React plugin
236
+ * @returns A new ReactPlugin instance
237
+ */
238
+ export function reactPlugin(options) {
239
+ return new ReactPlugin(options);
224
240
  }
225
- export {
226
- PLUGIN_NAME,
227
- ReactPlugin,
228
- reactPlugin
229
- };
@@ -0,0 +1 @@
1
+ export {};