@ecopages/ecopages-jsx 0.3.2 → 0.5.0
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 +1 -1
- package/package.json +4 -4
- package/src/ecopages-jsx-renderer.js +20 -37
package/README.md
CHANGED
|
@@ -123,5 +123,5 @@ Important:
|
|
|
123
123
|
- Components that may render foreign children must declare those children in `config.dependencies.components`.
|
|
124
124
|
- Ecopages validates mixed-renderer ownership from declared dependencies during render preparation. It does not treat rendered HTML alone as the source of truth.
|
|
125
125
|
- Route-level dependency resolvers can supply Components at request time; Ecopages JSX includes those resolved roots when deciding whether a Foreign Subtree needs handoff.
|
|
126
|
-
- Ecopages JSX keeps raw-markup preservation
|
|
126
|
+
- Ecopages JSX keeps raw-markup preservation inside the JSX renderer.
|
|
127
127
|
- JSX renderers use the required core `AssetProcessingService` to process declared component dependencies.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/ecopages-jsx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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/file-system": "0.
|
|
38
|
-
"@ecopages/mdx": "0.
|
|
37
|
+
"@ecopages/file-system": "0.5.0",
|
|
38
|
+
"@ecopages/mdx": "0.5.0",
|
|
39
39
|
"@mdx-js/mdx": "^3.1.1",
|
|
40
40
|
"vfile": "^6.0.3"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@ecopages/core": "0.
|
|
43
|
+
"@ecopages/core": "0.5.0",
|
|
44
44
|
"@ecopages/jsx": "^0.4.0",
|
|
45
45
|
"@ecopages/radiant": "^0.4.0"
|
|
46
46
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { HttpError } from '@ecopages/core/errors';
|
|
2
1
|
import { createIntegrationRenderer, } from '@ecopages/core/integration';
|
|
3
2
|
import { resolveQueuedTokens } from '@ecopages/core/integration';
|
|
4
3
|
import { createMarkupNodeLike } from '@ecopages/jsx';
|
|
@@ -17,7 +16,7 @@ export function createEcopagesJsxRenderer(jsxConfig = {}) {
|
|
|
17
16
|
/** Creates JSX renderer hooks that can also configure a custom renderer subclass. */
|
|
18
17
|
export function createEcopagesJsxRendererHookFactory(jsxConfig = {}) {
|
|
19
18
|
const mdxExtensions = jsxConfig.mdxExtensions ?? ['.mdx'];
|
|
20
|
-
return ({ appConfig,
|
|
19
|
+
return ({ appConfig, resolveDependencyPath }) => {
|
|
21
20
|
const radiantSsrPolicy = new EcopagesJsxRadiantSsrPolicy(jsxConfig.radiantSsrEnabled ?? false);
|
|
22
21
|
const ssrScriptPreloader = new CustomElementScriptPreloader({
|
|
23
22
|
cacheScope: CUSTOM_ELEMENT_SSR_PRELOAD_CACHE_SCOPES.ecopagesJsx,
|
|
@@ -54,35 +53,26 @@ export function createEcopagesJsxRendererHookFactory(jsxConfig = {}) {
|
|
|
54
53
|
await radiantSsrPolicy.prepareRuntime();
|
|
55
54
|
await ssrScriptPreloader.preloadSsrScripts([input.component]);
|
|
56
55
|
return await withEjsxHmrOwnershipScope(async () => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
throw new TypeError('JSX renderer expected a callable component.');
|
|
60
|
-
}
|
|
61
|
-
const component = input.component;
|
|
62
|
-
const componentProps = input.children === undefined
|
|
63
|
-
? input.props
|
|
64
|
-
: {
|
|
65
|
-
...input.props,
|
|
66
|
-
children: typeof input.children === 'string'
|
|
67
|
-
? createMarkupNodeLike(input.children)
|
|
68
|
-
: input.children,
|
|
69
|
-
};
|
|
70
|
-
const content = await withCustomElementRenderHook(() => component(componentProps));
|
|
71
|
-
const html = await renderJsx(content);
|
|
72
|
-
const assets = input.component.config?.dependencies
|
|
73
|
-
? await resolveComponentDependencies([input.component])
|
|
74
|
-
: undefined;
|
|
75
|
-
recordEjsxHmrOwnership([input.component]);
|
|
76
|
-
return {
|
|
77
|
-
html,
|
|
78
|
-
canAttachAttributes: true,
|
|
79
|
-
integrationName: ECOPAGES_JSX_PLUGIN_NAME,
|
|
80
|
-
assets,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
throw createRenderError('Error rendering component', error);
|
|
56
|
+
if (typeof input.component !== 'function') {
|
|
57
|
+
throw new TypeError('JSX renderer expected a callable component.');
|
|
85
58
|
}
|
|
59
|
+
const component = input.component;
|
|
60
|
+
const componentProps = input.children === undefined
|
|
61
|
+
? input.props
|
|
62
|
+
: {
|
|
63
|
+
...input.props,
|
|
64
|
+
children: typeof input.children === 'string'
|
|
65
|
+
? createMarkupNodeLike(input.children)
|
|
66
|
+
: input.children,
|
|
67
|
+
};
|
|
68
|
+
const content = await withCustomElementRenderHook(() => component(componentProps));
|
|
69
|
+
const html = await renderJsx(content);
|
|
70
|
+
recordEjsxHmrOwnership([input.component]);
|
|
71
|
+
return {
|
|
72
|
+
html,
|
|
73
|
+
canAttachAttributes: true,
|
|
74
|
+
integrationName: ECOPAGES_JSX_PLUGIN_NAME,
|
|
75
|
+
};
|
|
86
76
|
});
|
|
87
77
|
},
|
|
88
78
|
renderQueuedChildren: async (children, _runtimeContext, queuedResolutionsByToken, resolveToken) => {
|
|
@@ -146,10 +136,3 @@ function isJsxSerializableForeignChild(children) {
|
|
|
146
136
|
}
|
|
147
137
|
return 'strings' in children && Array.isArray(children.strings);
|
|
148
138
|
}
|
|
149
|
-
function createRenderError(message, cause) {
|
|
150
|
-
if (HttpError.isHttpError(cause)) {
|
|
151
|
-
return cause;
|
|
152
|
-
}
|
|
153
|
-
const errorMessage = cause instanceof Error ? `${message}: ${cause.message}` : message;
|
|
154
|
-
return HttpError.InternalServerError(errorMessage);
|
|
155
|
-
}
|