@ecopages/core 0.2.0-rc.6 → 0.2.0-rc.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +2 -0
  2. package/package.json +27 -3
  3. package/src/adapters/abstract/segment-path-matcher.js +56 -38
  4. package/src/adapters/bun/create-app.d.ts +4 -0
  5. package/src/adapters/bun/create-app.js +46 -31
  6. package/src/adapters/shared/runtime/server-adapter.d.ts +1 -0
  7. package/src/adapters/shared/runtime/server-adapter.js +9 -22
  8. package/src/build/rolldown/rolldown-adapter-helpers.js +41 -25
  9. package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
  10. package/src/declarations.d.ts +10 -1
  11. package/src/eco/README.md +3 -1
  12. package/src/eco/lazy-injector-map.js +57 -41
  13. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
  14. package/src/hmr/strategies/js-hmr-strategy.js +24 -16
  15. package/src/islands/README.md +5 -1
  16. package/src/plugins/component-import-discovery.js +115 -77
  17. package/src/plugins/eco-component-meta-plugin.js +47 -30
  18. package/src/route-renderer/README.md +3 -2
  19. package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
  20. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
  21. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
  22. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +68 -0
  23. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +183 -0
  24. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +9 -0
  25. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +22 -0
  26. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
  27. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
  28. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +7 -2
  29. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +2 -0
  30. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +3 -2
  31. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +1 -1
  32. package/src/route-renderer/orchestration/integration-renderer.d.ts +7 -3
  33. package/src/route-renderer/orchestration/integration-renderer.js +34 -20
  34. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +1 -1
  35. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -2
  36. package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
  37. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
  38. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
  39. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +3 -2
  40. package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
  41. package/src/route-renderer/orchestration/string-markup-renderer.js +2 -1
  42. package/src/route-renderer/page-loading/component-dependency-collection.js +95 -74
  43. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
  44. package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +0 -3
  45. package/src/route-renderer/page-loading/file-scoped-dependency-components.js +37 -34
  46. package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
  47. package/src/router/README.md +7 -1
  48. package/src/router/server/route-registry.d.ts +13 -0
  49. package/src/router/server/route-registry.js +46 -32
  50. package/src/services/README.md +2 -0
  51. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +6 -0
  52. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +24 -5
  53. package/src/services/assets/asset-processing-service/page-package.js +42 -39
  54. package/src/services/module-loading/page-module-import.service.d.ts +6 -0
  55. package/src/services/module-loading/page-module-import.service.js +60 -27
  56. package/src/services/validation/schema-validation-service.d.ts +1 -0
  57. package/src/services/validation/schema-validation-service.js +23 -36
  58. package/src/static-site-generator/static-site-generator.d.ts +4 -0
  59. package/src/static-site-generator/static-site-generator.js +75 -48
  60. package/src/types/internal-types.d.ts +5 -1
  61. package/src/utils/parse-cli-args.js +29 -22
  62. package/src/watchers/project-watcher.d.ts +5 -0
  63. package/src/watchers/project-watcher.js +46 -32
@@ -0,0 +1,68 @@
1
+ import type { EcoComponent } from '../../../types/public-types.js';
2
+ import { invalidateCustomElementScriptPreload } from './custom-element-script-preload-invalidation.js';
3
+ export { invalidateCustomElementScriptPreload };
4
+ export type CustomElementSsrPreloadComponent = EcoComponent | Partial<EcoComponent>;
5
+ export declare const CUSTOM_ELEMENT_SSR_PRELOAD_CACHE_SCOPES: {
6
+ readonly lit: "lit";
7
+ readonly ecopagesJsx: "ecopages-jsx";
8
+ };
9
+ /**
10
+ * Detects preload failures that are expected for browser-only modules.
11
+ */
12
+ export declare function isExpectedCustomElementSsrPreloadError(error: unknown): boolean;
13
+ /**
14
+ * Collects `dependencies.scripts` paths marked `ssr: true` from a component tree.
15
+ */
16
+ export declare function collectCustomElementSsrPreloadScripts(components: Array<CustomElementSsrPreloadComponent | undefined>, resolveDependencyPath: (componentDir: string, sourcePath: string) => string, requireLazyScriptEntry?: boolean): string[];
17
+ export interface CustomElementScriptPreloaderOptions {
18
+ cacheScope: string;
19
+ enabled?: boolean;
20
+ /**
21
+ * When true, only lazy script entries with `ssr: true` are preloaded.
22
+ *
23
+ * @remarks
24
+ * Lit keeps this enabled so eager `ssr: true` scripts are not evaluated in an
25
+ * isolated module graph that would register incompatible custom elements.
26
+ */
27
+ requireLazyScriptEntry?: boolean;
28
+ resolveDependencyPath: (componentDir: string, sourcePath: string) => string;
29
+ preferSourceImports?: boolean;
30
+ /**
31
+ * Resolves a script path to the module entry the SSR renderer should import.
32
+ *
33
+ * @remarks
34
+ * When this is set, {@link importServerModule} is skipped. Callers that need
35
+ * the app module loader (Lit's static-render worker) must omit the resolver.
36
+ */
37
+ resolvePreloadEntrypoint?: (scriptPath: string) => Promise<string>;
38
+ importServerModule?: (scriptPath: string, registryKey: string) => Promise<unknown>;
39
+ logLabel?: string;
40
+ }
41
+ /**
42
+ * Preloads `dependencies.scripts` entries marked `ssr: true` before SSR.
43
+ *
44
+ * @remarks
45
+ * `lazy` controls browser delivery only; `ssr: true` opts into server evaluation
46
+ * for both eager and lazy script entries. State is keyed by `cacheScope` so
47
+ * concurrent renders and dev invalidation share one deduplicated import cache.
48
+ */
49
+ export declare class CustomElementScriptPreloader {
50
+ private readonly cacheScope;
51
+ private readonly enabled;
52
+ private readonly requireLazyScriptEntry;
53
+ private readonly resolveDependencyPath;
54
+ private readonly preferSourceImports;
55
+ private readonly resolvePreloadEntrypoint?;
56
+ private readonly importServerModule?;
57
+ private readonly logLabel;
58
+ constructor({ cacheScope, enabled, requireLazyScriptEntry, resolveDependencyPath, preferSourceImports, resolvePreloadEntrypoint, importServerModule, logLabel, }: CustomElementScriptPreloaderOptions);
59
+ invalidateScript(scriptPath: string): void;
60
+ isExpectedSsrPreloadError(error: unknown): boolean;
61
+ collectSsrPreloadScripts(components: Array<CustomElementSsrPreloadComponent | undefined>): string[];
62
+ /**
63
+ * Preloads SSR-eligible scripts to register custom elements before render.
64
+ */
65
+ preloadSsrScripts(components: Array<CustomElementSsrPreloadComponent | undefined>): Promise<void>;
66
+ private preloadOneScript;
67
+ private importScriptForPreload;
68
+ }
@@ -0,0 +1,183 @@
1
+ import { getComponentIdentity } from '../../../eco/component-identity.js';
2
+ import path from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { randomUUID } from 'node:crypto';
5
+ import { getCustomElementScriptPreloadScopeState, invalidateCustomElementScriptPreload, } from './custom-element-script-preload-invalidation.js';
6
+ export { invalidateCustomElementScriptPreload };
7
+ const registryKeys = new WeakMap();
8
+ export const CUSTOM_ELEMENT_SSR_PRELOAD_CACHE_SCOPES = {
9
+ lit: 'lit',
10
+ ecopagesJsx: 'ecopages-jsx',
11
+ };
12
+ function getRegistryKey(registry) {
13
+ let key = registryKeys.get(registry);
14
+ if (!key) {
15
+ key = randomUUID();
16
+ registryKeys.set(registry, key);
17
+ }
18
+ return key;
19
+ }
20
+ /**
21
+ * Detects preload failures that are expected for browser-only modules.
22
+ */
23
+ export function isExpectedCustomElementSsrPreloadError(error) {
24
+ const errorMessage = error instanceof Error ? error.message : String(error);
25
+ return (errorMessage.includes(`reading 'Element'`) ||
26
+ errorMessage.includes('window is not defined') ||
27
+ errorMessage.includes('document is not defined') ||
28
+ errorMessage.includes('navigator is not defined'));
29
+ }
30
+ function collectSsrScriptsFromConfig(config, scriptPaths, resolveDependencyPath, componentFile, requireLazyScriptEntry = false) {
31
+ if (!componentFile) {
32
+ return;
33
+ }
34
+ const componentDir = path.dirname(componentFile);
35
+ for (const script of config.dependencies?.scripts ?? []) {
36
+ if (typeof script === 'string' || script.ssr !== true || !script.src) {
37
+ continue;
38
+ }
39
+ if (requireLazyScriptEntry && !script.lazy) {
40
+ continue;
41
+ }
42
+ scriptPaths.add(resolveDependencyPath(componentDir, script.src));
43
+ }
44
+ }
45
+ /**
46
+ * Collects `dependencies.scripts` paths marked `ssr: true` from a component tree.
47
+ */
48
+ export function collectCustomElementSsrPreloadScripts(components, resolveDependencyPath, requireLazyScriptEntry = false) {
49
+ const scriptPaths = new Set();
50
+ const visitedConfigs = new Set();
51
+ const collect = (component) => {
52
+ const config = component?.config;
53
+ if (!config || visitedConfigs.has(config)) {
54
+ return;
55
+ }
56
+ visitedConfigs.add(config);
57
+ const componentFile = getComponentIdentity(component?.config)?.file;
58
+ collectSsrScriptsFromConfig(config, scriptPaths, resolveDependencyPath, componentFile, requireLazyScriptEntry);
59
+ for (const layout of config.layouts ?? []) {
60
+ collect(layout);
61
+ }
62
+ for (const nestedComponent of config.dependencies?.components || []) {
63
+ collect(nestedComponent);
64
+ }
65
+ };
66
+ for (const component of components) {
67
+ collect(component);
68
+ }
69
+ return Array.from(scriptPaths);
70
+ }
71
+ /**
72
+ * Preloads `dependencies.scripts` entries marked `ssr: true` before SSR.
73
+ *
74
+ * @remarks
75
+ * `lazy` controls browser delivery only; `ssr: true` opts into server evaluation
76
+ * for both eager and lazy script entries. State is keyed by `cacheScope` so
77
+ * concurrent renders and dev invalidation share one deduplicated import cache.
78
+ */
79
+ export class CustomElementScriptPreloader {
80
+ cacheScope;
81
+ enabled;
82
+ requireLazyScriptEntry;
83
+ resolveDependencyPath;
84
+ preferSourceImports;
85
+ resolvePreloadEntrypoint;
86
+ importServerModule;
87
+ logLabel;
88
+ constructor({ cacheScope, enabled = true, requireLazyScriptEntry = false, resolveDependencyPath, preferSourceImports, resolvePreloadEntrypoint, importServerModule, logLabel = 'ecopages', }) {
89
+ this.cacheScope = cacheScope;
90
+ this.enabled = enabled;
91
+ this.requireLazyScriptEntry = requireLazyScriptEntry;
92
+ this.resolveDependencyPath = resolveDependencyPath;
93
+ this.preferSourceImports = preferSourceImports ?? typeof Bun !== 'undefined';
94
+ this.resolvePreloadEntrypoint = resolvePreloadEntrypoint;
95
+ this.importServerModule = importServerModule;
96
+ this.logLabel = logLabel;
97
+ }
98
+ invalidateScript(scriptPath) {
99
+ invalidateCustomElementScriptPreload(scriptPath, this.cacheScope);
100
+ }
101
+ isExpectedSsrPreloadError(error) {
102
+ return isExpectedCustomElementSsrPreloadError(error);
103
+ }
104
+ collectSsrPreloadScripts(components) {
105
+ return collectCustomElementSsrPreloadScripts(components, this.resolveDependencyPath, this.requireLazyScriptEntry);
106
+ }
107
+ /**
108
+ * Preloads SSR-eligible scripts to register custom elements before render.
109
+ */
110
+ async preloadSsrScripts(components) {
111
+ if (!this.enabled) {
112
+ return;
113
+ }
114
+ const scopeState = getCustomElementScriptPreloadScopeState(this.cacheScope);
115
+ const registry = globalThis.customElements;
116
+ if (scopeState.activeRegistry !== registry) {
117
+ scopeState.preloadedScripts.clear();
118
+ scopeState.preloadFailedScripts.clear();
119
+ scopeState.inFlightImports.clear();
120
+ scopeState.activeRegistry = registry;
121
+ }
122
+ const scripts = this.collectSsrPreloadScripts(components);
123
+ if (scripts.length === 0) {
124
+ return;
125
+ }
126
+ await Promise.all(scripts.map((scriptPath) => this.preloadOneScript(scriptPath, scopeState, registry)));
127
+ }
128
+ async preloadOneScript(scriptPath, scopeState, registry) {
129
+ if (scopeState.preloadedScripts.has(scriptPath) || scopeState.preloadFailedScripts.has(scriptPath)) {
130
+ return;
131
+ }
132
+ let inFlight = scopeState.inFlightImports.get(scriptPath);
133
+ if (inFlight) {
134
+ await inFlight;
135
+ return;
136
+ }
137
+ inFlight = (async () => {
138
+ try {
139
+ await this.importScriptForPreload(scriptPath, registry);
140
+ scopeState.preloadedScripts.add(scriptPath);
141
+ }
142
+ catch (error) {
143
+ scopeState.preloadFailedScripts.add(scriptPath);
144
+ if (this.isExpectedSsrPreloadError(error)) {
145
+ if (process.env.ECOPAGES_DEBUG === 'true') {
146
+ console.warn(`[ecopages][${this.logLabel}] Skipping SSR preload for browser-only script: ${scriptPath}`);
147
+ }
148
+ return;
149
+ }
150
+ console.warn(`[ecopages][${this.logLabel}] Failed to preload SSR script: ${scriptPath}`, error);
151
+ }
152
+ finally {
153
+ scopeState.inFlightImports.delete(scriptPath);
154
+ }
155
+ })();
156
+ scopeState.inFlightImports.set(scriptPath, inFlight);
157
+ await inFlight;
158
+ }
159
+ async importScriptForPreload(scriptPath, registry) {
160
+ const registryKey = registry ? getRegistryKey(registry) : 'default';
161
+ if (this.resolvePreloadEntrypoint) {
162
+ const preloadEntrypoint = await this.resolvePreloadEntrypoint(scriptPath);
163
+ const importUrl = pathToFileURL(preloadEntrypoint);
164
+ if (registry && typeof Bun === 'undefined') {
165
+ importUrl.searchParams.set('eco-ssr-registry', registryKey);
166
+ }
167
+ await import(/* @vite-ignore */ importUrl.href);
168
+ return;
169
+ }
170
+ if (this.importServerModule) {
171
+ await this.importServerModule(scriptPath, registryKey);
172
+ return;
173
+ }
174
+ if (!this.preferSourceImports) {
175
+ throw new Error(`Cannot preload SSR script ${scriptPath}: configure appConfig.runtime.appModuleLoader or enable source imports (Bun)`);
176
+ }
177
+ const importUrl = pathToFileURL(scriptPath);
178
+ if (registry && typeof Bun === 'undefined') {
179
+ importUrl.searchParams.set('eco-ssr-registry', registryKey);
180
+ }
181
+ await import(/* @vite-ignore */ importUrl.href);
182
+ }
183
+ }
@@ -0,0 +1,9 @@
1
+ import type { EcoPagesAppConfig } from '../../../types/internal-types.js';
2
+ /**
3
+ * Imports one registered script through the app server module loader for SSR.
4
+ *
5
+ * @remarks
6
+ * Uses an isolated outdir per custom-element registry so concurrent renders do
7
+ * not share mutable module evaluation state.
8
+ */
9
+ export declare function createCustomElementServerModuleImporter(appConfig: EcoPagesAppConfig, outdirSegment: string): (filePath: string, registryKey: string) => Promise<unknown>;
@@ -0,0 +1,22 @@
1
+ import path from 'node:path';
2
+ /**
3
+ * Imports one registered script through the app server module loader for SSR.
4
+ *
5
+ * @remarks
6
+ * Uses an isolated outdir per custom-element registry so concurrent renders do
7
+ * not share mutable module evaluation state.
8
+ */
9
+ export function createCustomElementServerModuleImporter(appConfig, outdirSegment) {
10
+ return async (filePath, registryKey) => {
11
+ const loader = appConfig.runtime?.appModuleLoader;
12
+ if (!loader) {
13
+ throw new Error('Custom element SSR script preload requires the app server module loader');
14
+ }
15
+ return loader.importModule({
16
+ filePath,
17
+ rootDir: appConfig.rootDir,
18
+ outdir: path.join(appConfig.absolutePaths.workDir, outdirSegment, registryKey),
19
+ forceBuild: true,
20
+ });
21
+ };
22
+ }
@@ -0,0 +1,10 @@
1
+ import { type AssetDefinition, type ProcessedAsset } from '../../../services/assets/asset-processing-service/index.js';
2
+ export type CustomElementSsrPreloadEntrypointResolverOptions = {
3
+ preferSourceImports: boolean;
4
+ processDependencies?: (dependencies: AssetDefinition[], integrationName: string) => Promise<ProcessedAsset[]>;
5
+ };
6
+ /**
7
+ * Resolves SSR script paths through the asset pipeline so preload imports share
8
+ * the renderer dependency graph instead of an isolated app-module bundle.
9
+ */
10
+ export declare function createCustomElementSsrPreloadEntrypointResolver({ preferSourceImports, processDependencies, }: CustomElementSsrPreloadEntrypointResolverOptions): (scriptPath: string) => Promise<string>;
@@ -0,0 +1,46 @@
1
+ import { AssetFactory, } from '../../../services/assets/asset-processing-service/index.js';
2
+ /**
3
+ * Resolves SSR script paths through the asset pipeline so preload imports share
4
+ * the renderer dependency graph instead of an isolated app-module bundle.
5
+ */
6
+ export function createCustomElementSsrPreloadEntrypointResolver({ preferSourceImports, processDependencies, }) {
7
+ const entrypointCache = new Map();
8
+ return async (scriptPath) => {
9
+ const cachedEntrypoint = entrypointCache.get(scriptPath);
10
+ if (cachedEntrypoint) {
11
+ return cachedEntrypoint;
12
+ }
13
+ if (preferSourceImports) {
14
+ entrypointCache.set(scriptPath, scriptPath);
15
+ return scriptPath;
16
+ }
17
+ if (!processDependencies) {
18
+ entrypointCache.set(scriptPath, scriptPath);
19
+ return scriptPath;
20
+ }
21
+ try {
22
+ const processed = await processDependencies([
23
+ AssetFactory.createInlineFileScript({
24
+ filepath: scriptPath,
25
+ excludeFromHtml: true,
26
+ position: 'head',
27
+ bundle: true,
28
+ attributes: {
29
+ type: 'module',
30
+ defer: '',
31
+ },
32
+ }),
33
+ ], `custom-element-ssr-preload:${scriptPath}`);
34
+ const entrypoint = processed[0]?.filepath ?? scriptPath;
35
+ entrypointCache.set(scriptPath, entrypoint);
36
+ return entrypoint;
37
+ }
38
+ catch (error) {
39
+ if (process.env.ECOPAGES_DEBUG === 'true') {
40
+ console.warn(`[ecopages] Failed to resolve custom-element SSR preload entrypoint for: ${scriptPath}`, error);
41
+ }
42
+ entrypointCache.set(scriptPath, scriptPath);
43
+ return scriptPath;
44
+ }
45
+ };
46
+ }
@@ -1,4 +1,5 @@
1
- import type { BaseIntegrationContext, ComponentRenderInput, ComponentRenderResult, EcoComponent, PageMetadataProps } from '../../../types/public-types.js';
1
+ import type { BaseIntegrationContext, ComponentRenderResult, EcoComponent, PageMetadataProps } from '../../../types/public-types.js';
2
+ import type { InternalComponentRenderInput } from '../../../types/internal-types.js';
2
3
  import type { ProcessedAsset } from '../../../services/assets/asset-processing-service/index.js';
3
4
  import { HtmlTransformerService, type HtmlDocumentContribution } from '../../../services/html/html-transformer.service.js';
4
5
  export type DocumentShellLayoutInput = {
@@ -36,6 +37,8 @@ export type DocumentShellComposeChildrenHook = (context: DocumentShellComposeChi
36
37
  export type DocumentShellComposeInput = {
37
38
  primaryComponent: EcoComponent;
38
39
  primaryProps: Record<string, unknown>;
40
+ /** Components whose ownership graphs must join the foreign-child decision. */
41
+ foreignChildRoots?: ReadonlyArray<EcoComponent | Partial<EcoComponent>>;
39
42
  layout?: DocumentShellLayoutInput;
40
43
  layouts?: DocumentShellLayoutInput[];
41
44
  composeChildren?: DocumentShellComposeChildrenHook;
@@ -47,6 +50,8 @@ export type DocumentShellPageRenderInput = {
47
50
  component: EcoComponent;
48
51
  props: Record<string, unknown>;
49
52
  };
53
+ /** Components whose ownership graphs must join the foreign-child decision. */
54
+ foreignChildRoots?: ReadonlyArray<EcoComponent | Partial<EcoComponent>>;
50
55
  layout?: DocumentShellLayoutInput;
51
56
  layouts?: DocumentShellLayoutInput[];
52
57
  composeChildren?: DocumentShellComposeChildrenHook;
@@ -57,7 +62,7 @@ export type DocumentShellPageRenderInput = {
57
62
  transformDocumentHtml?: (html: string) => string;
58
63
  };
59
64
  export type DocumentShellRenderDependencies = {
60
- renderComponentWithForeignChildren(input: ComponentRenderInput): Promise<ComponentRenderResult>;
65
+ renderComponentWithForeignChildren(input: InternalComponentRenderInput): Promise<ComponentRenderResult>;
61
66
  appendProcessedDependencies(...assetGroups: Array<readonly ProcessedAsset[] | undefined>): ProcessedAsset[];
62
67
  };
63
68
  export type DocumentShellAttributeStamping = {
@@ -68,6 +68,7 @@ export async function composeDocumentShell(dependencies, input) {
68
68
  primaryRender = await dependencies.renderComponentWithForeignChildren({
69
69
  component: input.primaryComponent,
70
70
  props: input.primaryProps,
71
+ foreignChildRoots: input.foreignChildRoots,
71
72
  integrationContext: { rendererCache },
72
73
  });
73
74
  const composed = await composeChildren({
@@ -113,6 +114,7 @@ export async function renderPageDocumentShell(dependencies, input, docType) {
113
114
  const { documentHtml: composedDocumentHtml } = await composeDocumentShell(dependencies, {
114
115
  primaryComponent: input.page.component,
115
116
  primaryProps: input.page.props,
117
+ foreignChildRoots: input.foreignChildRoots,
116
118
  layout: input.layout,
117
119
  layouts: input.layouts,
118
120
  composeChildren: input.composeChildren,
@@ -1,5 +1,6 @@
1
1
  import type { ProcessedAsset } from '../../../services/assets/asset-processing-service/index.js';
2
2
  import type { BaseIntegrationContext, ComponentRenderInput, ComponentRenderResult, EcoComponent, ForeignSubtreeRenderPayload } from '../../../types/public-types.js';
3
+ import type { InternalComponentRenderInput } from '../../../types/internal-types.js';
3
4
  import { type ForeignChildRuntime } from './component-render-context.js';
4
5
  export type QueuedForeignChildDecisionInput = {
5
6
  currentIntegration: string;
@@ -38,10 +39,10 @@ export interface ForeignSubtreeExecutionDecisionInput {
38
39
  }
39
40
  export interface ForeignSubtreeExecutionRenderOptions {
40
41
  currentIntegrationName: string;
41
- input: ComponentRenderInput;
42
+ input: InternalComponentRenderInput;
42
43
  renderComponent(input: ComponentRenderInput): Promise<ComponentRenderResult>;
43
44
  normalizeComponentRenderOutput(result: ComponentRenderResult): ComponentRenderResult;
44
- hasForeignChildDescendants(component: EcoComponent): boolean;
45
+ hasForeignChildDescendants(component: EcoComponent, foreignChildRoots?: ReadonlyArray<EcoComponent | Partial<EcoComponent>>): boolean;
45
46
  createForeignChildRuntime(options: {
46
47
  renderInput: ComponentRenderInput;
47
48
  rendererCache: Map<string, ForeignSubtreeExecutionOwningRenderer>;
@@ -241,7 +241,7 @@ export class ForeignSubtreeExecutionService {
241
241
  if (delegatedForeignChildRender) {
242
242
  return delegatedForeignChildRender;
243
243
  }
244
- const hasForeignChildren = options.hasForeignChildDescendants(options.input.component) ||
244
+ const hasForeignChildren = options.hasForeignChildDescendants(options.input.component, options.input.foreignChildRoots) ||
245
245
  this.requiresForeignChildRuntime(options.input);
246
246
  const activeRenderContext = getComponentRenderContext();
247
247
  if (!hasForeignChildren) {
@@ -3,7 +3,7 @@
3
3
  * Every integration renderer should extend this class
4
4
  * @module
5
5
  */
6
- import type { EcoPagesAppConfig, IHmrManager } from '../../types/internal-types.js';
6
+ import type { EcoPagesAppConfig, IHmrManager, InternalComponentRenderInput } from '../../types/internal-types.js';
7
7
  import type { ComponentRenderInput, ComponentRenderResult, EcoComponent, EcoPageFile, EcoPagesElement, HtmlTemplateProps, IntegrationRendererRenderOptions, PageBrowserGraphContribution, PageBrowserGraphContributionContext, PageBrowserGraphResult, PageMetadataProps, RouteRendererBody, RouteRendererOptions, RouteRenderResult } from '../../types/public-types.js';
8
8
  import { type AssetProcessingService, type ProcessedAsset } from '../../services/assets/asset-processing-service/index.js';
9
9
  import { HtmlTransformerService } from '../../services/html/html-transformer.service.js';
@@ -217,7 +217,11 @@ export declare abstract class IntegrationRenderer<C = EcoPagesElement> {
217
217
  pageProps: Record<string, unknown>;
218
218
  documentProps?: Record<string, unknown>;
219
219
  transformDocumentHtml?: (html: string) => string;
220
+ foreignChildRoots?: ReadonlyArray<EcoComponent | Partial<EcoComponent>>;
220
221
  }): Promise<string>;
222
+ private serializeStringRenderChildren;
223
+ private assertStringRenderChildren;
224
+ private assertStringRenderContent;
221
225
  protected renderStringComponentWithSerializedChildren(input: ComponentRenderInput, component: (props: Record<string, unknown>) => Promise<EcoPagesElement> | EcoPagesElement): Promise<ComponentRenderResult>;
222
226
  /**
223
227
  * Renders a string-first component, then resolves any queued foreign
@@ -349,7 +353,7 @@ export declare abstract class IntegrationRenderer<C = EcoPagesElement> {
349
353
  * render them with no active foreign-child runtime, which bypasses the owning
350
354
  * renderer's nested foreign-child handoff.
351
355
  */
352
- renderComponentWithForeignChildren(input: ComponentRenderInput): Promise<ComponentRenderResult>;
356
+ renderComponentWithForeignChildren(input: InternalComponentRenderInput): Promise<ComponentRenderResult>;
353
357
  protected finalizeIslandComponentRender(input: ComponentRenderInput, result: ComponentRenderResult): ComponentRenderResult;
354
358
  private normalizeComponentRenderOutput;
355
359
  protected normalizeUnresolvedMarkerArtifactHtml(html: string): string;
@@ -360,7 +364,7 @@ export declare abstract class IntegrationRenderer<C = EcoPagesElement> {
360
364
  * This keeps foreign-child runtime setup narrow: same-integration trees can render
361
365
  * directly without paying the queue orchestration cost.
362
366
  */
363
- protected hasForeignChildDescendants(component: EcoComponent): boolean;
367
+ protected hasForeignChildDescendants(component: EcoComponent, foreignChildRoots?: ReadonlyArray<EcoComponent | Partial<EcoComponent>>): boolean;
364
368
  /**
365
369
  * Render a view directly to a Response object.
366
370
  * Used for explicit routing where views are rendered from route handlers.
@@ -366,26 +366,40 @@ export class IntegrationRenderer {
366
366
  appendProcessedDependencies: (...assetGroups) => this.appendProcessedDependencies(...assetGroups),
367
367
  }, input, this.DOC_TYPE);
368
368
  }
369
- async renderStringComponentWithSerializedChildren(input, component) {
370
- const serializedChildren = input.children === undefined
371
- ? undefined
372
- : typeof input.children === 'string'
373
- ? input.children
374
- : isMarkupNodeLike(input.children) && typeof input.children.outerHTML === 'string'
375
- ? input.children.outerHTML
376
- : undefined;
377
- if (input.children !== undefined && serializedChildren === undefined) {
378
- const componentFile = input.component.config?.identity?.file ?? 'unknown component';
379
- const childTag = Object.prototype.toString.call(input.children);
380
- throw new TypeError(`[ecopages] ${this.name} renderer expected serialized children for ${componentFile}, received ${childTag}.`);
369
+ serializeStringRenderChildren(children) {
370
+ if (children === undefined) {
371
+ return undefined;
372
+ }
373
+ if (typeof children === 'string') {
374
+ return children;
375
+ }
376
+ if (isMarkupNodeLike(children) && typeof children.outerHTML === 'string') {
377
+ return children.outerHTML;
378
+ }
379
+ return undefined;
380
+ }
381
+ assertStringRenderChildren(input, serializedChildren) {
382
+ if (input.children === undefined || serializedChildren !== undefined) {
383
+ return;
384
+ }
385
+ const componentFile = input.component.config?.identity?.file ?? 'unknown component';
386
+ const childTag = Object.prototype.toString.call(input.children);
387
+ throw new TypeError(`[ecopages] ${this.name} renderer expected serialized children for ${componentFile}, received ${childTag}.`);
388
+ }
389
+ assertStringRenderContent(input, content) {
390
+ if (typeof content === 'string') {
391
+ return;
381
392
  }
393
+ const componentFile = input.component.config?.identity?.file ?? 'unknown component';
394
+ const contentTag = Object.prototype.toString.call(content);
395
+ throw new TypeError(`[ecopages] ${this.name} renderer expected a string render result for ${componentFile}, received ${contentTag}.`);
396
+ }
397
+ async renderStringComponentWithSerializedChildren(input, component) {
398
+ const serializedChildren = this.serializeStringRenderChildren(input.children);
399
+ this.assertStringRenderChildren(input, serializedChildren);
382
400
  const props = serializedChildren === undefined ? input.props : { ...input.props, children: serializedChildren };
383
401
  const content = await component(props);
384
- if (typeof content !== 'string') {
385
- const componentFile = input.component.config?.identity?.file ?? 'unknown component';
386
- const contentTag = Object.prototype.toString.call(content);
387
- throw new TypeError(`[ecopages] ${this.name} renderer expected a string render result for ${componentFile}, received ${contentTag}.`);
388
- }
402
+ this.assertStringRenderContent(input, content);
389
403
  const html = content;
390
404
  const assets = input.component.config?.dependencies &&
391
405
  typeof this.assetProcessingService?.processDependencies === 'function'
@@ -688,7 +702,7 @@ export class IntegrationRenderer {
688
702
  input,
689
703
  renderComponent: (renderInput) => this.renderComponent(renderInput),
690
704
  normalizeComponentRenderOutput: (result) => this.normalizeComponentRenderOutput(result),
691
- hasForeignChildDescendants: (component) => this.hasForeignChildDescendants(component),
705
+ hasForeignChildDescendants: (component, foreignChildRoots) => this.hasForeignChildDescendants(component, foreignChildRoots),
692
706
  createForeignChildRuntime: ({ renderInput, rendererCache }) => this.createForeignChildRuntime({
693
707
  renderInput,
694
708
  rendererCache: rendererCache,
@@ -725,8 +739,8 @@ export class IntegrationRenderer {
725
739
  * This keeps foreign-child runtime setup narrow: same-integration trees can render
726
740
  * directly without paying the queue orchestration cost.
727
741
  */
728
- hasForeignChildDescendants(component) {
729
- return hasForeignChildDescendantsInGraph(component, this.name);
742
+ hasForeignChildDescendants(component, foreignChildRoots) {
743
+ return hasForeignChildDescendantsInGraph(component, this.name, foreignChildRoots);
730
744
  }
731
745
  /**
732
746
  * Render a single component and return structured output for orchestration paths.
@@ -3,5 +3,5 @@ import type { EcoComponent, ResolvedLazyTrigger } from '../../../types/public-ty
3
3
  import type { ProcessedAsset } from '../../../services/assets/asset-processing-service/index.js';
4
4
  export declare function collectIntegrationNamesFromGraph(components: (EcoComponent | Partial<EcoComponent>)[], currentIntegrationName: string): Set<string>;
5
5
  export declare function collectResolvedLazyTriggersFromGraph(components: (EcoComponent | Partial<EcoComponent>)[], currentIntegrationName: string): ResolvedLazyTrigger[];
6
- export declare function hasForeignChildDescendantsInGraph(component: EcoComponent, currentIntegrationName: string): boolean;
6
+ export declare function hasForeignChildDescendantsInGraph(component: EcoComponent, currentIntegrationName: string, foreignChildRoots?: ReadonlyArray<EcoComponent | Partial<EcoComponent>>): boolean;
7
7
  export declare function collectUsedIntegrationDependenciesFromGraph(appConfig: EcoPagesAppConfig, components: (EcoComponent | Partial<EcoComponent>)[], currentIntegrationName: string): ProcessedAsset[];
@@ -31,10 +31,10 @@ export function collectResolvedLazyTriggersFromGraph(components, currentIntegrat
31
31
  });
32
32
  return triggers;
33
33
  }
34
- export function hasForeignChildDescendantsInGraph(component, currentIntegrationName) {
34
+ export function hasForeignChildDescendantsInGraph(component, currentIntegrationName, foreignChildRoots) {
35
35
  let foundForeign = false;
36
36
  walkComponentGraph({
37
- roots: [{ component }],
37
+ roots: toGraphRoots([component, ...(foreignChildRoots ?? [])]),
38
38
  currentIntegrationName,
39
39
  onComponent: ({ component: currentComponent }) => {
40
40
  if (foundForeign) {