@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
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ProcessedAsset } from '../../services/assets/asset-processing-service/index.js';
|
|
2
|
+
import type { ComponentRenderInput, ComponentRenderResult, EcoComponent } from '../../types/public-types.js';
|
|
3
|
+
import type { ComponentBoundaryRuntime } from './component-render-context.js';
|
|
4
|
+
export type QueuedBoundaryDecisionInput = {
|
|
5
|
+
currentIntegration: string;
|
|
6
|
+
targetIntegration?: string;
|
|
7
|
+
component: EcoComponent;
|
|
8
|
+
props: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
export type QueuedBoundaryResolution = {
|
|
11
|
+
token: string;
|
|
12
|
+
component: EcoComponent;
|
|
13
|
+
props: Record<string, unknown>;
|
|
14
|
+
componentInstanceId: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Shared mutable state for one renderer-owned queued boundary runtime.
|
|
18
|
+
*
|
|
19
|
+
* Renderers that cannot resolve foreign boundaries inline can enqueue transport
|
|
20
|
+
* tokens during their initial render, then resolve those tokens against the
|
|
21
|
+
* owning renderer before returning final HTML.
|
|
22
|
+
*/
|
|
23
|
+
export type QueuedBoundaryRuntimeContext = {
|
|
24
|
+
rendererCache: Map<string, unknown>;
|
|
25
|
+
componentInstanceScope?: string;
|
|
26
|
+
nextBoundaryId: number;
|
|
27
|
+
queuedResolutions: QueuedBoundaryResolution[];
|
|
28
|
+
};
|
|
29
|
+
type QueuedBoundaryIntegrationContext = {
|
|
30
|
+
rendererCache?: Map<string, unknown>;
|
|
31
|
+
componentInstanceId?: string;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
};
|
|
34
|
+
type QueuedBoundaryChildRenderResult = {
|
|
35
|
+
assets: ProcessedAsset[];
|
|
36
|
+
html?: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Shared queue orchestration for renderer-owned boundary runtimes that emit
|
|
40
|
+
* temporary transport tokens during one render pass.
|
|
41
|
+
*
|
|
42
|
+
* The service keeps three responsibilities in one place:
|
|
43
|
+
* - storing per-render queue state on the active integration context
|
|
44
|
+
* - creating a `ComponentBoundaryRuntime` that enqueues foreign boundaries
|
|
45
|
+
* - resolving queued tokens back through the owning renderer before final HTML
|
|
46
|
+
* leaves the current renderer
|
|
47
|
+
*
|
|
48
|
+
* Renderers still own framework-specific child rendering. This service only
|
|
49
|
+
* handles queue bookkeeping, recursion, cycle detection, and asset merging.
|
|
50
|
+
*/
|
|
51
|
+
export declare class QueuedBoundaryRuntimeService {
|
|
52
|
+
/**
|
|
53
|
+
* Reads the queued boundary runtime state previously attached to one render.
|
|
54
|
+
*/
|
|
55
|
+
getRuntimeContext<TContext extends QueuedBoundaryRuntimeContext>(input: ComponentRenderInput, runtimeContextKey: string): TContext | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Creates the runtime hook used by `runWithComponentRenderContext()` for one
|
|
58
|
+
* renderer-owned queue.
|
|
59
|
+
*
|
|
60
|
+
* When the renderer decides a boundary must be handed off, the runtime returns
|
|
61
|
+
* a resolved transport token instead of rendering the foreign component inline.
|
|
62
|
+
*/
|
|
63
|
+
createRuntime<TContext extends QueuedBoundaryRuntimeContext>(options: {
|
|
64
|
+
boundaryInput: ComponentRenderInput;
|
|
65
|
+
rendererCache: Map<string, unknown>;
|
|
66
|
+
runtimeContextKey: string;
|
|
67
|
+
tokenPrefix: string;
|
|
68
|
+
shouldQueueBoundary: (input: QueuedBoundaryDecisionInput) => boolean;
|
|
69
|
+
createRuntimeContext?: (integrationContext: QueuedBoundaryIntegrationContext, rendererCache: Map<string, unknown>) => TContext;
|
|
70
|
+
}): ComponentBoundaryRuntime;
|
|
71
|
+
/**
|
|
72
|
+
* Resolves every queued transport token in one renderer-owned HTML fragment.
|
|
73
|
+
*
|
|
74
|
+
* The caller supplies framework-specific child rendering, while this service
|
|
75
|
+
* handles recursive token replacement, cycle detection, root-attribute
|
|
76
|
+
* application, and merged asset collection.
|
|
77
|
+
*/
|
|
78
|
+
resolveQueuedHtml<TContext extends QueuedBoundaryRuntimeContext>(options: {
|
|
79
|
+
html: string;
|
|
80
|
+
runtimeContext?: TContext;
|
|
81
|
+
queueLabel: string;
|
|
82
|
+
renderQueuedChildren: (children: unknown, runtimeContext: TContext, queuedResolutionsByToken: Map<string, QueuedBoundaryResolution>, resolveToken: (token: string) => Promise<string>) => Promise<QueuedBoundaryChildRenderResult>;
|
|
83
|
+
resolveBoundary: (input: ComponentRenderInput, rendererCache: Map<string, unknown>) => Promise<ComponentRenderResult | undefined>;
|
|
84
|
+
applyAttributesToFirstElement: (html: string, attributes: Record<string, string>) => string;
|
|
85
|
+
dedupeProcessedAssets: (assets: ProcessedAsset[]) => ProcessedAsset[];
|
|
86
|
+
}): Promise<{
|
|
87
|
+
assets: ProcessedAsset[];
|
|
88
|
+
html: string;
|
|
89
|
+
}>;
|
|
90
|
+
private createBoundaryToken;
|
|
91
|
+
private ensureRuntimeContext;
|
|
92
|
+
}
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
class QueuedBoundaryRuntimeService {
|
|
2
|
+
/**
|
|
3
|
+
* Reads the queued boundary runtime state previously attached to one render.
|
|
4
|
+
*/
|
|
5
|
+
getRuntimeContext(input, runtimeContextKey) {
|
|
6
|
+
const integrationContext = input.integrationContext;
|
|
7
|
+
const runtimeContext = integrationContext?.[runtimeContextKey];
|
|
8
|
+
if (typeof runtimeContext !== "object" || runtimeContext === null) {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
return runtimeContext;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates the runtime hook used by `runWithComponentRenderContext()` for one
|
|
15
|
+
* renderer-owned queue.
|
|
16
|
+
*
|
|
17
|
+
* When the renderer decides a boundary must be handed off, the runtime returns
|
|
18
|
+
* a resolved transport token instead of rendering the foreign component inline.
|
|
19
|
+
*/
|
|
20
|
+
createRuntime(options) {
|
|
21
|
+
const runtimeContext = this.ensureRuntimeContext(options);
|
|
22
|
+
const interceptBoundary = (input) => {
|
|
23
|
+
if (!options.shouldQueueBoundary(input)) {
|
|
24
|
+
return { kind: "inline" };
|
|
25
|
+
}
|
|
26
|
+
runtimeContext.nextBoundaryId += 1;
|
|
27
|
+
const boundaryId = runtimeContext.nextBoundaryId;
|
|
28
|
+
const token = this.createBoundaryToken(options.tokenPrefix, runtimeContext, boundaryId);
|
|
29
|
+
runtimeContext.queuedResolutions.push({
|
|
30
|
+
token,
|
|
31
|
+
component: input.component,
|
|
32
|
+
props: { ...input.props },
|
|
33
|
+
componentInstanceId: runtimeContext.componentInstanceScope ? `${runtimeContext.componentInstanceScope}_n_${boundaryId}` : `n_${boundaryId}`
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
kind: "resolved",
|
|
37
|
+
value: token
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
interceptBoundary,
|
|
42
|
+
interceptBoundarySync: interceptBoundary
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resolves every queued transport token in one renderer-owned HTML fragment.
|
|
47
|
+
*
|
|
48
|
+
* The caller supplies framework-specific child rendering, while this service
|
|
49
|
+
* handles recursive token replacement, cycle detection, root-attribute
|
|
50
|
+
* application, and merged asset collection.
|
|
51
|
+
*/
|
|
52
|
+
async resolveQueuedHtml(options) {
|
|
53
|
+
if (!options.runtimeContext || options.runtimeContext.queuedResolutions.length === 0) {
|
|
54
|
+
return { assets: [], html: options.html };
|
|
55
|
+
}
|
|
56
|
+
const runtimeContext = options.runtimeContext;
|
|
57
|
+
const queuedResolutionsByToken = new Map(
|
|
58
|
+
runtimeContext.queuedResolutions.map((resolution) => [resolution.token, resolution])
|
|
59
|
+
);
|
|
60
|
+
const resolvedHtmlByToken = /* @__PURE__ */ new Map();
|
|
61
|
+
const resolvingTokens = /* @__PURE__ */ new Set();
|
|
62
|
+
const collectedAssets = [];
|
|
63
|
+
const resolveToken = async (token) => {
|
|
64
|
+
const cachedHtml = resolvedHtmlByToken.get(token);
|
|
65
|
+
if (cachedHtml) {
|
|
66
|
+
return cachedHtml;
|
|
67
|
+
}
|
|
68
|
+
const resolution = queuedResolutionsByToken.get(token);
|
|
69
|
+
if (!resolution) {
|
|
70
|
+
return token;
|
|
71
|
+
}
|
|
72
|
+
if (resolvingTokens.has(token)) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`[ecopages] ${options.queueLabel} boundary queue contains a cycle or unresolved dependency links.`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
resolvingTokens.add(token);
|
|
78
|
+
try {
|
|
79
|
+
const renderedChildren = await options.renderQueuedChildren(
|
|
80
|
+
resolution.props.children,
|
|
81
|
+
runtimeContext,
|
|
82
|
+
queuedResolutionsByToken,
|
|
83
|
+
resolveToken
|
|
84
|
+
);
|
|
85
|
+
if (renderedChildren.assets.length > 0) {
|
|
86
|
+
collectedAssets.push(...renderedChildren.assets);
|
|
87
|
+
}
|
|
88
|
+
const boundaryRender = await options.resolveBoundary(
|
|
89
|
+
{
|
|
90
|
+
component: resolution.component,
|
|
91
|
+
props: { ...resolution.props },
|
|
92
|
+
children: renderedChildren.html,
|
|
93
|
+
integrationContext: {
|
|
94
|
+
rendererCache: runtimeContext.rendererCache,
|
|
95
|
+
componentInstanceId: resolution.componentInstanceId
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
runtimeContext.rendererCache
|
|
99
|
+
);
|
|
100
|
+
if (!boundaryRender) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`[ecopages] ${options.queueLabel} queued boundary could not resolve its owning renderer.`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if ((boundaryRender.assets?.length ?? 0) > 0) {
|
|
106
|
+
collectedAssets.push(...boundaryRender.assets ?? []);
|
|
107
|
+
}
|
|
108
|
+
const resolvedHtml2 = boundaryRender.canAttachAttributes && boundaryRender.rootAttributes ? options.applyAttributesToFirstElement(boundaryRender.html, boundaryRender.rootAttributes) : boundaryRender.html;
|
|
109
|
+
resolvedHtmlByToken.set(token, resolvedHtml2);
|
|
110
|
+
return resolvedHtml2;
|
|
111
|
+
} finally {
|
|
112
|
+
resolvingTokens.delete(token);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
let resolvedHtml = options.html;
|
|
116
|
+
for (const resolution of runtimeContext.queuedResolutions) {
|
|
117
|
+
if (!resolvedHtml.includes(resolution.token)) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
resolvedHtml = resolvedHtml.split(resolution.token).join(await resolveToken(resolution.token));
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
assets: options.dedupeProcessedAssets(collectedAssets),
|
|
124
|
+
html: resolvedHtml
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
createBoundaryToken(tokenPrefix, runtimeContext, boundaryId) {
|
|
128
|
+
return `${tokenPrefix}${runtimeContext.componentInstanceScope ?? "root"}__${boundaryId}__`;
|
|
129
|
+
}
|
|
130
|
+
ensureRuntimeContext(options) {
|
|
131
|
+
let integrationContext;
|
|
132
|
+
if (typeof options.boundaryInput.integrationContext === "object" && options.boundaryInput.integrationContext !== null) {
|
|
133
|
+
integrationContext = options.boundaryInput.integrationContext;
|
|
134
|
+
} else {
|
|
135
|
+
integrationContext = {};
|
|
136
|
+
}
|
|
137
|
+
const existingRuntimeContext = integrationContext[options.runtimeContextKey];
|
|
138
|
+
if (typeof existingRuntimeContext !== "object" || existingRuntimeContext === null) {
|
|
139
|
+
integrationContext[options.runtimeContextKey] = options.createRuntimeContext?.(integrationContext, options.rendererCache) ?? {
|
|
140
|
+
rendererCache: options.rendererCache,
|
|
141
|
+
componentInstanceScope: integrationContext.componentInstanceId,
|
|
142
|
+
nextBoundaryId: 0,
|
|
143
|
+
queuedResolutions: []
|
|
144
|
+
};
|
|
145
|
+
} else {
|
|
146
|
+
existingRuntimeContext.rendererCache = options.rendererCache;
|
|
147
|
+
}
|
|
148
|
+
integrationContext.rendererCache = options.rendererCache;
|
|
149
|
+
options.boundaryInput.integrationContext = integrationContext;
|
|
150
|
+
return integrationContext[options.runtimeContextKey];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
QueuedBoundaryRuntimeService
|
|
155
|
+
};
|
|
@@ -1,73 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { EcoComponent, IntegrationRendererRenderOptions, RouteRendererBody, RouteRendererOptions, RouteRenderResult } from '../../types/public-types.js';
|
|
3
|
-
import type { ProcessedAsset } from '../../services/assets/asset-processing-service/index.js';
|
|
4
|
-
import type { MarkerGraphContext } from '../component-graph/marker-graph-resolver.js';
|
|
5
|
-
/**
|
|
6
|
-
* Serializable graph context merged from render-time captured references and
|
|
7
|
-
* optional explicit page-module graph metadata.
|
|
8
|
-
*/
|
|
9
|
-
export type RenderExecutionGraphContext = {
|
|
10
|
-
propsByRef?: Record<string, Record<string, unknown>>;
|
|
11
|
-
slotChildrenByRef?: MarkerGraphContext['slotChildrenByRef'];
|
|
12
|
-
};
|
|
1
|
+
import type { IntegrationRendererRenderOptions, RouteRendererBody, RouteRendererOptions, RouteRenderResult } from '../../types/public-types.js';
|
|
13
2
|
export interface CapturedHtmlRenderResult {
|
|
14
3
|
body: RouteRendererBody;
|
|
15
4
|
html: string;
|
|
16
|
-
graphContext: RenderExecutionGraphContext;
|
|
17
5
|
}
|
|
18
6
|
export interface FinalizeHtmlRenderOptions {
|
|
19
7
|
html: string;
|
|
20
|
-
graphContext: RenderExecutionGraphContext;
|
|
21
|
-
componentsToResolve: EcoComponent[];
|
|
22
8
|
componentRootAttributes?: Record<string, string>;
|
|
23
9
|
documentAttributes?: Record<string, string>;
|
|
24
|
-
mergeAssets?: boolean;
|
|
25
10
|
}
|
|
26
11
|
export interface RenderExecutionCallbacks<C> {
|
|
27
12
|
prepareRenderOptions(options: RouteRendererOptions): Promise<IntegrationRendererRenderOptions<C>>;
|
|
28
13
|
render(renderOptions: IntegrationRendererRenderOptions<C>): Promise<RouteRendererBody>;
|
|
29
|
-
getComponentRenderBoundaryContext(): ComponentRenderBoundaryContext;
|
|
30
14
|
getDocumentAttributes(renderOptions: IntegrationRendererRenderOptions<C>): Record<string, string> | undefined;
|
|
31
|
-
resolveMarkerGraphHtml(input: {
|
|
32
|
-
html: string;
|
|
33
|
-
componentsToResolve: EcoComponent[];
|
|
34
|
-
graphContext: RenderExecutionGraphContext;
|
|
35
|
-
}): Promise<{
|
|
36
|
-
html: string;
|
|
37
|
-
assets: ProcessedAsset[];
|
|
38
|
-
}>;
|
|
39
|
-
dedupeProcessedAssets(assets: ProcessedAsset[]): ProcessedAsset[];
|
|
40
|
-
getProcessedDependencies(): ProcessedAsset[];
|
|
41
|
-
setProcessedDependencies(dependencies: ProcessedAsset[]): void;
|
|
42
15
|
applyAttributesToHtmlElement(html: string, attributes: Record<string, string>): string;
|
|
43
16
|
applyAttributesToFirstBodyElement(html: string, attributes: Record<string, string>): string;
|
|
44
17
|
transformResponse(response: Response): Promise<RouteRendererBody>;
|
|
45
18
|
}
|
|
46
|
-
export interface FinalizeHtmlRenderCallbacks {
|
|
47
|
-
resolveMarkerGraphHtml(input: {
|
|
48
|
-
html: string;
|
|
49
|
-
componentsToResolve: EcoComponent[];
|
|
50
|
-
graphContext: RenderExecutionGraphContext;
|
|
51
|
-
}): Promise<{
|
|
52
|
-
html: string;
|
|
53
|
-
assets: ProcessedAsset[];
|
|
54
|
-
}>;
|
|
55
|
-
dedupeProcessedAssets(assets: ProcessedAsset[]): ProcessedAsset[];
|
|
56
|
-
getProcessedDependencies(): ProcessedAsset[];
|
|
57
|
-
setProcessedDependencies(dependencies: ProcessedAsset[]): void;
|
|
58
|
-
applyAttributesToHtmlElement(html: string, attributes: Record<string, string>): string;
|
|
59
|
-
applyAttributesToFirstBodyElement(html: string, attributes: Record<string, string>): string;
|
|
60
|
-
}
|
|
61
19
|
/**
|
|
62
20
|
* Executes the main post-preparation rendering flow for integration renderers.
|
|
63
21
|
*
|
|
64
22
|
* This service owns the orchestration that happens after normalized render
|
|
65
|
-
* options have been prepared:
|
|
66
|
-
*
|
|
67
|
-
*
|
|
23
|
+
* options have been prepared: one render pass, unresolved boundary-marker
|
|
24
|
+
* enforcement, root-attribute application, and final HTML transformation into
|
|
25
|
+
* a response body stream.
|
|
68
26
|
*/
|
|
69
27
|
export declare class RenderExecutionService {
|
|
70
|
-
captureHtmlRender(
|
|
28
|
+
captureHtmlRender(render: () => Promise<RouteRendererBody>): Promise<CapturedHtmlRenderResult>;
|
|
71
29
|
/**
|
|
72
30
|
* Executes one integration render pass and returns the final route render
|
|
73
31
|
* result.
|
|
@@ -78,28 +36,8 @@ export declare class RenderExecutionService {
|
|
|
78
36
|
* @param callbacks Renderer-specific hooks required during execution.
|
|
79
37
|
* @returns Final route render output with body and cache strategy.
|
|
80
38
|
*/
|
|
81
|
-
execute<C = unknown>(options: RouteRendererOptions,
|
|
39
|
+
execute<C = unknown>(options: RouteRendererOptions, callbacks: RenderExecutionCallbacks<C>): Promise<RouteRenderResult>;
|
|
82
40
|
private captureRenderedBody;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* provided by the page module.
|
|
86
|
-
*
|
|
87
|
-
* @param capturedGraphContext Graph context captured from the first render pass.
|
|
88
|
-
* @param explicitGraphContext Optional page-module graph metadata.
|
|
89
|
-
* @returns Merged graph context used during marker resolution.
|
|
90
|
-
*/
|
|
91
|
-
mergeGraphContext(capturedGraphContext: RenderExecutionGraphContext, explicitGraphContext?: RenderExecutionGraphContext): RenderExecutionGraphContext;
|
|
92
|
-
finalizeHtmlRender(options: FinalizeHtmlRenderOptions, callbacks: FinalizeHtmlRenderCallbacks): Promise<{
|
|
93
|
-
html: string;
|
|
94
|
-
assets: ProcessedAsset[];
|
|
95
|
-
}>;
|
|
96
|
-
/**
|
|
97
|
-
* Returns the component set that participates in marker graph resolution for a
|
|
98
|
-
* render pass.
|
|
99
|
-
*
|
|
100
|
-
* @typeParam C Integration render output element type.
|
|
101
|
-
* @param renderOptions Normalized render options for the pass.
|
|
102
|
-
* @returns Ordered component list for graph registry construction.
|
|
103
|
-
*/
|
|
104
|
-
private getComponentsToResolve;
|
|
41
|
+
finalizeHtmlRender(options: FinalizeHtmlRenderOptions, callbacks: Pick<RenderExecutionCallbacks<unknown>, 'applyAttributesToHtmlElement' | 'applyAttributesToFirstBodyElement'>): Promise<string>;
|
|
42
|
+
private applyFinalHtmlAttributes;
|
|
105
43
|
}
|
|
@@ -1,38 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
runWithComponentRenderContext
|
|
3
|
-
} from "../../eco/component-render-context.js";
|
|
4
|
-
function decodeHtmlEntities(value) {
|
|
5
|
-
let decoded = value;
|
|
6
|
-
let previous;
|
|
7
|
-
do {
|
|
8
|
-
previous = decoded;
|
|
9
|
-
decoded = decoded.replaceAll(""", '"').replaceAll("'", "'").replaceAll("'", "'").replaceAll("<", "<").replaceAll(">", ">").replaceAll("&", "&");
|
|
10
|
-
} while (decoded !== previous);
|
|
11
|
-
return decoded;
|
|
12
|
-
}
|
|
13
|
-
function restoreEscapedComponentMarkers(html) {
|
|
14
|
-
return html.replace(
|
|
15
|
-
/&(?:amp;)?lt;eco-marker\b[\s\S]*?&(?:amp;)?gt;&(?:amp;)?lt;\/eco-marker&(?:amp;)?gt;/g,
|
|
16
|
-
(marker) => decodeHtmlEntities(marker)
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
const MAX_MARKER_RESOLUTION_PASSES = 10;
|
|
1
|
+
import { inspectBoundaryArtifactHtml } from "./render-output.utils.js";
|
|
20
2
|
class RenderExecutionService {
|
|
21
|
-
async captureHtmlRender(
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
currentIntegration: currentIntegrationName,
|
|
25
|
-
boundaryContext
|
|
26
|
-
},
|
|
27
|
-
async () => {
|
|
28
|
-
const renderedBody = await render();
|
|
29
|
-
return await this.captureRenderedBody(renderedBody);
|
|
30
|
-
}
|
|
31
|
-
);
|
|
3
|
+
async captureHtmlRender(render) {
|
|
4
|
+
const renderedBody = await render();
|
|
5
|
+
const capturedRender = await this.captureRenderedBody(renderedBody);
|
|
32
6
|
return {
|
|
33
|
-
body:
|
|
34
|
-
html:
|
|
35
|
-
graphContext: renderExecution.graphContext
|
|
7
|
+
body: capturedRender.body,
|
|
8
|
+
html: capturedRender.html
|
|
36
9
|
};
|
|
37
10
|
}
|
|
38
11
|
/**
|
|
@@ -45,17 +18,19 @@ class RenderExecutionService {
|
|
|
45
18
|
* @param callbacks Renderer-specific hooks required during execution.
|
|
46
19
|
* @returns Final route render output with body and cache strategy.
|
|
47
20
|
*/
|
|
48
|
-
async execute(options,
|
|
21
|
+
async execute(options, callbacks) {
|
|
49
22
|
const renderOptions = await callbacks.prepareRenderOptions(options);
|
|
50
23
|
const shouldApplyComponentRootAttributes = renderOptions.componentRender?.canAttachAttributes && renderOptions.componentRender.rootAttributes && Object.keys(renderOptions.componentRender.rootAttributes).length > 0;
|
|
51
|
-
const renderExecution = await this.captureHtmlRender(
|
|
52
|
-
|
|
53
|
-
callbacks.getComponentRenderBoundaryContext(),
|
|
54
|
-
async () => callbacks.render(renderOptions)
|
|
55
|
-
);
|
|
56
|
-
const normalizedCapturedHtml = restoreEscapedComponentMarkers(renderExecution.html);
|
|
24
|
+
const renderExecution = await this.captureHtmlRender(async () => callbacks.render(renderOptions));
|
|
25
|
+
const boundaryArtifacts = inspectBoundaryArtifactHtml(renderExecution.html);
|
|
57
26
|
const documentAttributes = callbacks.getDocumentAttributes(renderOptions);
|
|
58
|
-
const
|
|
27
|
+
const hasBoundaryMarkerHtml = boundaryArtifacts.hasUnresolvedBoundaryArtifacts;
|
|
28
|
+
if (hasBoundaryMarkerHtml) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"[ecopages] Route render returned unresolved boundary artifact HTML. Full-route unresolved-boundary fallback has been removed; resolve mixed boundaries inside renderComponentBoundary()."
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
const canReuseCapturedBody = !hasBoundaryMarkerHtml && !shouldApplyComponentRootAttributes && !(documentAttributes && Object.keys(documentAttributes).length > 0);
|
|
59
34
|
if (canReuseCapturedBody) {
|
|
60
35
|
const body2 = await callbacks.transformResponse(
|
|
61
36
|
new Response(renderExecution.body, {
|
|
@@ -69,23 +44,19 @@ class RenderExecutionService {
|
|
|
69
44
|
cacheStrategy: renderOptions.cacheStrategy
|
|
70
45
|
};
|
|
71
46
|
}
|
|
72
|
-
const componentGraphContext = this.mergeGraphContext(
|
|
73
|
-
renderExecution.graphContext,
|
|
74
|
-
renderOptions.componentGraphContext
|
|
75
|
-
);
|
|
76
47
|
const finalization = await this.finalizeHtmlRender(
|
|
77
48
|
{
|
|
78
|
-
html:
|
|
79
|
-
graphContext: componentGraphContext,
|
|
80
|
-
componentsToResolve: this.getComponentsToResolve(renderOptions),
|
|
49
|
+
html: boundaryArtifacts.normalizedHtml,
|
|
81
50
|
componentRootAttributes: shouldApplyComponentRootAttributes ? renderOptions.componentRender?.rootAttributes : void 0,
|
|
82
|
-
documentAttributes
|
|
83
|
-
mergeAssets: true
|
|
51
|
+
documentAttributes
|
|
84
52
|
},
|
|
85
|
-
|
|
53
|
+
{
|
|
54
|
+
applyAttributesToHtmlElement: callbacks.applyAttributesToHtmlElement,
|
|
55
|
+
applyAttributesToFirstBodyElement: callbacks.applyAttributesToFirstBodyElement
|
|
56
|
+
}
|
|
86
57
|
);
|
|
87
58
|
const body = await callbacks.transformResponse(
|
|
88
|
-
new Response(finalization
|
|
59
|
+
new Response(finalization, {
|
|
89
60
|
headers: {
|
|
90
61
|
"Content-Type": "text/html"
|
|
91
62
|
}
|
|
@@ -116,74 +87,18 @@ class RenderExecutionService {
|
|
|
116
87
|
html: await new Response(capturedBody).text()
|
|
117
88
|
};
|
|
118
89
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Merges captured render-time graph references with any explicit graph context
|
|
121
|
-
* provided by the page module.
|
|
122
|
-
*
|
|
123
|
-
* @param capturedGraphContext Graph context captured from the first render pass.
|
|
124
|
-
* @param explicitGraphContext Optional page-module graph metadata.
|
|
125
|
-
* @returns Merged graph context used during marker resolution.
|
|
126
|
-
*/
|
|
127
|
-
mergeGraphContext(capturedGraphContext, explicitGraphContext) {
|
|
128
|
-
return {
|
|
129
|
-
propsByRef: {
|
|
130
|
-
...capturedGraphContext.propsByRef ?? {},
|
|
131
|
-
...explicitGraphContext?.propsByRef ?? {}
|
|
132
|
-
},
|
|
133
|
-
slotChildrenByRef: {
|
|
134
|
-
...capturedGraphContext.slotChildrenByRef ?? {},
|
|
135
|
-
...explicitGraphContext?.slotChildrenByRef ?? {}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
90
|
async finalizeHtmlRender(options, callbacks) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
const markerResolution = await callbacks.resolveMarkerGraphHtml({
|
|
147
|
-
html: renderedHtml,
|
|
148
|
-
componentsToResolve: options.componentsToResolve,
|
|
149
|
-
graphContext: options.graphContext
|
|
150
|
-
});
|
|
151
|
-
const resolvedHtml = restoreEscapedComponentMarkers(markerResolution.html);
|
|
152
|
-
markerAssets = callbacks.dedupeProcessedAssets([...markerAssets, ...markerResolution.assets]);
|
|
153
|
-
if (options.mergeAssets !== false && markerResolution.assets.length > 0) {
|
|
154
|
-
const mergedDependencies = callbacks.dedupeProcessedAssets([
|
|
155
|
-
...callbacks.getProcessedDependencies(),
|
|
156
|
-
...markerResolution.assets
|
|
157
|
-
]);
|
|
158
|
-
callbacks.setProcessedDependencies(mergedDependencies);
|
|
159
|
-
}
|
|
160
|
-
if (resolvedHtml === renderedHtml) {
|
|
161
|
-
renderedHtml = resolvedHtml;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
renderedHtml = resolvedHtml;
|
|
165
|
-
}
|
|
91
|
+
return this.applyFinalHtmlAttributes(options.html, options, callbacks);
|
|
92
|
+
}
|
|
93
|
+
applyFinalHtmlAttributes(html, options, callbacks) {
|
|
94
|
+
let renderedHtml = html;
|
|
166
95
|
if (options.componentRootAttributes && Object.keys(options.componentRootAttributes).length > 0) {
|
|
167
96
|
renderedHtml = callbacks.applyAttributesToFirstBodyElement(renderedHtml, options.componentRootAttributes);
|
|
168
97
|
}
|
|
169
98
|
if (options.documentAttributes && Object.keys(options.documentAttributes).length > 0) {
|
|
170
99
|
renderedHtml = callbacks.applyAttributesToHtmlElement(renderedHtml, options.documentAttributes);
|
|
171
100
|
}
|
|
172
|
-
return
|
|
173
|
-
html: renderedHtml,
|
|
174
|
-
assets: markerAssets
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Returns the component set that participates in marker graph resolution for a
|
|
179
|
-
* render pass.
|
|
180
|
-
*
|
|
181
|
-
* @typeParam C Integration render output element type.
|
|
182
|
-
* @param renderOptions Normalized render options for the pass.
|
|
183
|
-
* @returns Ordered component list for graph registry construction.
|
|
184
|
-
*/
|
|
185
|
-
getComponentsToResolve(renderOptions) {
|
|
186
|
-
return renderOptions.Layout ? [renderOptions.HtmlTemplate, renderOptions.Layout, renderOptions.Page] : [renderOptions.HtmlTemplate, renderOptions.Page];
|
|
101
|
+
return renderedHtml;
|
|
187
102
|
}
|
|
188
103
|
}
|
|
189
104
|
export {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { EcoComponent } from '../../types/public-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns `true` when `value` is a thenable (Promise-like) object.
|
|
4
|
+
*
|
|
5
|
+
* Used to transparently handle both synchronous and asynchronous component
|
|
6
|
+
* render results without requiring every caller to branch on `instanceof Promise`.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam T Expected resolved type of the thenable.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isThenable<T>(value: unknown): value is PromiseLike<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Injects `data-eco-trigger` into the first real HTML element opening tag of
|
|
13
|
+
* a component's rendered output string.
|
|
14
|
+
*
|
|
15
|
+
* The scan skips over leading whitespace, HTML comments (`<!-- -->`), CDATA
|
|
16
|
+
* sections, and doctype declarations so that the attribute is always placed on
|
|
17
|
+
* the first actual element — not spurious markup that can precede it.
|
|
18
|
+
*
|
|
19
|
+
* The insertion point is the end of the element's tag name, before any existing
|
|
20
|
+
* attributes or the closing `>`, which produces output like:
|
|
21
|
+
*
|
|
22
|
+
* ```html
|
|
23
|
+
* <my-element data-eco-trigger="eco-trigger-abc123" class="foo">…</my-element>
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* When no eligible opening tag is found the original string is returned
|
|
27
|
+
* unchanged so callers never receive a broken fragment.
|
|
28
|
+
*
|
|
29
|
+
* @param content Rendered HTML string (or any value coercible to string).
|
|
30
|
+
* @param triggerId Stable trigger identifier produced by `buildResolvedLazyTriggers`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function addTriggerAttribute(content: unknown, triggerId: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Wraps rendered component output in a `<scripts-injector>` element that
|
|
35
|
+
* carries an inline injector map for the legacy (non-global-injector) path.
|
|
36
|
+
*
|
|
37
|
+
* @param content Rendered component HTML.
|
|
38
|
+
* @param lazyGroups Resolved lazy script groups attached to the component config.
|
|
39
|
+
*/
|
|
40
|
+
export declare function wrapWithScriptsInjector(content: unknown, lazyGroups: NonNullable<EcoComponent['config']>['_resolvedLazyScripts']): string;
|
|
41
|
+
export declare function decodeHtmlEntities(value: string): string;
|
|
42
|
+
export declare function normalizeBoundaryArtifactHtml(html: string): string;
|
|
43
|
+
export declare function inspectBoundaryArtifactHtml(html: string): {
|
|
44
|
+
hasUnresolvedBoundaryArtifacts: boolean;
|
|
45
|
+
normalizedHtml: string;
|
|
46
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { buildInjectorMapScript } from "../../eco/lazy-injector-map.js";
|
|
2
|
+
function isThenable(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
4
|
+
}
|
|
5
|
+
function addTriggerAttribute(content, triggerId) {
|
|
6
|
+
const str = String(content);
|
|
7
|
+
let i = 0;
|
|
8
|
+
while (i < str.length) {
|
|
9
|
+
if (str[i] !== "<") {
|
|
10
|
+
i++;
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const next = str[i + 1];
|
|
14
|
+
if (next === "!" || next === "?") {
|
|
15
|
+
const end = str.indexOf(">", i);
|
|
16
|
+
if (end === -1) break;
|
|
17
|
+
i = end + 1;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (next && /[a-zA-Z]/.test(next)) {
|
|
21
|
+
const tagSlice = str.slice(i + 1);
|
|
22
|
+
const nameEnd = tagSlice.search(/[\s/>]/);
|
|
23
|
+
if (nameEnd === -1) break;
|
|
24
|
+
const insertAt = i + 1 + nameEnd;
|
|
25
|
+
return `${str.slice(0, insertAt)} data-eco-trigger="${triggerId}"${str.slice(insertAt)}`;
|
|
26
|
+
}
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
return str;
|
|
30
|
+
}
|
|
31
|
+
function wrapWithScriptsInjector(content, lazyGroups) {
|
|
32
|
+
const wrappedContent = String(content);
|
|
33
|
+
const injectorMapScript = buildInjectorMapScript(lazyGroups ?? []);
|
|
34
|
+
return `<scripts-injector><script type="ecopages/injector-map">${injectorMapScript}<\/script>${wrappedContent}<\/scripts-injector>`;
|
|
35
|
+
}
|
|
36
|
+
function decodeHtmlEntities(value) {
|
|
37
|
+
let decoded = value;
|
|
38
|
+
let previous;
|
|
39
|
+
do {
|
|
40
|
+
previous = decoded;
|
|
41
|
+
decoded = decoded.replaceAll(""", '"').replaceAll("'", "'").replaceAll("'", "'").replaceAll("<", "<").replaceAll(">", ">").replaceAll("&", "&");
|
|
42
|
+
} while (decoded !== previous);
|
|
43
|
+
return decoded;
|
|
44
|
+
}
|
|
45
|
+
function normalizeBoundaryArtifactHtml(html) {
|
|
46
|
+
return html.replace(
|
|
47
|
+
/&(?:amp;)?lt;eco-marker\b[\s\S]*?&(?:amp;)?gt;&(?:amp;)?lt;\/eco-marker&(?:amp;)?gt;/g,
|
|
48
|
+
(marker) => decodeHtmlEntities(marker)
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
function inspectBoundaryArtifactHtml(html) {
|
|
52
|
+
const normalizedHtml = normalizeBoundaryArtifactHtml(html);
|
|
53
|
+
return {
|
|
54
|
+
normalizedHtml,
|
|
55
|
+
hasUnresolvedBoundaryArtifacts: normalizedHtml.includes("<eco-marker")
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
addTriggerAttribute,
|
|
60
|
+
decodeHtmlEntities,
|
|
61
|
+
inspectBoundaryArtifactHtml,
|
|
62
|
+
isThenable,
|
|
63
|
+
normalizeBoundaryArtifactHtml,
|
|
64
|
+
wrapWithScriptsInjector
|
|
65
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { EcoPagesAppConfig } from '../../types/internal-types.js';
|
|
2
2
|
import type { ComponentRenderResult, EcoComponent, EcoPageComponent, EcoPageFile, EcoPagesElement, GetMetadata, GetStaticProps, HtmlTemplateProps, IntegrationRendererRenderOptions, PageMetadataProps, RouteRendererOptions } from '../../types/public-types.js';
|
|
3
3
|
import { type AssetProcessingService, type ProcessedAsset } from '../../services/assets/asset-processing-service/index.js';
|
|
4
|
-
import { type ComponentRenderBoundaryContext } from '../../eco/component-render-context.js';
|
|
5
4
|
type ResolvedPageModule = {
|
|
6
5
|
Page: EcoPageFile['default'] | EcoPageComponent<any>;
|
|
7
6
|
getStaticProps?: GetStaticProps<Record<string, unknown>>;
|
|
@@ -29,11 +28,6 @@ export interface RenderPreparationCallbacks {
|
|
|
29
28
|
component: EcoComponent;
|
|
30
29
|
props: Record<string, unknown>;
|
|
31
30
|
}): Promise<ComponentRenderResult>;
|
|
32
|
-
/**
|
|
33
|
-
* Returns the boundary policy context that should be active while rendering
|
|
34
|
-
* page-root component output during preparation.
|
|
35
|
-
*/
|
|
36
|
-
getComponentRenderBoundaryContext(): ComponentRenderBoundaryContext;
|
|
37
31
|
setProcessedDependencies(dependencies: ProcessedAsset[]): void;
|
|
38
32
|
dedupeProcessedAssets(assets: ProcessedAsset[]): ProcessedAsset[];
|
|
39
33
|
createPageLocalsProxy(filePath: string): RouteRendererOptions['locals'];
|