@ecopages/ecopages-jsx 0.2.0-rc.0 → 0.2.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -1
- package/package.json +9 -6
- package/src/ecopages-jsx-mdx.d.ts +7 -2
- package/src/ecopages-jsx-mdx.js +18 -29
- package/src/ecopages-jsx-radiant-ssr-policy.js +2 -1
- package/src/ecopages-jsx-renderer.d.ts +1 -0
- package/src/ecopages-jsx-renderer.js +149 -109
- package/src/ecopages-jsx.plugin.js +16 -2
- package/src/radiant-registered-script-ssr-invalidation.js +2 -0
package/README.md
CHANGED
|
@@ -53,6 +53,12 @@ Radiant support is enabled by default. When `radiant: true`, the plugin keeps th
|
|
|
53
53
|
|
|
54
54
|
That means server-rendered `RadiantElement` hosts hydrate in place only when both the SSR markers and the explicit client hydrator are present. Without the client hydrator, Radiant intentionally falls back to a fresh client render on first connect.
|
|
55
55
|
|
|
56
|
+
### Hydration Semantics: RadiantElement vs. RadiantController
|
|
57
|
+
|
|
58
|
+
- **`RadiantElement` (DOM Preservation)**: Custom elements extending `RadiantElement` support true in-place hydration. When `@ecopages/radiant/client/install-hydrator` executes before elements connect, existing light-DOM SSR nodes are preserved, retaining DOM node identity, form input state, active focus, and media playback.
|
|
59
|
+
- **`RadiantController` (Activation / Template Re-mount)**: Controllers attached via `[data-controller]` activate when `startControllers(document)` is called. Activation executes the controller's `render()` method and mounts its template fresh into the host container, replacing server-rendered child nodes. Reactive properties and signal bindings remain fully interactive, but individual child DOM nodes are reconstructed.
|
|
60
|
+
- **Guidance**: Use `RadiantElement` when in-place preservation of SSR nodes (e.g., focused inputs, media elements, or CSS transitions) is required. Use `RadiantController` for Stimulus-style progressive enhancement on arbitrary markup where child DOM reconstruction is acceptable.
|
|
61
|
+
|
|
56
62
|
```ts
|
|
57
63
|
ecopagesJsxPlugin({
|
|
58
64
|
radiant: true,
|
|
@@ -72,6 +78,23 @@ new MyElement().renderHostToString({ mode: 'hydrate' });
|
|
|
72
78
|
|
|
73
79
|
The legacy `hydrate: true` option remains compatible, but `mode` is the current SSR contract. Registered intrinsic tags that contain a dash are SSR candidates, and framework-specific host rendering should be adapted through the server custom-element render hook instead of hardcoding framework branches into JSX page code.
|
|
74
80
|
|
|
81
|
+
The integration loads Radiant host serialization through the public `@ecopages/radiant/server/radiant-element-ssr` export after installing the light-DOM shim. Applications do not need a separate Radiant SSR side-effect import.
|
|
82
|
+
|
|
83
|
+
### Registered Radiant scripts (`ssr: true`)
|
|
84
|
+
|
|
85
|
+
Declare custom-element registration once in `dependencies.scripts`. Ecopages JSX preloads entries marked `ssr: true` on the server before render so hosts can SSR without a redundant `import './my-element.script.ts'` in the component file.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
export const ThemeToggle = eco.component({
|
|
89
|
+
dependencies: {
|
|
90
|
+
scripts: [{ src: './theme-toggle.script.ts', ssr: true, lazy: { 'on:idle': true } }],
|
|
91
|
+
},
|
|
92
|
+
render: () => <theme-toggle />,
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Keep `import type` when you only need props from the script module. Do not add `ssr: true` to browser-only scripts that touch `window` or `document` without guards.
|
|
97
|
+
|
|
75
98
|
## MDX Support
|
|
76
99
|
|
|
77
100
|
Enable MDX to treat `.mdx` files as JSX routes compiled against the `@ecopages/jsx` runtime.
|
|
@@ -100,7 +123,8 @@ Ecopages JSX can own the outer page shell or just a nested foreign subtree. When
|
|
|
100
123
|
|
|
101
124
|
Important:
|
|
102
125
|
|
|
103
|
-
- Cross-integration
|
|
126
|
+
- Cross-integration shell stacks should use `EcoEmbed` from `@ecopages/ecopages-jsx/eco-embed` (or the matching integration adapter). Plain opaque objects fail fast at core foreign-subtree queue boundaries; they are not coerced with `String(object)`. Pass already-serialized HTML when `EcoEmbed` is not needed.
|
|
104
127
|
- Components that may render foreign children must declare those children in `config.dependencies.components`.
|
|
105
128
|
- Ecopages validates mixed-renderer ownership from declared dependencies during render preparation. It does not treat rendered HTML alone as the source of truth.
|
|
129
|
+
- Route-level dependency resolvers can supply Components at request time; Ecopages JSX includes those resolved roots when deciding whether a Foreign Subtree needs handoff.
|
|
106
130
|
- Ecopages JSX keeps raw-markup preservation and asset collection inside the JSX renderer.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/ecopages-jsx",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.10",
|
|
4
4
|
"description": "JSX integration plugin for Ecopages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"main": "./src/ecopages-jsx.plugin.js",
|
|
12
12
|
"types": "./src/ecopages-jsx.plugin.d.ts",
|
|
13
13
|
"type": "module",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
14
17
|
"exports": {
|
|
15
18
|
".": {
|
|
16
19
|
"default": "./src/ecopages-jsx.plugin.js",
|
|
@@ -31,13 +34,13 @@
|
|
|
31
34
|
"directory": "packages/integrations/ecopages-jsx"
|
|
32
35
|
},
|
|
33
36
|
"dependencies": {
|
|
34
|
-
"@ecopages/mdx": "0.2.0-rc.
|
|
37
|
+
"@ecopages/mdx": "0.2.0-rc.10",
|
|
35
38
|
"@mdx-js/mdx": "^3.1.1",
|
|
36
39
|
"vfile": "^6.0.3"
|
|
37
40
|
},
|
|
38
41
|
"peerDependencies": {
|
|
39
|
-
"@ecopages/core": "0.2.0-rc.
|
|
40
|
-
"@ecopages/jsx": "0.3.0-rc.
|
|
41
|
-
"@ecopages/radiant": "0.3.0-rc.
|
|
42
|
+
"@ecopages/core": "0.2.0-rc.10",
|
|
43
|
+
"@ecopages/jsx": "^0.3.0-rc.9",
|
|
44
|
+
"@ecopages/radiant": "^0.3.0-rc.9"
|
|
42
45
|
}
|
|
43
|
-
}
|
|
46
|
+
}
|
|
@@ -13,7 +13,12 @@ export type EcopagesJsxMdxPageModule = EcoPageFile<{
|
|
|
13
13
|
}>;
|
|
14
14
|
export { appendMdxExtensions, createMdxExtensionFilter };
|
|
15
15
|
export declare const resolveMdxCompilerOptions: (mdxOptions: EcopagesJsxMdxOptions) => ResolvedMdxCompileOptions;
|
|
16
|
-
export
|
|
17
|
-
|
|
16
|
+
export interface CreateEcopagesJsxMdxLoaderPluginOptions {
|
|
17
|
+
compilerOptions: ResolvedMdxCompileOptions;
|
|
18
|
+
extensions: string[];
|
|
19
|
+
projectRoot: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const createMdxLoaderPlugin: (options: CreateEcopagesJsxMdxLoaderPluginOptions) => EcoBuildPlugin;
|
|
22
|
+
export declare const registerBunMdxPlugin: (options: CreateEcopagesJsxMdxLoaderPluginOptions) => Promise<void>;
|
|
18
23
|
export declare const isMdxFile: (filePath: string, extensions: string[]) => boolean;
|
|
19
24
|
export declare const normalizeMdxPageModule: (file: string, module: EcopagesJsxMdxPageModule) => EcopagesJsxMdxPageModule;
|
package/src/ecopages-jsx-mdx.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
1
|
import { ensurePageConfigLayouts } from '@ecopages/core/eco/page-layout-normalization';
|
|
3
|
-
import { rapidhash } from '@ecopages/core/hash';
|
|
4
2
|
import { appendMdxExtensions, createMdxExtensionFilter, createMdxLoaderPlugin as createMdxLoaderPluginCore, resolveMdxCompilerOptions as resolveMdxCompilerOptionsCore, } from '@ecopages/mdx/core';
|
|
5
|
-
import { VFile } from 'vfile';
|
|
6
3
|
import { ECOPAGES_JSX_PLUGIN_NAME } from './ecopages-jsx.constants.js';
|
|
7
4
|
export { appendMdxExtensions, createMdxExtensionFilter };
|
|
8
5
|
export const resolveMdxCompilerOptions = (mdxOptions) => resolveMdxCompilerOptionsCore(mdxOptions, {
|
|
@@ -12,27 +9,24 @@ export const resolveMdxCompilerOptions = (mdxOptions) => resolveMdxCompilerOptio
|
|
|
12
9
|
outputFormat: 'program',
|
|
13
10
|
},
|
|
14
11
|
});
|
|
15
|
-
export const createMdxLoaderPlugin = (
|
|
12
|
+
export const createMdxLoaderPlugin = (options) => createMdxLoaderPluginCore({
|
|
16
13
|
name: 'ecopages-jsx-mdx-loader',
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
integrationName: ECOPAGES_JSX_PLUGIN_NAME,
|
|
15
|
+
compilerOptions: options.compilerOptions,
|
|
16
|
+
extensions: options.extensions,
|
|
19
17
|
includeSourceMap: false,
|
|
20
18
|
loader: 'js',
|
|
19
|
+
projectRoot: options.projectRoot,
|
|
21
20
|
});
|
|
22
|
-
export const registerBunMdxPlugin = async (
|
|
21
|
+
export const registerBunMdxPlugin = async (options) => {
|
|
23
22
|
if (typeof Bun === 'undefined') {
|
|
24
23
|
return;
|
|
25
24
|
}
|
|
26
|
-
const
|
|
25
|
+
const plugin = createMdxLoaderPlugin(options);
|
|
27
26
|
Bun.plugin({
|
|
28
|
-
name:
|
|
27
|
+
name: plugin.name,
|
|
29
28
|
setup(build) {
|
|
30
|
-
|
|
31
|
-
const { compile } = await import('@mdx-js/mdx');
|
|
32
|
-
const source = await readFile(args.path, 'utf-8');
|
|
33
|
-
const compiled = await compile(new VFile({ value: source, path: args.path }), compilerOptions);
|
|
34
|
-
return { contents: String(compiled.value), loader: 'js' };
|
|
35
|
-
});
|
|
29
|
+
return plugin.setup(build);
|
|
36
30
|
},
|
|
37
31
|
});
|
|
38
32
|
};
|
|
@@ -44,27 +38,22 @@ export const normalizeMdxPageModule = (file, module) => {
|
|
|
44
38
|
throw new TypeError('MDX file must export a callable default component.');
|
|
45
39
|
}
|
|
46
40
|
const Page = module.default;
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
integration: ECOPAGES_JSX_PLUGIN_NAME,
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
if (module.layout && !(normalizedConfig.layouts && normalizedConfig.layouts.length > 0)) {
|
|
57
|
-
normalizedConfig.layout = module.layout;
|
|
41
|
+
const attributedConfig = module.config ?? Page.config;
|
|
42
|
+
if (!attributedConfig?.identity) {
|
|
43
|
+
throw new Error(`[ecopages] MDX page "${file}" is missing component identity; the MDX loader must attribute it.`);
|
|
44
|
+
}
|
|
45
|
+
if (module.layout && !(attributedConfig.layouts && attributedConfig.layouts.length > 0)) {
|
|
46
|
+
attributedConfig.layout = module.layout;
|
|
58
47
|
}
|
|
59
|
-
ensurePageConfigLayouts(
|
|
48
|
+
ensurePageConfigLayouts(attributedConfig);
|
|
60
49
|
const wrappedPage = async (props) => await Page(props);
|
|
61
|
-
wrappedPage.config =
|
|
50
|
+
wrappedPage.config = attributedConfig;
|
|
62
51
|
if (module.getMetadata ?? Page.metadata) {
|
|
63
52
|
wrappedPage.metadata = module.getMetadata ?? Page.metadata;
|
|
64
53
|
}
|
|
65
54
|
return {
|
|
66
55
|
...module,
|
|
67
56
|
default: wrappedPage,
|
|
68
|
-
config:
|
|
57
|
+
config: attributedConfig,
|
|
69
58
|
};
|
|
70
59
|
};
|
|
@@ -59,7 +59,8 @@ export class EcopagesJsxRadiantSsrPolicy {
|
|
|
59
59
|
async ensureRuntimeInstalled() {
|
|
60
60
|
if (!this.runtimeModulesPromise) {
|
|
61
61
|
const radiantLightDomShimEntry = import.meta.resolve('@ecopages/radiant/server/light-dom-shim');
|
|
62
|
-
const radiantElementSsrRuntimeModuleUrl =
|
|
62
|
+
const radiantElementSsrRuntimeModuleUrl = import.meta
|
|
63
|
+
.resolve('@ecopages/radiant/server/radiant-element-ssr');
|
|
63
64
|
this.runtimeModulesPromise = (async () => {
|
|
64
65
|
const lightDomShimModule = await import(radiantLightDomShimEntry);
|
|
65
66
|
ensureRadiantLightDomGlobals(lightDomShimModule.ensureLightDomShim);
|
|
@@ -16,6 +16,7 @@ export declare class EcopagesJsxRenderer extends IntegrationRenderer<JsxRenderab
|
|
|
16
16
|
private readonly mdxExtensions;
|
|
17
17
|
private readonly renderSession;
|
|
18
18
|
private readonly radiantSsrPolicy;
|
|
19
|
+
private readonly ssrScriptPreloader;
|
|
19
20
|
/**
|
|
20
21
|
* Serializes foreign-child props for string-first boundaries.
|
|
21
22
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IntegrationRenderer, } from '@ecopages/core/route-renderer/orchestration/integration-renderer';
|
|
2
|
+
import { resolveDocumentShellLayouts } from '@ecopages/core/route-renderer/orchestration/document-shell/layout-shell-props.service';
|
|
2
3
|
import { getForeignSubtreeResolutionContextKey, resolveOwningIntegrationRenderer, } from '@ecopages/core/route-renderer/orchestration/foreign-child/owning-renderer-resolution';
|
|
3
4
|
import { createMarkupNodeLike } from '@ecopages/jsx';
|
|
4
5
|
import { renderToString, withServerCustomElementRenderHook } from '@ecopages/jsx/server';
|
|
@@ -6,6 +7,8 @@ import { ECOPAGES_JSX_PLUGIN_NAME } from './ecopages-jsx.constants.js';
|
|
|
6
7
|
import { isMdxFile, normalizeMdxPageModule, } from './ecopages-jsx-mdx.js';
|
|
7
8
|
import { EcopagesJsxRenderSession } from './ecopages-jsx-render-session.js';
|
|
8
9
|
import { EcopagesJsxRadiantSsrPolicy } from './ecopages-jsx-radiant-ssr-policy.js';
|
|
10
|
+
import { CUSTOM_ELEMENT_SSR_PRELOAD_CACHE_SCOPES, CustomElementScriptPreloader, } from '@ecopages/core/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader';
|
|
11
|
+
import { createSharedServerModuleImporter } from '@ecopages/core/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer';
|
|
9
12
|
/**
|
|
10
13
|
* Local Ecopages renderer for JSX templates in the docs app.
|
|
11
14
|
*
|
|
@@ -17,6 +20,7 @@ export class EcopagesJsxRenderer extends IntegrationRenderer {
|
|
|
17
20
|
mdxExtensions;
|
|
18
21
|
renderSession;
|
|
19
22
|
radiantSsrPolicy;
|
|
23
|
+
ssrScriptPreloader;
|
|
20
24
|
/**
|
|
21
25
|
* Serializes foreign-child props for string-first boundaries.
|
|
22
26
|
*
|
|
@@ -121,8 +125,26 @@ export class EcopagesJsxRenderer extends IntegrationRenderer {
|
|
|
121
125
|
});
|
|
122
126
|
this.mdxExtensions = jsxConfig?.mdxExtensions ?? ['.mdx'];
|
|
123
127
|
this.renderSession = new EcopagesJsxRenderSession((assets) => this.htmlTransformer.dedupeProcessedAssets(assets));
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
const radiantSsrEnabled = jsxConfig?.radiantSsrEnabled ?? false;
|
|
129
|
+
this.radiantSsrPolicy = jsxConfig?.radiantSsrPolicy ?? new EcopagesJsxRadiantSsrPolicy(radiantSsrEnabled);
|
|
130
|
+
const preferSourceImports = typeof Bun !== 'undefined';
|
|
131
|
+
this.ssrScriptPreloader = new CustomElementScriptPreloader({
|
|
132
|
+
cacheScope: CUSTOM_ELEMENT_SSR_PRELOAD_CACHE_SCOPES.ecopagesJsx,
|
|
133
|
+
collectForIntegration: ECOPAGES_JSX_PLUGIN_NAME,
|
|
134
|
+
enabled: radiantSsrEnabled,
|
|
135
|
+
logLabel: 'ecopages-jsx',
|
|
136
|
+
preferSourceImports,
|
|
137
|
+
resolveDependencyPath: (componentDir, sourcePath) => this.resolveDependencyPath(componentDir, sourcePath),
|
|
138
|
+
/**
|
|
139
|
+
* @remarks
|
|
140
|
+
* Bun imports the source file through `preferSourceImports`. Node must
|
|
141
|
+
* not: dev asset output is still the `.tsx` source, and a browser bundle
|
|
142
|
+
* is a second Radiant graph. The page server-module loader transpiles
|
|
143
|
+
* the script and externalizes packages, so `customElements.define` hits
|
|
144
|
+
* the same module instances the page already loaded.
|
|
145
|
+
*/
|
|
146
|
+
importServerModule: preferSourceImports ? undefined : createSharedServerModuleImporter(this.appConfig),
|
|
147
|
+
});
|
|
126
148
|
}
|
|
127
149
|
/** Returns whether the requested page file should be treated as MDX. */
|
|
128
150
|
isMdxFile(filePath) {
|
|
@@ -135,122 +157,140 @@ export class EcopagesJsxRenderer extends IntegrationRenderer {
|
|
|
135
157
|
});
|
|
136
158
|
}
|
|
137
159
|
async render(options) {
|
|
138
|
-
return await this.withPreparedRadiantRuntime(async () =>
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
component: options.Layout,
|
|
160
|
+
return await this.withPreparedRadiantRuntime(async () => {
|
|
161
|
+
await this.ssrScriptPreloader.preloadSsrScripts([
|
|
162
|
+
options.Page,
|
|
163
|
+
options.Layout,
|
|
164
|
+
options.HtmlTemplate,
|
|
165
|
+
...(options.resolvedPageDependencyComponents ?? []),
|
|
166
|
+
]);
|
|
167
|
+
return await this.renderSession.withActiveScope(async () => {
|
|
168
|
+
try {
|
|
169
|
+
const result = await this.renderPageWithDocumentShell({
|
|
170
|
+
page: {
|
|
171
|
+
component: options.Page,
|
|
151
172
|
props: {
|
|
152
173
|
...options.pageProps,
|
|
153
|
-
locals: options.
|
|
174
|
+
locals: options.pageLocals,
|
|
154
175
|
},
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
176
|
+
},
|
|
177
|
+
/**
|
|
178
|
+
* @remarks Content components supplied by the Page dependency
|
|
179
|
+
* resolver (for example the active MDX entry) carry foreign
|
|
180
|
+
* ownership the static Page config cannot declare.
|
|
181
|
+
*/
|
|
182
|
+
foreignChildRoots: options.resolvedPageDependencyComponents,
|
|
183
|
+
layouts: resolveDocumentShellLayouts({
|
|
184
|
+
layout: options.Layout,
|
|
185
|
+
layoutEntries: options.layoutEntries,
|
|
186
|
+
params: options.params,
|
|
187
|
+
query: options.query,
|
|
188
|
+
locals: options.locals,
|
|
189
|
+
}),
|
|
190
|
+
htmlTemplate: options.HtmlTemplate,
|
|
191
|
+
metadata: options.metadata,
|
|
192
|
+
pageProps: options.pageProps ?? {},
|
|
193
|
+
});
|
|
194
|
+
this.recordHmrOwnership([
|
|
195
|
+
options.Page,
|
|
196
|
+
options.Layout,
|
|
197
|
+
options.HtmlTemplate,
|
|
198
|
+
...(options.resolvedPageDependencyComponents ?? []),
|
|
199
|
+
]);
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
throw this.createRenderError('Error rendering page', error);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
173
207
|
}
|
|
174
208
|
async renderComponent(input) {
|
|
175
|
-
return await this.withPreparedRadiantRuntime(async () =>
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
: input.children
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
runtimeContext: this.foreignSubtreeExecutionService.getQueuedRuntimeContext(input, getForeignSubtreeResolutionContextKey(this.name)),
|
|
196
|
-
queueLabel: 'Ecopages JSX',
|
|
197
|
-
getOwningRenderer: (integrationName, rendererCache) => resolveOwningIntegrationRenderer({
|
|
198
|
-
appConfig: this.appConfig,
|
|
199
|
-
runtimeOrigin: this.runtimeOrigin,
|
|
209
|
+
return await this.withPreparedRadiantRuntime(async () => {
|
|
210
|
+
await this.ssrScriptPreloader.preloadSsrScripts([input.component]);
|
|
211
|
+
return await this.renderSession.withActiveScope(async () => {
|
|
212
|
+
const assetFrame = this.renderSession.beginCollectedAssetFrame();
|
|
213
|
+
try {
|
|
214
|
+
if (typeof input.component !== 'function') {
|
|
215
|
+
throw new TypeError('JSX renderer expected a callable component.');
|
|
216
|
+
}
|
|
217
|
+
const component = input.component;
|
|
218
|
+
const componentProps = input.children === undefined
|
|
219
|
+
? input.props
|
|
220
|
+
: {
|
|
221
|
+
...input.props,
|
|
222
|
+
children: typeof input.children === 'string'
|
|
223
|
+
? createMarkupNodeLike(input.children)
|
|
224
|
+
: input.children,
|
|
225
|
+
};
|
|
226
|
+
const content = await this.withCustomElementRenderHook(() => component(componentProps));
|
|
227
|
+
const rendered = await this.renderJsx(content);
|
|
228
|
+
const queuedForeignSubtreeResolution = await this.foreignSubtreeExecutionService.resolveQueuedHtml({
|
|
200
229
|
currentIntegrationName: this.name,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
html: rendered.html,
|
|
231
|
+
runtimeContext: this.foreignSubtreeExecutionService.getQueuedRuntimeContext(input, getForeignSubtreeResolutionContextKey(this.name)),
|
|
232
|
+
queueLabel: 'Ecopages JSX',
|
|
233
|
+
getOwningRenderer: (integrationName, rendererCache) => resolveOwningIntegrationRenderer({
|
|
234
|
+
appConfig: this.appConfig,
|
|
235
|
+
runtimeOrigin: this.runtimeOrigin,
|
|
236
|
+
currentIntegrationName: this.name,
|
|
237
|
+
currentRenderer: this,
|
|
238
|
+
integrationName,
|
|
239
|
+
cache: rendererCache,
|
|
240
|
+
}),
|
|
241
|
+
applyAttributesToFirstElement: (resolvedHtml, attributes) => this.htmlTransformer.applyAttributesToFirstElement(resolvedHtml, attributes),
|
|
242
|
+
dedupeProcessedAssets: (assets) => this.htmlTransformer.dedupeProcessedAssets(assets),
|
|
243
|
+
renderQueuedChildren: (children, _runtimeContext, queuedResolutionsByToken, resolveToken) => this.renderQueuedForeignSubtreeChildren(children, queuedResolutionsByToken, resolveToken),
|
|
244
|
+
});
|
|
245
|
+
const componentAssets = input.component.config?.dependencies &&
|
|
246
|
+
typeof this.assetProcessingService?.processDependencies === 'function'
|
|
247
|
+
? await this.processComponentDependencies([input.component])
|
|
248
|
+
: [];
|
|
249
|
+
const assets = this.htmlTransformer.dedupeProcessedAssets([
|
|
250
|
+
...this.renderSession.endCollectedAssetFrame(assetFrame),
|
|
251
|
+
...queuedForeignSubtreeResolution.assets,
|
|
252
|
+
...componentAssets,
|
|
253
|
+
]);
|
|
254
|
+
this.recordHmrOwnership([input.component]);
|
|
255
|
+
return this.finalizeIslandComponentRender(input, {
|
|
256
|
+
html: queuedForeignSubtreeResolution.html,
|
|
257
|
+
canAttachAttributes: true,
|
|
258
|
+
rootTag: this.getRootTagName(queuedForeignSubtreeResolution.html),
|
|
259
|
+
integrationName: this.name,
|
|
260
|
+
assets,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
this.renderSession.endCollectedAssetFrame(assetFrame);
|
|
265
|
+
throw this.createRenderError('Error rendering component', error);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
});
|
|
232
269
|
}
|
|
233
270
|
async renderToResponse(view, props, ctx) {
|
|
234
|
-
return await this.withPreparedRadiantRuntime(async () =>
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
271
|
+
return await this.withPreparedRadiantRuntime(async () => {
|
|
272
|
+
const viewComponent = view;
|
|
273
|
+
const layouts = viewComponent.config?.layouts;
|
|
274
|
+
await this.ssrScriptPreloader.preloadSsrScripts([view, ...(layouts ?? [])]);
|
|
275
|
+
return await this.renderSession.withActiveScope(async () => {
|
|
276
|
+
try {
|
|
277
|
+
if (typeof view !== 'function') {
|
|
278
|
+
throw new TypeError('JSX renderer expected a callable view component.');
|
|
279
|
+
}
|
|
280
|
+
const response = await this.renderViewWithDocumentShell({
|
|
281
|
+
view: viewComponent,
|
|
282
|
+
props: props,
|
|
283
|
+
ctx,
|
|
284
|
+
layout: layouts?.[layouts.length - 1],
|
|
285
|
+
});
|
|
286
|
+
this.recordHmrOwnership([view]);
|
|
287
|
+
return response;
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
throw this.createRenderError('Error rendering view', error);
|
|
238
291
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const response = await this.renderViewWithDocumentShell({
|
|
242
|
-
view: viewComponent,
|
|
243
|
-
props: props,
|
|
244
|
-
ctx,
|
|
245
|
-
layout: layouts?.[layouts.length - 1],
|
|
246
|
-
});
|
|
247
|
-
this.recordHmrOwnership([view]);
|
|
248
|
-
return response;
|
|
249
|
-
}
|
|
250
|
-
catch (error) {
|
|
251
|
-
throw this.createRenderError('Error rendering view', error);
|
|
252
|
-
}
|
|
253
|
-
}));
|
|
292
|
+
});
|
|
293
|
+
});
|
|
254
294
|
}
|
|
255
295
|
async renderJsx(value) {
|
|
256
296
|
const collectedAssets = [];
|
|
@@ -150,7 +150,14 @@ export class EcopagesJsxPlugin extends IntegrationPlugin {
|
|
|
150
150
|
if (!this.mdxEnabled || !this.mdxCompilerOptions || this.mdxLoaderPlugin) {
|
|
151
151
|
return;
|
|
152
152
|
}
|
|
153
|
-
|
|
153
|
+
if (!this.appConfig?.rootDir) {
|
|
154
|
+
throw new Error('[EcopagesJsxPlugin] Cannot create MDX loader: appConfig.rootDir is required.');
|
|
155
|
+
}
|
|
156
|
+
this.mdxLoaderPlugin = createMdxLoaderPlugin({
|
|
157
|
+
compilerOptions: this.mdxCompilerOptions,
|
|
158
|
+
extensions: this.mdxExtensions,
|
|
159
|
+
projectRoot: this.appConfig.rootDir,
|
|
160
|
+
});
|
|
154
161
|
}
|
|
155
162
|
/**
|
|
156
163
|
* Registers Bun's MDX loader at runtime setup time.
|
|
@@ -162,7 +169,14 @@ export class EcopagesJsxPlugin extends IntegrationPlugin {
|
|
|
162
169
|
if (typeof Bun === 'undefined' || !this.mdxCompilerOptions) {
|
|
163
170
|
return;
|
|
164
171
|
}
|
|
165
|
-
|
|
172
|
+
if (!this.appConfig) {
|
|
173
|
+
throw new Error('[EcopagesJsxPlugin] Cannot register Bun MDX plugin: appConfig is not set');
|
|
174
|
+
}
|
|
175
|
+
await registerBunMdxPlugin({
|
|
176
|
+
compilerOptions: this.mdxCompilerOptions,
|
|
177
|
+
extensions: this.mdxExtensions,
|
|
178
|
+
projectRoot: this.appConfig.rootDir,
|
|
179
|
+
});
|
|
166
180
|
}
|
|
167
181
|
}
|
|
168
182
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { CUSTOM_ELEMENT_SSR_PRELOAD_CACHE_SCOPES, invalidateCustomElementScriptPreload, } from '@ecopages/core/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader';
|
|
2
3
|
const CUSTOM_ELEMENT_TAG_PATTERN = /@customElement\s*\(\s*['"`]([^'"`]+)['"`]/u;
|
|
3
4
|
/**
|
|
4
5
|
* Reads the custom-element tag name from a registered script module source file.
|
|
@@ -38,6 +39,7 @@ export function clearRadiantCustomElementDefinition(tagName) {
|
|
|
38
39
|
* Clears the SSR custom-element registry entry for one registered Radiant script module.
|
|
39
40
|
*/
|
|
40
41
|
export function invalidateRadiantRegisteredScriptSsrRegistration(scriptPath) {
|
|
42
|
+
invalidateCustomElementScriptPreload(scriptPath, CUSTOM_ELEMENT_SSR_PRELOAD_CACHE_SCOPES.ecopagesJsx);
|
|
41
43
|
const tagName = resolveRadiantCustomElementTag(scriptPath);
|
|
42
44
|
if (!tagName) {
|
|
43
45
|
return false;
|