@ecopages/react 0.8.0 → 0.10.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/README.md +17 -27
- package/package.json +4 -4
- package/src/bundling/bundle.d.ts +6 -0
- package/src/bundling/bundle.js +23 -9
- package/src/client-graph/ast-transform-eco-page.d.ts +14 -1
- package/src/client-graph/ast-transform-eco-page.js +60 -13
- package/src/client-graph/ast-transform-stripped-imports.js +1 -1
- package/src/client-graph/ast-transform-walk-imports.d.ts +0 -1
- package/src/client-graph/ast-transform-walk-imports.js +5 -10
- package/src/client-graph/ast-transform.d.ts +1 -1
- package/src/client-graph/ast-transform.js +1 -2
- package/src/client-graph/boundary-plugin-transform.d.ts +0 -1
- package/src/client-graph/boundary-plugin-transform.js +1 -2
- package/src/client-graph/boundary-plugin.d.ts +19 -0
- package/src/client-graph/boundary-plugin.js +54 -16
- package/src/client-graph/foreign-boundary-rewrite.d.ts +18 -3
- package/src/client-graph/foreign-boundary-rewrite.js +199 -48
- package/src/client-graph/foreign-jsx-reach.d.ts +21 -2
- package/src/client-graph/foreign-jsx-reach.js +56 -14
- package/src/client-graph/foreign-module.d.ts +45 -0
- package/src/client-graph/foreign-module.js +132 -0
- package/src/client-graph/module-classification.d.ts +0 -1
- package/src/client-graph/module-classification.js +0 -4
- package/src/client-graph/reachability-analyzer.d.ts +0 -1
- package/src/client-graph/reachability-analyzer.js +0 -5
- package/src/client-graph/reachability-client-roots.js +28 -0
- package/src/client-graph/requested-exports-plan.d.ts +1 -1
- package/src/client-graph/requested-exports-plan.js +1 -1
- package/src/client-graph/specifier-classification.js +2 -2
- package/src/hmr/hmr-strategy.d.ts +5 -2
- package/src/hmr/hmr-strategy.js +12 -5
- package/src/hydration/browser/foreign-boundary.d.ts +12 -0
- package/src/hydration/browser/foreign-boundary.js +19 -0
- package/src/hydration/browser/page-hydration-hmr.d.ts +1 -0
- package/src/hydration/browser/page-hydration-hmr.js +2 -2
- package/src/hydration/browser/page-hydration.d.ts +2 -1
- package/src/hydration/browser/page-hydration.js +3 -2
- package/src/hydration/hydration-page-entry-source.js +3 -3
- package/src/hydration/page-data-manifest.d.ts +22 -1
- package/src/hydration/page-data-manifest.js +38 -3
- package/src/hydration/page-data-reader.d.ts +2 -1
- package/src/hydration/page-data-reader.js +4 -2
- package/src/hydration/page-payload.d.ts +6 -15
- package/src/hydration/page-payload.js +5 -42
- package/src/hydration/serialize-page-data-script.d.ts +4 -4
- package/src/hydration/serialize-page-data-script.js +6 -6
- package/src/page/page-module.d.ts +4 -2
- package/src/page/page-module.js +8 -23
- package/src/plugin/react.plugin.js +2 -0
- package/src/render/component-ownership.d.ts +1 -6
- package/src/render/component-ownership.js +0 -3
- package/src/render/component-ssr.d.ts +0 -1
- package/src/render/component-ssr.js +0 -7
- package/src/render/layout-compose.d.ts +16 -8
- package/src/render/layout-compose.js +13 -36
- package/src/render/react-renderer.js +37 -55
|
@@ -12,8 +12,7 @@ import { AsyncLocalStorage } from 'node:async_hooks';
|
|
|
12
12
|
import { buildIslandHostAttributes, getComponentIdentity } from '@ecopages/core';
|
|
13
13
|
import { createIntegrationRenderer, selectHydrationIslandEntries, } from '@ecopages/core/integration';
|
|
14
14
|
import { ECO_DOCUMENT_OWNER_ATTRIBUTE } from '@ecopages/core/client';
|
|
15
|
-
import {
|
|
16
|
-
import { ensurePageConfigLayouts, moveMdxMetadataOntoPage } from '@ecopages/core/integration';
|
|
15
|
+
import { ensurePageConfigLayouts, moveMdxMetadataOntoPage, resolveRenderLayouts } from '@ecopages/core/integration';
|
|
17
16
|
import { hasSingleRootElement } from './html-boundary.js';
|
|
18
17
|
import { toRootRelativePath } from '@ecopages/core/build';
|
|
19
18
|
import { getIslandComponentKey } from '../hydration/hydration-asset.js';
|
|
@@ -25,12 +24,12 @@ import { PageModuleService } from '../page/page-module.js';
|
|
|
25
24
|
import { PagePayloadService } from '../hydration/page-payload.js';
|
|
26
25
|
import { HydrationAssetService } from '../hydration/hydration-asset.js';
|
|
27
26
|
import {} from '@ecopages/core/integration';
|
|
28
|
-
import { asNonReactShellComponent,
|
|
29
|
-
import {
|
|
27
|
+
import { asNonReactShellComponent, isReactManagedComponent } from './component-ownership.js';
|
|
28
|
+
import { renderComponentHtml, renderNonReactShellComponent, restoreRuntimeChildHtml, replaceForeignSubtreeTokens, toReactNode, wrapForeignSubtreeTokens, } from './component-ssr.js';
|
|
30
29
|
import { BundleError, ReactRenderError } from './errors.js';
|
|
31
30
|
import { renderReactHtml, resolveReactRuntimeModules, runWithRenderBudget, } from './react-runtime.js';
|
|
32
31
|
import { composeReactLayoutPageTree, shouldUseUnifiedReactLayoutComposition } from './unified-layout-composition.js';
|
|
33
|
-
import { assertComposablePage
|
|
32
|
+
import { assertComposablePage } from './layout-compose.js';
|
|
34
33
|
import { LayoutRenderTracker } from './layout-render-tracker.js';
|
|
35
34
|
export { BundleError, ReactRenderError } from './errors.js';
|
|
36
35
|
const ReactIntegrationRenderer = createIntegrationRenderer(REACT_PLUGIN_NAME);
|
|
@@ -60,7 +59,7 @@ export class ReactRenderer extends ReactIntegrationRenderer {
|
|
|
60
59
|
this.hookTargets.buildIslandClientAssets = (plan) => this.buildPageClientBrowserAssetsHook(plan);
|
|
61
60
|
this.hookTargets.collectAppBrowserClientBuildEntries = (plan) => this.collectAppBrowserClientBuildEntriesHook(plan);
|
|
62
61
|
this.hookTargets.renderComponent = (input) => this.renderComponentHook(input);
|
|
63
|
-
this.hookTargets.renderQueuedChildren = (children, runtimeContext,
|
|
62
|
+
this.hookTargets.renderQueuedChildren = (children, runtimeContext, resolveTokens) => this.renderQueuedChildrenHook(children, runtimeContext, resolveTokens);
|
|
64
63
|
this.hookTargets.normalizePageModule = (file, module) => this.normalizeImportedPageFileHook(file, module);
|
|
65
64
|
this.hookTargets.collectPageBrowserGraphContribution = (context) => this.collectPageBrowserGraphContributionHook(context);
|
|
66
65
|
this.hookTargets.composeChildren = ({ page, layouts, foreignChildRoots }) => this.resolveComposeChildren({ page, shellLayouts: layouts, foreignChildRoots });
|
|
@@ -167,36 +166,43 @@ export class ReactRenderer extends ReactIntegrationRenderer {
|
|
|
167
166
|
* Resolves the Foreign Subtree tokens in `html`, wrapping them in the hydration boundary only when `hydrates`.
|
|
168
167
|
*/
|
|
169
168
|
resolveReactQueuedForeignSubtreeHtml(html, runtimeContext, hydrates) {
|
|
170
|
-
return this.resolveQueuedForeignSubtrees(hydrates ? wrapForeignSubtreeTokens(html, runtimeContext) : html, runtimeContext, async (children, currentRuntimeContext,
|
|
169
|
+
return this.resolveQueuedForeignSubtrees(hydrates ? wrapForeignSubtreeTokens(html, runtimeContext) : html, runtimeContext, async (children, currentRuntimeContext, resolveTokens) => ({
|
|
171
170
|
html: await this.renderQueuedChildrenToHtml({
|
|
172
171
|
children,
|
|
173
172
|
runtimeContext: currentRuntimeContext,
|
|
174
|
-
|
|
175
|
-
resolveToken,
|
|
173
|
+
resolveTokens,
|
|
176
174
|
}),
|
|
177
175
|
}));
|
|
178
176
|
}
|
|
179
177
|
async renderQueuedChildrenToHtml(options) {
|
|
180
|
-
const { children, runtimeContext,
|
|
178
|
+
const { children, runtimeContext, resolveTokens } = options;
|
|
181
179
|
if (children === undefined) {
|
|
182
180
|
return undefined;
|
|
183
181
|
}
|
|
184
182
|
const runtime = this.getReactRuntimeModules();
|
|
185
|
-
let html =
|
|
183
|
+
let html = await this.renderReactTree(runtime.react.createElement(runtime.react.Fragment, null, toReactNode(children, this.name)), 'queued children');
|
|
186
184
|
html = restoreRuntimeChildHtml(html, runtimeContext);
|
|
187
|
-
return await
|
|
188
|
-
}
|
|
189
|
-
buildPagePayload(
|
|
190
|
-
const
|
|
185
|
+
return await resolveTokens(html);
|
|
186
|
+
}
|
|
187
|
+
buildPagePayload(renderOptions) {
|
|
188
|
+
const layoutTiers = renderOptions.layoutEntries?.length
|
|
189
|
+
? resolveRenderLayouts(renderOptions, {
|
|
190
|
+
layout: renderOptions.Layout,
|
|
191
|
+
layoutEntries: renderOptions.layoutEntries,
|
|
192
|
+
params: renderOptions.params,
|
|
193
|
+
query: renderOptions.query,
|
|
194
|
+
locals: renderOptions.locals,
|
|
195
|
+
}).map((layout) => layout.props ?? {})
|
|
196
|
+
: undefined;
|
|
191
197
|
return {
|
|
192
|
-
pageModuleUrl: this.pagePayloadService.resolvePageModuleUrl(
|
|
198
|
+
pageModuleUrl: this.pagePayloadService.resolvePageModuleUrl(renderOptions.pagePackage, {
|
|
193
199
|
routerEnabled: Boolean(this.routerAdapter),
|
|
194
200
|
}),
|
|
195
201
|
pageProps: this.pagePayloadService.buildSerializedPageProps({
|
|
196
|
-
pageProps:
|
|
197
|
-
params:
|
|
198
|
-
query:
|
|
199
|
-
|
|
202
|
+
pageProps: renderOptions.pageProps,
|
|
203
|
+
params: renderOptions.params,
|
|
204
|
+
query: renderOptions.query,
|
|
205
|
+
layoutTiers,
|
|
200
206
|
}),
|
|
201
207
|
};
|
|
202
208
|
}
|
|
@@ -249,14 +255,14 @@ export class ReactRenderer extends ReactIntegrationRenderer {
|
|
|
249
255
|
componentInstanceId: input.integrationContext?.componentInstanceId,
|
|
250
256
|
};
|
|
251
257
|
const hasResolvedChildHtml = input.children !== undefined;
|
|
252
|
-
let html =
|
|
258
|
+
let html = await renderComponentHtml({
|
|
253
259
|
input,
|
|
254
260
|
context,
|
|
255
261
|
runtimeContext,
|
|
256
262
|
runtime: this.getReactRuntimeModules(),
|
|
257
263
|
timeoutMs: this.getRuntimeState().renderTimeoutMs,
|
|
258
264
|
label: getComponentIdentity(input.component)?.file ?? 'component',
|
|
259
|
-
})
|
|
265
|
+
});
|
|
260
266
|
const componentFile = getComponentIdentity(componentConfig)?.file;
|
|
261
267
|
const isIslandRoot = Boolean(componentFile && context.componentInstanceId && !hasResolvedChildHtml) &&
|
|
262
268
|
hasSingleRootElement(replaceForeignSubtreeTokens(html, runtimeContext, '<x></x>'));
|
|
@@ -270,7 +276,7 @@ export class ReactRenderer extends ReactIntegrationRenderer {
|
|
|
270
276
|
integrationName: this.name,
|
|
271
277
|
componentInstanceId: context.componentInstanceId,
|
|
272
278
|
componentKey: getIslandComponentKey(toRootRelativePath(this.appConfig.rootDir, componentFile), componentConfig),
|
|
273
|
-
props:
|
|
279
|
+
props: input.props,
|
|
274
280
|
});
|
|
275
281
|
html = `<eco-island style="display:contents">${html}</eco-island>`;
|
|
276
282
|
}
|
|
@@ -281,15 +287,14 @@ export class ReactRenderer extends ReactIntegrationRenderer {
|
|
|
281
287
|
rootAttributes,
|
|
282
288
|
};
|
|
283
289
|
}
|
|
284
|
-
async renderQueuedChildrenHook(children, runtimeContext,
|
|
290
|
+
async renderQueuedChildrenHook(children, runtimeContext, resolveTokens) {
|
|
285
291
|
if (children === undefined) {
|
|
286
292
|
return {};
|
|
287
293
|
}
|
|
288
294
|
const html = await this.renderQueuedChildrenToHtml({
|
|
289
295
|
children,
|
|
290
296
|
runtimeContext: runtimeContext,
|
|
291
|
-
|
|
292
|
-
resolveToken,
|
|
297
|
+
resolveTokens,
|
|
293
298
|
});
|
|
294
299
|
return html === undefined ? {} : { html };
|
|
295
300
|
}
|
|
@@ -346,9 +351,9 @@ export class ReactRenderer extends ReactIntegrationRenderer {
|
|
|
346
351
|
const runtime = this.getReactRuntimeModules();
|
|
347
352
|
const renderTracker = new LayoutRenderTracker();
|
|
348
353
|
const tree = composeReactLayoutPageTree(pageComponent, page.props, shellEntries, {
|
|
349
|
-
context: resolveLayoutContextFromShell(page.props, shellEntries),
|
|
350
354
|
react: runtime.react,
|
|
351
355
|
renderTracker,
|
|
356
|
+
tierProps: shellEntries.map((entry) => entry.props ?? {}),
|
|
352
357
|
});
|
|
353
358
|
const runtimeInput = {
|
|
354
359
|
component: page.component,
|
|
@@ -358,7 +363,7 @@ export class ReactRenderer extends ReactIntegrationRenderer {
|
|
|
358
363
|
},
|
|
359
364
|
};
|
|
360
365
|
const runtimeContext = this.getQueuedForeignSubtreeContext(runtimeInput);
|
|
361
|
-
const html =
|
|
366
|
+
const html = await this.renderReactTree(tree, getComponentIdentity(page.component)?.file ?? 'page');
|
|
362
367
|
const layoutWithoutChildren = renderTracker.findLayoutWithoutChildren(page.component);
|
|
363
368
|
if (layoutWithoutChildren)
|
|
364
369
|
this.onLayoutChildrenNotRendered(layoutWithoutChildren);
|
|
@@ -382,14 +387,7 @@ export class ReactRenderer extends ReactIntegrationRenderer {
|
|
|
382
387
|
return (context) => this.composeReactLayoutPageChildrenForShell(page, context);
|
|
383
388
|
}
|
|
384
389
|
buildDocumentShellProps(options) {
|
|
385
|
-
const pagePayload = this.buildPagePayload(
|
|
386
|
-
Page: options.Page,
|
|
387
|
-
pageProps: options.pageProps,
|
|
388
|
-
params: options.params,
|
|
389
|
-
query: options.query,
|
|
390
|
-
locals: options.locals,
|
|
391
|
-
pagePackage: options.pagePackage,
|
|
392
|
-
});
|
|
390
|
+
const pagePayload = this.buildPagePayload(options);
|
|
393
391
|
return {
|
|
394
392
|
pageProps: pagePayload.pageProps,
|
|
395
393
|
documentProps: pagePayload.pageModuleUrl ? { pageModuleUrl: pagePayload.pageModuleUrl } : undefined,
|
|
@@ -403,14 +401,7 @@ export class ReactRenderer extends ReactIntegrationRenderer {
|
|
|
403
401
|
return this.buildRouterlessPageDataContributions(renderOptions);
|
|
404
402
|
if (isReactManagedComponent(renderOptions.HtmlTemplate, this.name))
|
|
405
403
|
return undefined;
|
|
406
|
-
const pagePayload = this.buildPagePayload(
|
|
407
|
-
Page: renderOptions.Page,
|
|
408
|
-
pageProps: renderOptions.pageProps,
|
|
409
|
-
params: renderOptions.params,
|
|
410
|
-
query: renderOptions.query,
|
|
411
|
-
locals: renderOptions.locals,
|
|
412
|
-
pagePackage: renderOptions.pagePackage,
|
|
413
|
-
});
|
|
404
|
+
const pagePayload = this.buildPagePayload(renderOptions);
|
|
414
405
|
return this.pagePayloadService.buildNonReactDocumentContributions({
|
|
415
406
|
htmlTemplate: renderOptions.HtmlTemplate,
|
|
416
407
|
pageProps: pagePayload.pageProps,
|
|
@@ -430,14 +421,7 @@ export class ReactRenderer extends ReactIntegrationRenderer {
|
|
|
430
421
|
buildRouterlessPageDataContributions(renderOptions) {
|
|
431
422
|
if (!this.hydratesPageTree(renderOptions.Page))
|
|
432
423
|
return undefined;
|
|
433
|
-
const pagePayload = this.buildPagePayload(
|
|
434
|
-
Page: renderOptions.Page,
|
|
435
|
-
pageProps: renderOptions.pageProps,
|
|
436
|
-
params: renderOptions.params,
|
|
437
|
-
query: renderOptions.query,
|
|
438
|
-
locals: renderOptions.locals,
|
|
439
|
-
pagePackage: renderOptions.pagePackage,
|
|
440
|
-
});
|
|
424
|
+
const pagePayload = this.buildPagePayload(renderOptions);
|
|
441
425
|
return [
|
|
442
426
|
{
|
|
443
427
|
placement: 'head-append',
|
|
@@ -464,8 +448,6 @@ function createReactRendererHookFactory(reactConfig, runtimeStateRef, hookTarget
|
|
|
464
448
|
getMdxLoaderPlugin: reactConfig?.getMdxLoaderPlugin,
|
|
465
449
|
});
|
|
466
450
|
const pageModuleService = new PageModuleService({
|
|
467
|
-
layoutsDir: appConfig.absolutePaths.layoutsDir,
|
|
468
|
-
componentsDir: appConfig.absolutePaths.componentsDir,
|
|
469
451
|
mdxExtensions,
|
|
470
452
|
integrationName: REACT_PLUGIN_NAME,
|
|
471
453
|
hasRouterAdapter: Boolean(routerAdapter),
|
|
@@ -500,7 +482,7 @@ function createReactRendererHookFactory(reactConfig, runtimeStateRef, hookTarget
|
|
|
500
482
|
buildIslandClientAssets: (plan) => requireReactRendererHookTarget(hookTargets, 'buildIslandClientAssets')(plan),
|
|
501
483
|
collectAppBrowserClientBuildEntries: (plan) => requireReactRendererHookTarget(hookTargets, 'collectAppBrowserClientBuildEntries')(plan),
|
|
502
484
|
renderComponent: (input) => requireReactRendererHookTarget(hookTargets, 'renderComponent')(input),
|
|
503
|
-
renderQueuedChildren: (children, runtimeContext,
|
|
485
|
+
renderQueuedChildren: (children, runtimeContext, resolveTokens) => requireReactRendererHookTarget(hookTargets, 'renderQueuedChildren')(children, runtimeContext, resolveTokens),
|
|
504
486
|
normalizePageModule: (file, module) => requireReactRendererHookTarget(hookTargets, 'normalizePageModule')(file, module),
|
|
505
487
|
collectPageBrowserGraphContribution: (context) => requireReactRendererHookTarget(hookTargets, 'collectPageBrowserGraphContribution')(context),
|
|
506
488
|
composeChildren: (input) => requireReactRendererHookTarget(hookTargets, 'composeChildren')(input),
|