@ecopages/react 0.2.0-alpha.5 → 0.2.0-alpha.7

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 (41) hide show
  1. package/CHANGELOG.md +22 -41
  2. package/README.md +135 -29
  3. package/package.json +3 -3
  4. package/src/react-hmr-strategy.d.ts +22 -30
  5. package/src/react-hmr-strategy.js +57 -120
  6. package/src/react-hmr-strategy.ts +76 -145
  7. package/src/react-renderer.d.ts +130 -11
  8. package/src/react-renderer.js +368 -64
  9. package/src/react-renderer.ts +490 -90
  10. package/src/react.plugin.d.ts +17 -5
  11. package/src/react.plugin.js +44 -13
  12. package/src/react.plugin.ts +49 -14
  13. package/src/router-adapter.d.ts +2 -2
  14. package/src/router-adapter.ts +2 -2
  15. package/src/services/react-bundle.service.d.ts +2 -30
  16. package/src/services/react-bundle.service.js +19 -94
  17. package/src/services/react-bundle.service.ts +20 -129
  18. package/src/services/react-hydration-asset.service.js +3 -3
  19. package/src/services/react-hydration-asset.service.ts +7 -4
  20. package/src/services/react-page-module.service.d.ts +3 -0
  21. package/src/services/react-page-module.service.js +20 -16
  22. package/src/services/react-page-module.service.ts +27 -17
  23. package/src/services/react-runtime-bundle.service.d.ts +12 -12
  24. package/src/services/react-runtime-bundle.service.js +98 -180
  25. package/src/services/react-runtime-bundle.service.ts +112 -211
  26. package/src/utils/client-graph-boundary-plugin.js +78 -1
  27. package/src/utils/client-graph-boundary-plugin.ts +122 -1
  28. package/src/utils/hydration-scripts.d.ts +18 -1
  29. package/src/utils/hydration-scripts.js +83 -32
  30. package/src/utils/hydration-scripts.ts +159 -38
  31. package/src/utils/react-dom-runtime-interop-plugin.d.ts +5 -0
  32. package/src/utils/react-dom-runtime-interop-plugin.js +29 -0
  33. package/src/utils/react-dom-runtime-interop-plugin.ts +33 -0
  34. package/src/utils/react-mdx-loader-plugin.js +13 -5
  35. package/src/utils/react-mdx-loader-plugin.ts +28 -5
  36. package/src/utils/react-runtime-specifier-map.d.ts +6 -0
  37. package/src/utils/react-runtime-specifier-map.js +37 -0
  38. package/src/utils/react-runtime-specifier-map.ts +45 -0
  39. package/src/utils/use-sync-external-store-shim-plugin.d.ts +5 -0
  40. package/src/utils/use-sync-external-store-shim-plugin.js +41 -0
  41. package/src/utils/use-sync-external-store-shim-plugin.ts +45 -0
@@ -12,6 +12,11 @@ import { ReactBundleService } from './services/react-bundle.service.js';
12
12
  import { ReactHmrPageMetadataCache } from './services/react-hmr-page-metadata-cache.js';
13
13
  import { ReactPageModuleService } from './services/react-page-module.service.js';
14
14
  import { ReactHydrationAssetService } from './services/react-hydration-asset.service.js';
15
+ type ReactPageModule = EcoPageFile<{
16
+ config?: EcoComponentConfig;
17
+ }> & {
18
+ config?: EcoComponentConfig;
19
+ };
15
20
  /**
16
21
  * Error thrown when an error occurs while rendering a React component.
17
22
  */
@@ -32,7 +37,6 @@ export declare class BundleError extends Error {
32
37
  export declare class ReactRenderer extends IntegrationRenderer<ReactNode> {
33
38
  name: string;
34
39
  componentDirectory: string;
35
- private componentRenderSequence;
36
40
  static routerAdapter: ReactRouterAdapter | undefined;
37
41
  static mdxCompilerOptions: CompileOptions | undefined;
38
42
  static mdxExtensions: string[];
@@ -57,14 +61,101 @@ export declare class ReactRenderer extends IntegrationRenderer<ReactNode> {
57
61
  runtimeOrigin: string;
58
62
  });
59
63
  protected shouldRenderPageComponent(): boolean;
64
+ /**
65
+ * Reads the declared integration name for a component or layout.
66
+ *
67
+ * We honor both the explicit `config.integration` override and injected
68
+ * `config.__eco.integration` metadata because pages can arrive here through
69
+ * authored config as well as build-time component metadata.
70
+ */
71
+ private getComponentIntegration;
72
+ /**
73
+ * Returns whether a component should stay inside the React render lane.
74
+ *
75
+ * Components without explicit integration metadata are treated as React-owned
76
+ * here because this renderer only receives them after the route pipeline has
77
+ * already selected the React integration.
78
+ */
79
+ private isReactManagedComponent;
80
+ /**
81
+ * Creates the canonical page-props payload used by router hydration.
82
+ *
83
+ * React pages embedded in a non-React HTML shell still need to expose the same
84
+ * page-data contract as fully React-owned documents so navigation and hydration
85
+ * can read one marker consistently.
86
+ */
87
+ private buildRouterPageDataScript;
88
+ private getRouterDocumentAttributes;
89
+ /**
90
+ * Commits a framework-agnostic component to React semantics.
91
+ *
92
+ * This is one of the two real cast boundaries in this file. Core keeps
93
+ * `EcoComponent` broad so integrations can share the same public surface; once
94
+ * the React renderer is executing, `createElement()` needs a concrete React
95
+ * component signature.
96
+ */
97
+ private asReactComponent;
98
+ /**
99
+ * Commits a mixed-shell component to the string-returning contract required by
100
+ * non-React layouts and HTML templates.
101
+ *
102
+ * This is the second real cast boundary: once we decide a shell is not managed
103
+ * by React, we call it directly and require serialized HTML back.
104
+ */
105
+ private asNonReactShellComponent;
106
+ /**
107
+ * Builds the serialized page-props payload embedded into the final HTML.
108
+ *
109
+ * The document payload is intentionally narrower than the full server render
110
+ * input: only routing data, public page props, and explicitly allowed locals are
111
+ * exposed to the browser.
112
+ */
113
+ private buildSerializedPageProps;
114
+ /**
115
+ * Appends route hydration assets for a concrete page/view file to the current
116
+ * HTML transformer state.
117
+ */
118
+ private appendHydrationAssetsForFile;
119
+ /**
120
+ * Resolves metadata for direct `renderToResponse()` calls.
121
+ *
122
+ * View rendering bypasses the normal route-file pipeline, so metadata has to be
123
+ * evaluated here from either the component-level generator or the application
124
+ * default.
125
+ */
126
+ private resolveViewMetadata;
127
+ /**
128
+ * Renders a non-React layout or HTML template and enforces that mixed shells
129
+ * return serialized HTML.
130
+ *
131
+ * The React renderer can compose through another integration's shell, but only
132
+ * if that shell yields a string that can be inserted into the final document.
133
+ */
134
+ private renderNonReactShellComponent;
135
+ /**
136
+ * Produces the page body before the final HTML template is applied.
137
+ *
138
+ * This method owns the React/non-React layout split. React-managed layouts stay
139
+ * as React elements so they can stream normally; non-React layouts are rendered
140
+ * to HTML first and then passed through as serialized content.
141
+ */
142
+ private composePageContent;
143
+ /**
144
+ * Wraps composed page content in the final document template.
145
+ *
146
+ * React-owned HTML templates stream directly. Non-React templates receive
147
+ * pre-rendered page HTML plus the canonical React page-data payload so the
148
+ * client runtime can recover page data after cross-integration handoff.
149
+ */
150
+ private renderDocument;
60
151
  /**
61
152
  * Renders a React component for component-level orchestration.
62
153
  *
63
154
  * Behavior:
64
155
  * - SSR always returns the component's own root HTML (no synthetic wrapper).
65
- * - For single-root output, a stable `data-eco-component-id` attribute is attached
66
- * to the root element so the client island runtime can target it directly.
67
- * - Island client scripts are emitted through `assets` and mounted independently.
156
+ * - When an explicit component instance id is provided, a stable
157
+ * `data-eco-component-id` attribute is attached so island hydration can target it.
158
+ * - Without an explicit instance id, component renders remain plain SSR output.
68
159
  *
69
160
  * This preserves DOM shape for global CSS/layout selectors while keeping a
70
161
  * deterministic mount target per component instance.
@@ -82,25 +173,53 @@ export declare class ReactRenderer extends IntegrationRenderer<ReactNode> {
82
173
  * @returns Processed assets for MDX configuration dependencies
83
174
  */
84
175
  private processMdxConfigDependencies;
176
+ private processDeclaredMdxSsrLazyDependencies;
177
+ private collectDeclaredMdxSsrLazyDependencies;
85
178
  buildRouteRenderAssets(pagePath: string): Promise<ProcessedAsset[]>;
86
- protected importPageFile(file: string): Promise<EcoPageFile<{
87
- config?: EcoComponentConfig;
88
- }>>;
179
+ /**
180
+ * Imports a page module while normalizing React MDX modules to the same shape
181
+ * as ordinary React page files.
182
+ *
183
+ * MDX page imports can expose `config` separately from the default export. The
184
+ * React renderer reattaches that config to the page component so downstream
185
+ * layout, dependency, and hydration logic can treat MDX and TSX pages the same.
186
+ */
187
+ protected importPageFile(file: string): Promise<ReactPageModule>;
188
+ /**
189
+ * Renders a full route response for the filesystem page pipeline.
190
+ *
191
+ * This path receives already-resolved route metadata, layout, locals, and HTML
192
+ * template instances from the shared renderer orchestration. Its main job is to
193
+ * serialize only the browser-safe page payload, compose the mixed React/non-
194
+ * React shell tree, and hand the result back as a document body.
195
+ */
89
196
  render({ params, query, props, locals, pageLocals, metadata, Page, Layout, HtmlTemplate, pageProps, }: IntegrationRendererRenderOptions<ReactNode>): Promise<RouteRendererBody>;
197
+ protected getDocumentAttributes(): Record<string, string> | undefined;
90
198
  /**
91
- * Safely extracts locals for client-side hydration.
199
+ * Safely extracts the declared subset of locals for client-side hydration.
92
200
  *
93
201
  * On dynamic pages with `cache: 'dynamic'`, middleware populates `locals` with
94
- * request-scoped data (e.g., session). This data needs to be serialized to the
95
- * client for hydration to match the server-rendered output.
202
+ * request-scoped data (e.g., session). Only keys explicitly declared via
203
+ * `Page.requires` are serialized to the client so sensitive request-only data
204
+ * is not leaked into hydration payloads by default.
96
205
  *
97
206
  * On static pages, `locals` is a Proxy that throws `LocalsAccessError` on access
98
207
  * to prevent accidental use. This method safely detects that case and returns
99
208
  * `undefined` instead of throwing.
100
209
  *
101
210
  * @param locals - The locals object from the render context
102
- * @returns The locals object if serializable, undefined otherwise
211
+ * @param requiredLocals - Keys explicitly requested for client hydration
212
+ * @returns The filtered locals object if serializable, undefined otherwise
103
213
  */
104
214
  private getSerializableLocals;
215
+ /**
216
+ * Renders an arbitrary React view through the application's HTML shell.
217
+ *
218
+ * Unlike route rendering, this path starts from a single component rather than a
219
+ * page module discovered by the router. It still needs to resolve metadata,
220
+ * layout dependencies, and hydration assets so direct `ctx.render()` calls match
221
+ * normal page responses.
222
+ */
105
223
  renderToResponse<P = Record<string, unknown>>(view: EcoComponent<P>, props: P, ctx: RenderToResponseContext): Promise<Response>;
106
224
  }
225
+ export {};