@ecopages/core 0.2.0-alpha.11 → 0.2.0-alpha.13
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/CHANGELOG.md +7 -10
- package/README.md +5 -4
- package/package.json +30 -6
- package/src/adapters/bun/hmr-manager.js +2 -2
- package/src/adapters/node/node-hmr-manager.js +2 -2
- package/src/adapters/node/server-adapter.d.ts +2 -2
- package/src/adapters/node/server-adapter.js +5 -5
- package/src/build/build-adapter.d.ts +8 -6
- package/src/build/build-adapter.js +44 -7
- package/src/eco/eco.js +18 -118
- package/src/eco/eco.utils.d.ts +1 -40
- package/src/eco/eco.utils.js +5 -35
- package/src/hmr/hmr-strategy.d.ts +8 -6
- package/src/integrations/ghtml/ghtml-renderer.d.ts +6 -1
- package/src/integrations/ghtml/ghtml-renderer.js +29 -28
- package/src/plugins/foreign-jsx-override-plugin.d.ts +31 -0
- package/src/plugins/foreign-jsx-override-plugin.js +35 -0
- package/src/plugins/integration-plugin.d.ts +90 -29
- package/src/plugins/integration-plugin.js +62 -19
- package/src/route-renderer/GRAPH.md +54 -84
- package/src/route-renderer/README.md +11 -19
- package/src/route-renderer/orchestration/component-render-context.d.ts +83 -0
- package/src/route-renderer/orchestration/component-render-context.js +147 -0
- package/src/route-renderer/orchestration/integration-renderer.d.ts +219 -81
- package/src/route-renderer/orchestration/integration-renderer.js +415 -171
- package/src/route-renderer/orchestration/queued-boundary-runtime.service.d.ts +93 -0
- package/src/route-renderer/orchestration/queued-boundary-runtime.service.js +155 -0
- package/src/route-renderer/orchestration/render-execution.service.d.ts +8 -70
- package/src/route-renderer/orchestration/render-execution.service.js +28 -113
- package/src/route-renderer/orchestration/render-output.utils.d.ts +46 -0
- package/src/route-renderer/orchestration/render-output.utils.js +65 -0
- package/src/route-renderer/orchestration/render-preparation.service.d.ts +0 -6
- package/src/route-renderer/orchestration/render-preparation.service.js +5 -13
- package/src/route-renderer/orchestration/template-serialization.d.ts +38 -0
- package/src/route-renderer/orchestration/template-serialization.js +45 -0
- package/src/route-renderer/page-loading/dependency-resolver.js +10 -8
- package/src/router/client/navigation-coordinator.js +2 -2
- package/src/router/server/fs-router-scanner.js +6 -1
- package/src/services/module-loading/node-bootstrap-plugin.js +14 -1
- package/src/services/module-loading/page-module-import.service.js +1 -1
- package/src/services/runtime-state/dev-graph.service.d.ts +5 -5
- package/src/services/runtime-state/dev-graph.service.js +10 -10
- package/src/types/public-types.d.ts +18 -3
- package/src/utils/html-escaping.d.ts +7 -0
- package/src/utils/html-escaping.js +6 -0
- package/src/eco/component-render-context.d.ts +0 -105
- package/src/eco/component-render-context.js +0 -94
- package/src/route-renderer/component-graph/component-graph-executor.d.ts +0 -33
- package/src/route-renderer/component-graph/component-graph-executor.js +0 -30
- package/src/route-renderer/component-graph/component-graph.d.ts +0 -53
- package/src/route-renderer/component-graph/component-graph.js +0 -94
- package/src/route-renderer/component-graph/component-marker.d.ts +0 -52
- package/src/route-renderer/component-graph/component-marker.js +0 -46
- package/src/route-renderer/component-graph/component-reference.d.ts +0 -11
- package/src/route-renderer/component-graph/component-reference.js +0 -39
- package/src/route-renderer/component-graph/marker-graph-resolver.d.ts +0 -79
- package/src/route-renderer/component-graph/marker-graph-resolver.js +0 -117
|
@@ -6,10 +6,13 @@ import { HttpError } from "../../errors/http-error.js";
|
|
|
6
6
|
import { LocalsAccessError } from "../../errors/locals-access-error.js";
|
|
7
7
|
import { DependencyResolverService } from "../page-loading/dependency-resolver.js";
|
|
8
8
|
import { PageModuleLoaderService } from "../page-loading/page-module-loader.js";
|
|
9
|
-
import { MarkerGraphResolver } from "../component-graph/marker-graph-resolver.js";
|
|
10
9
|
import { RenderExecutionService } from "./render-execution.service.js";
|
|
11
10
|
import { RenderPreparationService } from "./render-preparation.service.js";
|
|
12
|
-
import {
|
|
11
|
+
import { normalizeBoundaryArtifactHtml } from "./render-output.utils.js";
|
|
12
|
+
import { getComponentRenderContext, runWithComponentRenderContext } from "./component-render-context.js";
|
|
13
|
+
import {
|
|
14
|
+
QueuedBoundaryRuntimeService
|
|
15
|
+
} from "./queued-boundary-runtime.service.js";
|
|
13
16
|
function createLocalsProxy(filePath) {
|
|
14
17
|
const errorMessage = `[ecopages] Request locals are only available during request-time rendering with cache: 'dynamic'. Page: ${filePath}. If you meant to use locals here, set cache: 'dynamic' and provide locals from route middleware/handlers.`;
|
|
15
18
|
return new Proxy(
|
|
@@ -49,10 +52,55 @@ class IntegrationRenderer {
|
|
|
49
52
|
runtimeOrigin;
|
|
50
53
|
dependencyResolverService;
|
|
51
54
|
pageModuleLoaderService;
|
|
52
|
-
markerGraphResolver;
|
|
53
55
|
renderPreparationService;
|
|
54
56
|
renderExecutionService;
|
|
57
|
+
queuedBoundaryRuntimeService = new QueuedBoundaryRuntimeService();
|
|
55
58
|
DOC_TYPE = "<!DOCTYPE html>";
|
|
59
|
+
/**
|
|
60
|
+
* Reads the execution-scoped foreign renderer cache from one boundary input.
|
|
61
|
+
*
|
|
62
|
+
* Shared page/layout/document shell helpers pass one cache through
|
|
63
|
+
* `integrationContext` so repeated delegation to the same foreign integration
|
|
64
|
+
* can reuse a single initialized renderer instance during one render flow.
|
|
65
|
+
* The cache is deliberately scoped to the current render execution rather than
|
|
66
|
+
* stored on the renderer, which avoids leaking mutable integration state across
|
|
67
|
+
* requests while still preventing redundant renderer initialization.
|
|
68
|
+
*
|
|
69
|
+
* @param integrationContext - Optional boundary context carried with one render input.
|
|
70
|
+
* @returns The current execution cache when present.
|
|
71
|
+
*/
|
|
72
|
+
getBoundaryRendererCache(integrationContext) {
|
|
73
|
+
if (typeof integrationContext === "object" && integrationContext !== null && "rendererCache" in integrationContext && integrationContext.rendererCache instanceof Map) {
|
|
74
|
+
return integrationContext.rendererCache;
|
|
75
|
+
}
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
getRegisteredBoundaryOwner(component) {
|
|
79
|
+
const integrationName = component.config?.integration ?? component.config?.__eco?.integration;
|
|
80
|
+
if (!integrationName || integrationName === this.name) {
|
|
81
|
+
return void 0;
|
|
82
|
+
}
|
|
83
|
+
return this.appConfig.integrations.some((integration) => integration.name === integrationName) ? integrationName : void 0;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Attaches an execution-scoped foreign renderer cache to one boundary input.
|
|
87
|
+
*
|
|
88
|
+
* Foreign-owned page, layout, or document shells may delegate several times in
|
|
89
|
+
* the same render flow. Threading the cache through `integrationContext`
|
|
90
|
+
* preserves renderer reuse without changing the public boundary input contract.
|
|
91
|
+
* Existing integration-specific context is preserved and augmented.
|
|
92
|
+
*
|
|
93
|
+
* @param input - Original boundary render input.
|
|
94
|
+
* @param rendererCache - Execution-scoped renderer cache to propagate.
|
|
95
|
+
* @returns Boundary input augmented with the shared renderer cache.
|
|
96
|
+
*/
|
|
97
|
+
withBoundaryRendererCache(input, rendererCache) {
|
|
98
|
+
const integrationContext = input.integrationContext;
|
|
99
|
+
return {
|
|
100
|
+
...input,
|
|
101
|
+
integrationContext: typeof integrationContext === "object" && integrationContext !== null ? { ...integrationContext, rendererCache } : { rendererCache }
|
|
102
|
+
};
|
|
103
|
+
}
|
|
56
104
|
getRendererModuleValue(key) {
|
|
57
105
|
if (!this.rendererModules || typeof this.rendererModules !== "object") {
|
|
58
106
|
return void 0;
|
|
@@ -143,6 +191,265 @@ class IntegrationRenderer {
|
|
|
143
191
|
this.htmlTransformer.setProcessedDependencies(resolvedDependencies);
|
|
144
192
|
return resolvedDependencies;
|
|
145
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Merges component-scoped assets into the active HTML transformer state.
|
|
196
|
+
*
|
|
197
|
+
* Explicit page, layout, and document shell composition can produce assets at
|
|
198
|
+
* each boundary. This helper deduplicates those groups and folds them back into
|
|
199
|
+
* the transformer so downstream HTML finalization sees one canonical asset set.
|
|
200
|
+
*
|
|
201
|
+
* @param assetGroups - Optional groups of processed assets to merge.
|
|
202
|
+
* @returns The deduplicated asset subset contributed by this merge operation.
|
|
203
|
+
*/
|
|
204
|
+
appendProcessedDependencies(...assetGroups) {
|
|
205
|
+
const nextDependencies = this.htmlTransformer.dedupeProcessedAssets(
|
|
206
|
+
assetGroups.flatMap((assets) => assets ?? [])
|
|
207
|
+
);
|
|
208
|
+
if (nextDependencies.length === 0) {
|
|
209
|
+
return nextDependencies;
|
|
210
|
+
}
|
|
211
|
+
this.htmlTransformer.setProcessedDependencies(
|
|
212
|
+
this.htmlTransformer.dedupeProcessedAssets([
|
|
213
|
+
...this.htmlTransformer.getProcessedDependencies(),
|
|
214
|
+
...nextDependencies
|
|
215
|
+
])
|
|
216
|
+
);
|
|
217
|
+
return nextDependencies;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Resolves metadata for explicit view rendering.
|
|
221
|
+
*
|
|
222
|
+
* When a view declares a `metadata()` function, that contract owns the final
|
|
223
|
+
* metadata for the explicit render. Otherwise the app-level default metadata is
|
|
224
|
+
* reused so explicit routes and page-module routes share the same fallback.
|
|
225
|
+
*
|
|
226
|
+
* @param view - View component being rendered.
|
|
227
|
+
* @param props - Props passed to the view.
|
|
228
|
+
* @returns Resolved metadata for the final document shell.
|
|
229
|
+
*/
|
|
230
|
+
async resolveViewMetadata(view, props) {
|
|
231
|
+
return view.metadata ? await view.metadata({
|
|
232
|
+
params: {},
|
|
233
|
+
query: {},
|
|
234
|
+
props,
|
|
235
|
+
appConfig: this.appConfig
|
|
236
|
+
}) : this.appConfig.defaultMetadata;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Renders one explicit view response in partial mode.
|
|
240
|
+
*
|
|
241
|
+
* Same-integration views can optionally stream or render inline via the caller's
|
|
242
|
+
* `renderInline()` hook. Once a view may cross integration boundaries, this
|
|
243
|
+
* helper routes the render through `renderComponentBoundary()` instead so mixed
|
|
244
|
+
* shells can reuse the execution-scoped renderer cache and resolve nested
|
|
245
|
+
* foreign ownership before the partial response is returned.
|
|
246
|
+
*
|
|
247
|
+
* @param input - View render options for the partial response.
|
|
248
|
+
* @returns HTML response for the partial render.
|
|
249
|
+
*/
|
|
250
|
+
async renderPartialViewResponse(input) {
|
|
251
|
+
if (input.renderInline && !this.hasForeignBoundaryDescendants(input.view)) {
|
|
252
|
+
return this.createHtmlResponse(await input.renderInline(), input.ctx);
|
|
253
|
+
}
|
|
254
|
+
const rendererCache = /* @__PURE__ */ new Map();
|
|
255
|
+
const viewRender = await this.renderComponentBoundary({
|
|
256
|
+
component: input.view,
|
|
257
|
+
props: input.props ?? {},
|
|
258
|
+
integrationContext: { rendererCache }
|
|
259
|
+
});
|
|
260
|
+
const html = input.transformHtml ? input.transformHtml(viewRender.html) : viewRender.html;
|
|
261
|
+
return this.createHtmlResponse(html, input.ctx);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Renders an explicit view through optional layout and document shells.
|
|
265
|
+
*
|
|
266
|
+
* This helper is the shared explicit-route path for string-oriented and mixed
|
|
267
|
+
* integrations. It prepares view dependencies, resolves metadata, and composes
|
|
268
|
+
* view, layout, and html template boundaries with one execution-scoped renderer
|
|
269
|
+
* cache so repeated foreign shell delegation can reuse initialized renderers
|
|
270
|
+
* during the same render flow.
|
|
271
|
+
*
|
|
272
|
+
* @param input - View, props, and optional layout metadata for the render.
|
|
273
|
+
* @returns HTML response for the explicit view render.
|
|
274
|
+
*/
|
|
275
|
+
async renderViewWithDocumentShell(input) {
|
|
276
|
+
const normalizedProps = input.props ?? {};
|
|
277
|
+
if (input.ctx.partial) {
|
|
278
|
+
return this.renderPartialViewResponse({
|
|
279
|
+
view: input.view,
|
|
280
|
+
props: input.props,
|
|
281
|
+
ctx: input.ctx
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
await this.prepareViewDependencies(input.view, input.layout);
|
|
285
|
+
const HtmlTemplate = await this.getHtmlTemplate();
|
|
286
|
+
const metadata = await this.resolveViewMetadata(input.view, input.props);
|
|
287
|
+
const rendererCache = /* @__PURE__ */ new Map();
|
|
288
|
+
const viewRender = await this.renderComponentBoundary({
|
|
289
|
+
component: input.view,
|
|
290
|
+
props: normalizedProps,
|
|
291
|
+
integrationContext: { rendererCache }
|
|
292
|
+
});
|
|
293
|
+
const layoutRender = input.layout ? await this.renderComponentBoundary({
|
|
294
|
+
component: input.layout,
|
|
295
|
+
props: {},
|
|
296
|
+
children: viewRender.html,
|
|
297
|
+
integrationContext: { rendererCache }
|
|
298
|
+
}) : void 0;
|
|
299
|
+
const documentRender = await this.renderComponentBoundary({
|
|
300
|
+
component: HtmlTemplate,
|
|
301
|
+
props: {
|
|
302
|
+
metadata,
|
|
303
|
+
pageProps: normalizedProps
|
|
304
|
+
},
|
|
305
|
+
children: layoutRender?.html ?? viewRender.html,
|
|
306
|
+
integrationContext: { rendererCache }
|
|
307
|
+
});
|
|
308
|
+
this.appendProcessedDependencies(viewRender.assets, layoutRender?.assets, documentRender.assets);
|
|
309
|
+
const html = await this.finalizeResolvedHtml({
|
|
310
|
+
html: `${this.DOC_TYPE}${documentRender.html}`,
|
|
311
|
+
partial: false
|
|
312
|
+
});
|
|
313
|
+
return this.createHtmlResponse(html, input.ctx);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Renders a route page through optional layout and document shells.
|
|
317
|
+
*
|
|
318
|
+
* Route rendering and explicit view rendering now share the same boundary-owned
|
|
319
|
+
* shell composition model. This helper composes page, layout, and html template
|
|
320
|
+
* boundaries while threading one execution-scoped renderer cache through every
|
|
321
|
+
* delegated boundary so foreign shell ownership remains stable and renderer
|
|
322
|
+
* initialization is reused inside the current request.
|
|
323
|
+
*
|
|
324
|
+
* @param input - Page, layout, document, and metadata inputs for the route render.
|
|
325
|
+
* @returns Final serialized document HTML including the doctype prefix.
|
|
326
|
+
*/
|
|
327
|
+
async renderPageWithDocumentShell(input) {
|
|
328
|
+
const rendererCache = /* @__PURE__ */ new Map();
|
|
329
|
+
const pageRender = await this.renderComponentBoundary({
|
|
330
|
+
component: input.page.component,
|
|
331
|
+
props: input.page.props,
|
|
332
|
+
integrationContext: { rendererCache }
|
|
333
|
+
});
|
|
334
|
+
const layoutRender = input.layout ? await this.renderComponentBoundary({
|
|
335
|
+
component: input.layout.component,
|
|
336
|
+
props: input.layout.props ?? {},
|
|
337
|
+
children: pageRender.html,
|
|
338
|
+
integrationContext: { rendererCache }
|
|
339
|
+
}) : void 0;
|
|
340
|
+
const documentRender = await this.renderComponentBoundary({
|
|
341
|
+
component: input.htmlTemplate,
|
|
342
|
+
props: {
|
|
343
|
+
metadata: input.metadata,
|
|
344
|
+
pageProps: input.pageProps,
|
|
345
|
+
...input.documentProps ?? {}
|
|
346
|
+
},
|
|
347
|
+
children: layoutRender?.html ?? pageRender.html,
|
|
348
|
+
integrationContext: { rendererCache }
|
|
349
|
+
});
|
|
350
|
+
this.appendProcessedDependencies(pageRender.assets, layoutRender?.assets, documentRender.assets);
|
|
351
|
+
const documentHtml = input.transformDocumentHtml ? input.transformDocumentHtml(documentRender.html) : documentRender.html;
|
|
352
|
+
return `${this.DOC_TYPE}${documentHtml}`;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Renders one string-first component boundary and collects its assets.
|
|
356
|
+
*
|
|
357
|
+
* String-oriented integrations frequently share the same boundary contract:
|
|
358
|
+
* pass serialized children through props, coerce the render result to HTML, and
|
|
359
|
+
* attach any component-scoped dependencies. This helper centralizes that flow
|
|
360
|
+
* so integrations can opt into shared orchestration without repeating the same
|
|
361
|
+
* boundary boilerplate.
|
|
362
|
+
*
|
|
363
|
+
* @param input - Boundary render input.
|
|
364
|
+
* @param component - String-oriented component implementation to execute.
|
|
365
|
+
* @returns Structured component render result for orchestration paths.
|
|
366
|
+
*/
|
|
367
|
+
async renderStringComponentBoundary(input, component) {
|
|
368
|
+
const props = input.children === void 0 ? input.props : { ...input.props, children: input.children };
|
|
369
|
+
const content = await component(props);
|
|
370
|
+
const html = String(content);
|
|
371
|
+
const assets = input.component.config?.dependencies && typeof this.assetProcessingService?.processDependencies === "function" ? await this.processComponentDependencies([input.component]) : void 0;
|
|
372
|
+
return {
|
|
373
|
+
html,
|
|
374
|
+
canAttachAttributes: true,
|
|
375
|
+
rootTag: this.getRootTagName(html),
|
|
376
|
+
integrationName: this.name,
|
|
377
|
+
assets
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
getBoundaryTokenPrefix() {
|
|
381
|
+
return `__${this.name}_boundary__`;
|
|
382
|
+
}
|
|
383
|
+
getBoundaryRuntimeContextKey() {
|
|
384
|
+
return `__${this.name}_boundary_runtime__`;
|
|
385
|
+
}
|
|
386
|
+
getQueuedBoundaryRuntime(input, runtimeContextKey = this.getBoundaryRuntimeContextKey()) {
|
|
387
|
+
return this.queuedBoundaryRuntimeService.getRuntimeContext(input, runtimeContextKey);
|
|
388
|
+
}
|
|
389
|
+
async resolveQueuedBoundaryTokens(html, queuedResolutionsByToken, resolveToken) {
|
|
390
|
+
let resolvedHtml = html;
|
|
391
|
+
for (const token of queuedResolutionsByToken.keys()) {
|
|
392
|
+
if (!resolvedHtml.includes(token)) {
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
resolvedHtml = resolvedHtml.split(token).join(await resolveToken(token));
|
|
396
|
+
}
|
|
397
|
+
return resolvedHtml;
|
|
398
|
+
}
|
|
399
|
+
createQueuedBoundaryRuntime(options) {
|
|
400
|
+
return this.queuedBoundaryRuntimeService.createRuntime({
|
|
401
|
+
boundaryInput: options.boundaryInput,
|
|
402
|
+
rendererCache: options.rendererCache,
|
|
403
|
+
runtimeContextKey: options.runtimeContextKey ?? this.getBoundaryRuntimeContextKey(),
|
|
404
|
+
tokenPrefix: options.tokenPrefix ?? this.getBoundaryTokenPrefix(),
|
|
405
|
+
shouldQueueBoundary: (input) => this.shouldResolveBoundaryInOwningRenderer(input),
|
|
406
|
+
createRuntimeContext: options.createRuntimeContext
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
async resolveRendererOwnedQueuedBoundaryHtml(options) {
|
|
410
|
+
return this.queuedBoundaryRuntimeService.resolveQueuedHtml({
|
|
411
|
+
html: options.html,
|
|
412
|
+
runtimeContext: options.runtimeContext,
|
|
413
|
+
queueLabel: options.queueLabel,
|
|
414
|
+
renderQueuedChildren: options.renderQueuedChildren,
|
|
415
|
+
resolveBoundary: (input, rendererCache) => this.resolveBoundaryInOwningRenderer(input, rendererCache),
|
|
416
|
+
applyAttributesToFirstElement: (html, attributes) => this.htmlTransformer.applyAttributesToFirstElement(html, attributes),
|
|
417
|
+
dedupeProcessedAssets: (assets) => this.htmlTransformer.dedupeProcessedAssets(assets)
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Renders a string-first component, then resolves any queued foreign
|
|
422
|
+
* boundaries before returning final component HTML.
|
|
423
|
+
*/
|
|
424
|
+
async renderStringComponentBoundaryWithQueuedForeignBoundaries(input, component) {
|
|
425
|
+
const componentRender = await this.renderStringComponentBoundary(input, component);
|
|
426
|
+
const queuedBoundaryResolution = await this.resolveRendererOwnedQueuedBoundaryHtml({
|
|
427
|
+
html: componentRender.html,
|
|
428
|
+
runtimeContext: this.getQueuedBoundaryRuntime(input),
|
|
429
|
+
queueLabel: "String",
|
|
430
|
+
renderQueuedChildren: async (children, _runtimeContext, queuedResolutionsByToken, resolveToken) => {
|
|
431
|
+
if (children === void 0) {
|
|
432
|
+
return { assets: [], html: void 0 };
|
|
433
|
+
}
|
|
434
|
+
const html = await this.resolveQueuedBoundaryTokens(
|
|
435
|
+
typeof children === "string" ? children : String(children ?? ""),
|
|
436
|
+
queuedResolutionsByToken,
|
|
437
|
+
resolveToken
|
|
438
|
+
);
|
|
439
|
+
return { assets: [], html };
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
const mergedAssets = this.htmlTransformer.dedupeProcessedAssets([
|
|
443
|
+
...componentRender.assets ?? [],
|
|
444
|
+
...queuedBoundaryResolution.assets
|
|
445
|
+
]);
|
|
446
|
+
return {
|
|
447
|
+
...componentRender,
|
|
448
|
+
html: queuedBoundaryResolution.html,
|
|
449
|
+
rootTag: this.getRootTagName(queuedBoundaryResolution.html),
|
|
450
|
+
assets: mergedAssets.length > 0 ? mergedAssets : void 0
|
|
451
|
+
};
|
|
452
|
+
}
|
|
146
453
|
constructor({
|
|
147
454
|
appConfig,
|
|
148
455
|
assetProcessingService,
|
|
@@ -158,7 +465,6 @@ class IntegrationRenderer {
|
|
|
158
465
|
this.runtimeOrigin = runtimeOrigin;
|
|
159
466
|
this.dependencyResolverService = new DependencyResolverService(appConfig, assetProcessingService);
|
|
160
467
|
this.pageModuleLoaderService = new PageModuleLoaderService(appConfig, runtimeOrigin);
|
|
161
|
-
this.markerGraphResolver = new MarkerGraphResolver();
|
|
162
468
|
this.renderPreparationService = new RenderPreparationService(appConfig, assetProcessingService);
|
|
163
469
|
this.renderExecutionService = new RenderExecutionService();
|
|
164
470
|
}
|
|
@@ -328,14 +634,13 @@ class IntegrationRenderer {
|
|
|
328
634
|
resolveDependencies: (components) => this.resolveDependencies(components),
|
|
329
635
|
buildRouteRenderAssets: (file) => this.buildRouteRenderAssets(file),
|
|
330
636
|
shouldRenderPageComponent: (input) => this.shouldRenderPageComponent(input),
|
|
331
|
-
renderPageComponent: ({ component, props }) => this.
|
|
637
|
+
renderPageComponent: ({ component, props }) => this.renderComponentBoundary({
|
|
332
638
|
component,
|
|
333
639
|
props,
|
|
334
640
|
integrationContext: {
|
|
335
641
|
componentInstanceId: "eco-page-root"
|
|
336
642
|
}
|
|
337
643
|
}),
|
|
338
|
-
getComponentRenderBoundaryContext: () => this.getComponentRenderBoundaryContext(),
|
|
339
644
|
setProcessedDependencies: (dependencies) => this.htmlTransformer.setProcessedDependencies(dependencies),
|
|
340
645
|
dedupeProcessedAssets: (assets) => this.htmlTransformer.dedupeProcessedAssets(assets),
|
|
341
646
|
createPageLocalsProxy: (filePath) => createLocalsProxy(filePath)
|
|
@@ -375,11 +680,10 @@ class IntegrationRenderer {
|
|
|
375
680
|
*
|
|
376
681
|
* Execution flow:
|
|
377
682
|
* 1. Build normalized render options (`prepareRenderOptions`).
|
|
378
|
-
* 2. Render
|
|
379
|
-
* 3.
|
|
380
|
-
* 4.
|
|
381
|
-
* 5.
|
|
382
|
-
* 6. Run HTML transformer with final dependency set.
|
|
683
|
+
* 2. Render the route body once.
|
|
684
|
+
* 3. Reject unresolved route-level boundary artifacts.
|
|
685
|
+
* 4. Optionally apply root attributes for page/component root boundaries.
|
|
686
|
+
* 5. Run HTML transformer with final dependency set.
|
|
383
687
|
*
|
|
384
688
|
* Stream-safety note: the first render result is normalized to a string once,
|
|
385
689
|
* then the pipeline continues with that immutable HTML value to avoid disturbed
|
|
@@ -389,85 +693,41 @@ class IntegrationRenderer {
|
|
|
389
693
|
* @returns Rendered route body plus effective cache strategy.
|
|
390
694
|
*/
|
|
391
695
|
async execute(options) {
|
|
392
|
-
return this.renderExecutionService.execute(options,
|
|
696
|
+
return this.renderExecutionService.execute(options, {
|
|
393
697
|
prepareRenderOptions: (routeOptions) => this.prepareRenderOptions(routeOptions),
|
|
394
698
|
render: (renderOptions) => this.render(renderOptions),
|
|
395
|
-
getComponentRenderBoundaryContext: () => this.getComponentRenderBoundaryContext(),
|
|
396
|
-
resolveMarkerGraphHtml: (input) => this.resolveMarkerGraphHtml({
|
|
397
|
-
html: input.html,
|
|
398
|
-
componentsToResolve: input.componentsToResolve,
|
|
399
|
-
graphContext: input.graphContext
|
|
400
|
-
}),
|
|
401
699
|
getDocumentAttributes: (renderOptions) => this.getDocumentAttributes(renderOptions),
|
|
402
|
-
dedupeProcessedAssets: (assets) => this.htmlTransformer.dedupeProcessedAssets(assets),
|
|
403
|
-
getProcessedDependencies: () => this.htmlTransformer.getProcessedDependencies(),
|
|
404
|
-
setProcessedDependencies: (dependencies) => this.htmlTransformer.setProcessedDependencies(dependencies),
|
|
405
700
|
applyAttributesToHtmlElement: (html, attributes) => this.htmlTransformer.applyAttributesToHtmlElement(html, attributes),
|
|
406
701
|
applyAttributesToFirstBodyElement: (html, attributes) => this.htmlTransformer.applyAttributesToFirstBodyElement(html, attributes),
|
|
407
702
|
transformResponse: async (response) => {
|
|
408
703
|
const transformedResponse = await this.htmlTransformer.transform(response);
|
|
409
|
-
return transformedResponse.body;
|
|
704
|
+
return transformedResponse.body ?? await transformedResponse.text();
|
|
410
705
|
}
|
|
411
706
|
});
|
|
412
707
|
}
|
|
413
708
|
/**
|
|
414
|
-
*
|
|
415
|
-
* for deferred marker resolution.
|
|
709
|
+
* Finalizes already-resolved HTML for explicit renderer-owned paths.
|
|
416
710
|
*
|
|
417
|
-
* This
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*/
|
|
421
|
-
async captureHtmlRender(render) {
|
|
422
|
-
return this.renderExecutionService.captureHtmlRender(
|
|
423
|
-
this.name,
|
|
424
|
-
this.getComponentRenderBoundaryContext(),
|
|
425
|
-
render
|
|
426
|
-
);
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Finalizes previously captured HTML by resolving deferred markers, merging
|
|
430
|
-
* any emitted assets, stamping optional attributes, and optionally running the
|
|
431
|
-
* HTML transformer for full-document flows.
|
|
711
|
+
* This keeps document and root-attribute stamping plus HTML transformation
|
|
712
|
+
* available after a renderer has completed nested boundary resolution without
|
|
713
|
+
* routing back through shared route execution.
|
|
432
714
|
*/
|
|
433
|
-
async
|
|
715
|
+
async finalizeResolvedHtml(options) {
|
|
434
716
|
const rendererBootstrapDependencies = this.getRendererBootstrapDependencies(options.partial);
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
);
|
|
717
|
+
this.appendProcessedDependencies(rendererBootstrapDependencies);
|
|
718
|
+
let html = options.html;
|
|
719
|
+
if (options.componentRootAttributes && Object.keys(options.componentRootAttributes).length > 0) {
|
|
720
|
+
html = this.htmlTransformer.applyAttributesToFirstBodyElement(html, options.componentRootAttributes);
|
|
721
|
+
}
|
|
722
|
+
if (options.documentAttributes && Object.keys(options.documentAttributes).length > 0) {
|
|
723
|
+
html = this.htmlTransformer.applyAttributesToHtmlElement(html, options.documentAttributes);
|
|
442
724
|
}
|
|
443
|
-
const finalization = await this.renderExecutionService.finalizeHtmlRender(
|
|
444
|
-
{
|
|
445
|
-
html: options.html,
|
|
446
|
-
graphContext: options.graphContext,
|
|
447
|
-
componentsToResolve: options.componentsToResolve,
|
|
448
|
-
componentRootAttributes: options.componentRootAttributes,
|
|
449
|
-
documentAttributes: options.documentAttributes,
|
|
450
|
-
mergeAssets: options.mergeAssets ?? !options.partial
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
resolveMarkerGraphHtml: (input) => this.resolveMarkerGraphHtml({
|
|
454
|
-
html: input.html,
|
|
455
|
-
componentsToResolve: input.componentsToResolve,
|
|
456
|
-
graphContext: input.graphContext
|
|
457
|
-
}),
|
|
458
|
-
dedupeProcessedAssets: (assets) => this.htmlTransformer.dedupeProcessedAssets(assets),
|
|
459
|
-
getProcessedDependencies: () => this.htmlTransformer.getProcessedDependencies(),
|
|
460
|
-
setProcessedDependencies: (dependencies) => this.htmlTransformer.setProcessedDependencies(dependencies),
|
|
461
|
-
applyAttributesToHtmlElement: (html, attributes) => this.htmlTransformer.applyAttributesToHtmlElement(html, attributes),
|
|
462
|
-
applyAttributesToFirstBodyElement: (html, attributes) => this.htmlTransformer.applyAttributesToFirstBodyElement(html, attributes)
|
|
463
|
-
}
|
|
464
|
-
);
|
|
465
725
|
const shouldTransform = options.transformHtml ?? !options.partial;
|
|
466
726
|
if (!shouldTransform) {
|
|
467
|
-
return
|
|
727
|
+
return html;
|
|
468
728
|
}
|
|
469
729
|
const transformedResponse = await this.htmlTransformer.transform(
|
|
470
|
-
new Response(
|
|
730
|
+
new Response(html, {
|
|
471
731
|
headers: { "Content-Type": "text/html" }
|
|
472
732
|
})
|
|
473
733
|
);
|
|
@@ -482,40 +742,6 @@ class IntegrationRenderer {
|
|
|
482
742
|
getDocumentAttributes(_renderOptions) {
|
|
483
743
|
return void 0;
|
|
484
744
|
}
|
|
485
|
-
/**
|
|
486
|
-
* Resolves all `eco-marker` placeholders in rendered HTML using integration
|
|
487
|
-
* dispatch and bottom-up graph execution.
|
|
488
|
-
*
|
|
489
|
-
* Responsibility split:
|
|
490
|
-
* - core decodes markers into component refs, props, slot children, and target
|
|
491
|
-
* integration dispatch
|
|
492
|
-
* - the selected integration renderer performs the actual component render via
|
|
493
|
-
* `renderComponent()`
|
|
494
|
-
*
|
|
495
|
-
* Resolver callback behavior per marker:
|
|
496
|
-
* - resolve component definition by `componentRef`
|
|
497
|
-
* - resolve serialized props by `propsRef`
|
|
498
|
-
* - stitch resolved child HTML when `slotRef` is present
|
|
499
|
-
* - dispatch to target integration `renderComponent`
|
|
500
|
-
* - collect produced assets and apply root attributes when attachable
|
|
501
|
-
*
|
|
502
|
-
* @param options.html HTML that may still contain marker tokens.
|
|
503
|
-
* @param options.componentsToResolve Component set used to build component ref registry.
|
|
504
|
-
* @param options.graphContext Props/slot linkage captured during render.
|
|
505
|
-
* @returns Resolved HTML plus any component-scoped assets produced while resolving nodes.
|
|
506
|
-
* @throws Error when marker component refs or props refs cannot be resolved.
|
|
507
|
-
*/
|
|
508
|
-
async resolveMarkerGraphHtml(options) {
|
|
509
|
-
const integrationRendererCache = /* @__PURE__ */ new Map();
|
|
510
|
-
return this.markerGraphResolver.resolve({
|
|
511
|
-
html: options.html,
|
|
512
|
-
componentsToResolve: options.componentsToResolve,
|
|
513
|
-
graphContext: options.graphContext,
|
|
514
|
-
instanceIdScope: options.instanceIdScope,
|
|
515
|
-
resolveRenderer: (integrationName) => this.getIntegrationRendererForName(integrationName, integrationRendererCache),
|
|
516
|
-
applyAttributesToFirstElement: (html, attributes) => this.htmlTransformer.applyAttributesToFirstElement(html, attributes)
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
745
|
/**
|
|
520
746
|
* Returns a renderer instance for a given integration name.
|
|
521
747
|
*
|
|
@@ -537,57 +763,80 @@ class IntegrationRenderer {
|
|
|
537
763
|
const integrationPlugin = this.appConfig.integrations.find(
|
|
538
764
|
(integration) => integration.name === integrationName
|
|
539
765
|
);
|
|
540
|
-
invariant(!!integrationPlugin, `[ecopages] Integration not found for
|
|
766
|
+
invariant(!!integrationPlugin, `[ecopages] Integration not found for boundary owner: ${integrationName}`);
|
|
541
767
|
const renderer = integrationPlugin.initializeRenderer({
|
|
542
768
|
rendererModules: this.appConfig.runtime?.rendererModuleContext
|
|
543
769
|
});
|
|
544
770
|
cache.set(integrationName, renderer);
|
|
545
771
|
return renderer;
|
|
546
772
|
}
|
|
773
|
+
async resolveBoundaryInOwningRenderer(input, rendererCache) {
|
|
774
|
+
const boundaryOwner = this.getRegisteredBoundaryOwner(input.component);
|
|
775
|
+
if (!boundaryOwner) {
|
|
776
|
+
return void 0;
|
|
777
|
+
}
|
|
778
|
+
return await this.getIntegrationRendererForName(boundaryOwner, rendererCache).renderComponentBoundary(
|
|
779
|
+
this.withBoundaryRendererCache(input, rendererCache)
|
|
780
|
+
);
|
|
781
|
+
}
|
|
547
782
|
/**
|
|
548
|
-
* Renders one
|
|
549
|
-
*
|
|
550
|
-
* graph is being resolved bottom-up.
|
|
783
|
+
* Renders one component under this integration's boundary runtime and resolves
|
|
784
|
+
* any nested foreign boundaries captured during that render.
|
|
551
785
|
*
|
|
552
|
-
* Without this wrapper,
|
|
553
|
-
*
|
|
554
|
-
*
|
|
786
|
+
* Without this wrapper, a component tree with foreign-owned descendants would
|
|
787
|
+
* render them with no active boundary runtime, which bypasses the owning
|
|
788
|
+
* renderer's nested-boundary handoff.
|
|
555
789
|
*/
|
|
556
|
-
async
|
|
557
|
-
|
|
558
|
-
|
|
790
|
+
async renderComponentBoundary(input) {
|
|
791
|
+
const rendererCache = this.getBoundaryRendererCache(input.integrationContext) ?? /* @__PURE__ */ new Map();
|
|
792
|
+
const delegatedBoundaryRender = await this.resolveBoundaryInOwningRenderer(input, rendererCache);
|
|
793
|
+
if (delegatedBoundaryRender) {
|
|
794
|
+
return delegatedBoundaryRender;
|
|
795
|
+
}
|
|
796
|
+
const hasForeignBoundaries = this.hasForeignBoundaryDescendants(input.component);
|
|
797
|
+
const activeRenderContext = getComponentRenderContext();
|
|
798
|
+
if (!hasForeignBoundaries) {
|
|
799
|
+
if (!activeRenderContext || activeRenderContext.currentIntegration === this.name) {
|
|
800
|
+
return this.normalizeComponentBoundaryRender(await this.renderComponent(input));
|
|
801
|
+
}
|
|
802
|
+
const sameIntegrationExecution = await runWithComponentRenderContext(
|
|
803
|
+
{
|
|
804
|
+
currentIntegration: this.name
|
|
805
|
+
},
|
|
806
|
+
async () => this.renderComponent(input)
|
|
807
|
+
);
|
|
808
|
+
return this.normalizeComponentBoundaryRender(sameIntegrationExecution.value);
|
|
559
809
|
}
|
|
560
810
|
const execution = await runWithComponentRenderContext(
|
|
561
811
|
{
|
|
562
812
|
currentIntegration: this.name,
|
|
563
|
-
|
|
813
|
+
boundaryRuntime: this.createComponentBoundaryRuntime({
|
|
814
|
+
boundaryInput: input,
|
|
815
|
+
rendererCache
|
|
816
|
+
})
|
|
564
817
|
},
|
|
565
818
|
async () => this.renderComponent(input)
|
|
566
819
|
);
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
const parentInstanceId = input.integrationContext?.componentInstanceId;
|
|
575
|
-
const nestedResolution = await this.resolveMarkerGraphHtml({
|
|
576
|
-
html: execution.value.html,
|
|
577
|
-
componentsToResolve: [input.component],
|
|
578
|
-
graphContext: execution.graphContext,
|
|
579
|
-
instanceIdScope: parentInstanceId
|
|
580
|
-
});
|
|
581
|
-
return {
|
|
582
|
-
...execution.value,
|
|
583
|
-
html: nestedResolution.html,
|
|
584
|
-
assets: this.htmlTransformer.dedupeProcessedAssets([
|
|
585
|
-
...execution.value.assets ?? [],
|
|
586
|
-
...nestedResolution.assets
|
|
587
|
-
])
|
|
820
|
+
return this.normalizeComponentBoundaryRender(execution.value);
|
|
821
|
+
}
|
|
822
|
+
normalizeComponentBoundaryRender(result) {
|
|
823
|
+
const normalizedHtml = this.normalizeBoundaryArtifactHtml(result.html);
|
|
824
|
+
return normalizedHtml === result.html ? result : {
|
|
825
|
+
...result,
|
|
826
|
+
html: normalizedHtml
|
|
588
827
|
};
|
|
589
828
|
}
|
|
590
|
-
|
|
829
|
+
normalizeBoundaryArtifactHtml(html) {
|
|
830
|
+
return normalizeBoundaryArtifactHtml(html);
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Returns whether the component dependency tree crosses into another
|
|
834
|
+
* integration.
|
|
835
|
+
*
|
|
836
|
+
* This keeps boundary-runtime setup narrow: same-integration trees can render
|
|
837
|
+
* directly without paying the queue orchestration cost.
|
|
838
|
+
*/
|
|
839
|
+
hasForeignBoundaryDescendants(component) {
|
|
591
840
|
const stack = [component];
|
|
592
841
|
const seen = /* @__PURE__ */ new Set();
|
|
593
842
|
while (stack.length > 0) {
|
|
@@ -610,7 +859,7 @@ class IntegrationRenderer {
|
|
|
610
859
|
* Default behavior delegates to `renderToResponse` in partial mode and wraps
|
|
611
860
|
* the resulting HTML into the `ComponentRenderResult` contract.
|
|
612
861
|
*
|
|
613
|
-
* In
|
|
862
|
+
* In boundary resolution, this method is the integration-owned step that turns an
|
|
614
863
|
* already-resolved deferred boundary into concrete HTML, assets, and optional
|
|
615
864
|
* root attributes.
|
|
616
865
|
*
|
|
@@ -618,7 +867,7 @@ class IntegrationRenderer {
|
|
|
618
867
|
* root attributes, integration-specific hydration metadata).
|
|
619
868
|
*
|
|
620
869
|
* @param input Component render request.
|
|
621
|
-
* @returns Structured render result used by
|
|
870
|
+
* @returns Structured render result used by component/page orchestration.
|
|
622
871
|
*/
|
|
623
872
|
async renderComponent(input) {
|
|
624
873
|
const response = await this.renderToResponse(
|
|
@@ -655,46 +904,41 @@ class IntegrationRenderer {
|
|
|
655
904
|
return void 0;
|
|
656
905
|
}
|
|
657
906
|
/**
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
* `eco.component()` consumes this facade without knowing about integration
|
|
662
|
-
* registries or plugin instances.
|
|
907
|
+
* Creates the per-render boundary runtime adopted by the shared component
|
|
908
|
+
* render context.
|
|
663
909
|
*
|
|
664
|
-
*
|
|
910
|
+
* Real mixed-integration renderers should override this and keep foreign
|
|
911
|
+
* boundary resolution inside their own renderer-owned queue. The base runtime
|
|
912
|
+
* fails fast when a renderer crosses into a foreign owner without providing its
|
|
913
|
+
* own handoff mechanism.
|
|
665
914
|
*/
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
915
|
+
createComponentBoundaryRuntime(_options) {
|
|
916
|
+
const decideBoundaryInterception = (input) => {
|
|
917
|
+
if (!this.shouldResolveBoundaryInOwningRenderer(input)) {
|
|
918
|
+
return { kind: "inline" };
|
|
919
|
+
}
|
|
920
|
+
throw new Error(
|
|
921
|
+
`[ecopages] ${this.name} renderer crossed into ${input.targetIntegration} without a renderer-owned boundary runtime. Override createComponentBoundaryRuntime() to resolve foreign boundaries inside the owning renderer.`
|
|
922
|
+
);
|
|
923
|
+
};
|
|
924
|
+
const runtime = {
|
|
925
|
+
interceptBoundary: decideBoundaryInterception,
|
|
926
|
+
interceptBoundarySync: decideBoundaryInterception
|
|
669
927
|
};
|
|
928
|
+
return runtime;
|
|
670
929
|
}
|
|
671
930
|
/**
|
|
672
|
-
* Resolves whether a
|
|
673
|
-
*
|
|
931
|
+
* Resolves whether a boundary should leave the current render pass and be
|
|
932
|
+
* resolved by its owning renderer.
|
|
674
933
|
*
|
|
675
|
-
* Boundaries
|
|
676
|
-
*
|
|
677
|
-
* `shouldDeferComponentBoundary()` policy.
|
|
934
|
+
* Boundaries owned by the current integration always render inline. Foreign-
|
|
935
|
+
* owned boundaries must be handed off by a renderer-owned runtime.
|
|
678
936
|
*
|
|
679
937
|
* @param input Boundary metadata for the active render pass.
|
|
680
|
-
* @returns `true` when the boundary should
|
|
938
|
+
* @returns `true` when the boundary should leave the current pass; otherwise `false`.
|
|
681
939
|
*/
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
return false;
|
|
685
|
-
}
|
|
686
|
-
const targetIntegration = this.appConfig.integrations.find(
|
|
687
|
-
(integration) => integration.name === input.targetIntegration
|
|
688
|
-
);
|
|
689
|
-
invariant(
|
|
690
|
-
!!targetIntegration,
|
|
691
|
-
`[ecopages] Integration not found for component boundary: ${input.targetIntegration}`
|
|
692
|
-
);
|
|
693
|
-
return targetIntegration.shouldDeferComponentBoundary({
|
|
694
|
-
currentIntegration: input.currentIntegration,
|
|
695
|
-
targetIntegration: input.targetIntegration,
|
|
696
|
-
component: input.component
|
|
697
|
-
});
|
|
940
|
+
shouldResolveBoundaryInOwningRenderer(input) {
|
|
941
|
+
return !!input.targetIntegration && input.targetIntegration !== input.currentIntegration;
|
|
698
942
|
}
|
|
699
943
|
}
|
|
700
944
|
export {
|