@ecopages/react 0.2.0-beta.27 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/react",
3
- "version": "0.2.0-beta.27",
3
+ "version": "0.2.0-beta.28",
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.27",
96
+ "@ecopages/core": "0.2.0-beta.28",
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.27",
103
+ "@ecopages/file-system": "0.2.0-beta.28",
104
104
  "@ecopages/logger": "^0.2.3",
105
- "@ecopages/mdx": "0.2.0-beta.27",
105
+ "@ecopages/mdx": "0.2.0-beta.28",
106
106
  "@mdx-js/mdx": "^3.1.1",
107
107
  "oxc-parser": "^0.124.0",
108
108
  "oxc-transform": "^0.124.0",
@@ -56,10 +56,15 @@ class HydrationAssetService {
56
56
  isMdx
57
57
  } = options;
58
58
  const runtimeImports = this.config.bundleService.getRuntimeImports();
59
- const groupedBundle = this.config.routerAdapter ? {
59
+ const groupedBundle = !hmrEnabled && this.config.routerAdapter ? {
60
60
  id: HydrationAssetService.ROUTER_PAGE_GROUPED_BUNDLE_ID,
61
61
  entryName: this.getRouterPageGroupedEntryName(pagePath)
62
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;
63
68
  return [
64
69
  AssetFactory.createContentScript({
65
70
  position: "head",
@@ -76,9 +81,16 @@ class HydrationAssetService {
76
81
  }),
77
82
  name: componentName,
78
83
  packageRole: "page-script",
79
- bundle: !hmrEnabled,
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,
80
92
  groupedBundle,
81
- bundleOptions,
93
+ bundleOptions: pageBootstrapBundleOptions,
82
94
  attributes: {
83
95
  type: "module",
84
96
  defer: "",
@@ -24,8 +24,9 @@ export type HydrationScriptOptions = {
24
24
  * When true, emit HMR registration and hot-reload handlers.
25
25
  *
26
26
  * @remarks
27
- * The asset layer uses the same flag to leave HMR entries unbundled. When
28
- * false, this generator emits the same readable bootstrap without HMR hooks.
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.
29
30
  */
30
31
  hmrEnabled: boolean;
31
32
  /** Whether the source file is an MDX file */
@@ -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
- this.mergePageBrowserGraphIntoPagePackage(pageBrowserGraph);
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.resolveQueuedForeignSubtreeHtml(
143
+ return this.foreignSubtreeExecutionService.resolveQueuedHtml({
144
+ currentIntegrationName: this.name,
119
145
  html,
120
146
  runtimeContext,
121
- (children, currentRuntimeContext, queuedResolutionsByToken, resolveToken) => renderReactQueuedForeignSubtreeChildren({
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
- "React"
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.getQueuedForeignSubtreeResolutionContext(input);
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.createQueuedForeignSubtreeExecutionRuntime({
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.getQueuedForeignSubtreeResolutionContext(input),
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
- const html = await this.finalizeResolvedHtml({
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';