@ecopages/ecopages-jsx 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.
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.
|
|
@@ -103,4 +126,5 @@ Important:
|
|
|
103
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.8",
|
|
4
4
|
"description": "JSX integration plugin for Ecopages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"directory": "packages/integrations/ecopages-jsx"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@ecopages/mdx": "0.2.0-rc.
|
|
37
|
+
"@ecopages/mdx": "0.2.0-rc.8",
|
|
38
38
|
"@mdx-js/mdx": "^3.1.1",
|
|
39
39
|
"vfile": "^6.0.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@ecopages/core": "0.2.0-rc.
|
|
43
|
-
"@ecopages/jsx": "^0.3.0-rc.
|
|
44
|
-
"@ecopages/radiant": "^0.3.0-rc.
|
|
42
|
+
"@ecopages/core": "0.2.0-rc.8",
|
|
43
|
+
"@ecopages/jsx": "^0.3.0-rc.9",
|
|
44
|
+
"@ecopages/radiant": "^0.3.0-rc.9"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -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
|
*
|
|
@@ -7,6 +7,8 @@ import { ECOPAGES_JSX_PLUGIN_NAME } from './ecopages-jsx.constants.js';
|
|
|
7
7
|
import { isMdxFile, normalizeMdxPageModule, } from './ecopages-jsx-mdx.js';
|
|
8
8
|
import { EcopagesJsxRenderSession } from './ecopages-jsx-render-session.js';
|
|
9
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 { createCustomElementSsrPreloadEntrypointResolver } from '@ecopages/core/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint';
|
|
10
12
|
/**
|
|
11
13
|
* Local Ecopages renderer for JSX templates in the docs app.
|
|
12
14
|
*
|
|
@@ -18,6 +20,7 @@ export class EcopagesJsxRenderer extends IntegrationRenderer {
|
|
|
18
20
|
mdxExtensions;
|
|
19
21
|
renderSession;
|
|
20
22
|
radiantSsrPolicy;
|
|
23
|
+
ssrScriptPreloader;
|
|
21
24
|
/**
|
|
22
25
|
* Serializes foreign-child props for string-first boundaries.
|
|
23
26
|
*
|
|
@@ -122,8 +125,26 @@ export class EcopagesJsxRenderer extends IntegrationRenderer {
|
|
|
122
125
|
});
|
|
123
126
|
this.mdxExtensions = jsxConfig?.mdxExtensions ?? ['.mdx'];
|
|
124
127
|
this.renderSession = new EcopagesJsxRenderSession((assets) => this.htmlTransformer.dedupeProcessedAssets(assets));
|
|
125
|
-
|
|
126
|
-
|
|
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
|
+
/**
|
|
134
|
+
* @remarks
|
|
135
|
+
* Node production builds evaluate registration scripts through the
|
|
136
|
+
* asset pipeline during render. Preloading through the app module loader
|
|
137
|
+
* registers Radiant hosts in an isolated graph and breaks SSR.
|
|
138
|
+
*/
|
|
139
|
+
enabled: radiantSsrEnabled && preferSourceImports,
|
|
140
|
+
logLabel: 'ecopages-jsx',
|
|
141
|
+
preferSourceImports,
|
|
142
|
+
resolveDependencyPath: (componentDir, sourcePath) => this.resolveDependencyPath(componentDir, sourcePath),
|
|
143
|
+
resolvePreloadEntrypoint: createCustomElementSsrPreloadEntrypointResolver({
|
|
144
|
+
preferSourceImports,
|
|
145
|
+
processDependencies: this.assetProcessingService?.processDependencies?.bind(this.assetProcessingService),
|
|
146
|
+
}),
|
|
147
|
+
});
|
|
127
148
|
}
|
|
128
149
|
/** Returns whether the requested page file should be treated as MDX. */
|
|
129
150
|
isMdxFile(filePath) {
|
|
@@ -136,120 +157,140 @@ export class EcopagesJsxRenderer extends IntegrationRenderer {
|
|
|
136
157
|
});
|
|
137
158
|
}
|
|
138
159
|
async render(options) {
|
|
139
|
-
return await this.withPreparedRadiantRuntime(async () =>
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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,
|
|
172
|
+
props: {
|
|
173
|
+
...options.pageProps,
|
|
174
|
+
locals: options.pageLocals,
|
|
175
|
+
},
|
|
147
176
|
},
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
+
});
|
|
172
207
|
}
|
|
173
208
|
async renderComponent(input) {
|
|
174
|
-
return await this.withPreparedRadiantRuntime(async () =>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
: input.children
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
runtimeContext: this.foreignSubtreeExecutionService.getQueuedRuntimeContext(input, getForeignSubtreeResolutionContextKey(this.name)),
|
|
195
|
-
queueLabel: 'Ecopages JSX',
|
|
196
|
-
getOwningRenderer: (integrationName, rendererCache) => resolveOwningIntegrationRenderer({
|
|
197
|
-
appConfig: this.appConfig,
|
|
198
|
-
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({
|
|
199
229
|
currentIntegrationName: this.name,
|
|
200
|
-
|
|
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
|
-
|
|
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
|
+
});
|
|
231
269
|
}
|
|
232
270
|
async renderToResponse(view, props, ctx) {
|
|
233
|
-
return await this.withPreparedRadiantRuntime(async () =>
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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);
|
|
237
291
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const response = await this.renderViewWithDocumentShell({
|
|
241
|
-
view: viewComponent,
|
|
242
|
-
props: props,
|
|
243
|
-
ctx,
|
|
244
|
-
layout: layouts?.[layouts.length - 1],
|
|
245
|
-
});
|
|
246
|
-
this.recordHmrOwnership([view]);
|
|
247
|
-
return response;
|
|
248
|
-
}
|
|
249
|
-
catch (error) {
|
|
250
|
-
throw this.createRenderError('Error rendering view', error);
|
|
251
|
-
}
|
|
252
|
-
}));
|
|
292
|
+
});
|
|
293
|
+
});
|
|
253
294
|
}
|
|
254
295
|
async renderJsx(value) {
|
|
255
296
|
const collectedAssets = [];
|
|
@@ -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;
|