@ecopages/react 0.2.0-beta.31 → 0.2.0-beta.32
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 +5 -1
- package/package.json +4 -4
- package/src/app/client-only.js +13 -17
- package/src/app/dynamic.js +7 -10
- package/src/app/dynamic.test.browser.js +27 -29
- package/src/bundling/bootstrap-package-paths.js +5 -6
- package/src/bundling/bundle.js +115 -114
- package/src/bundling/discover-layout-runtime-modules.js +166 -155
- package/src/bundling/runtime-alias-map.d.ts +4 -1
- package/src/bundling/runtime-alias-map.js +107 -95
- package/src/bundling/runtime-bundle.js +250 -274
- package/src/bundling/runtime-interop-plugin.js +31 -35
- package/src/bundling/runtime-mode.js +10 -5
- package/src/bundling/runtime-modules.js +46 -35
- package/src/client-graph/ast-transform.js +415 -305
- package/src/client-graph/boundary-cache.js +146 -104
- package/src/client-graph/boundary-plugin.js +122 -104
- package/src/client-graph/component-config-traversal.js +70 -49
- package/src/client-graph/declared-modules.js +63 -41
- package/src/client-graph/reachability-analyzer.js +506 -313
- package/src/client-graph/specifier-classification.js +209 -141
- package/src/contracts/router-adapter.js +6 -0
- package/src/dev-transform/react-dev-transform-contributor.d.ts +17 -0
- package/src/dev-transform/react-dev-transform-contributor.js +22 -0
- package/src/hmr/hmr-scripts.js +22 -9
- package/src/hmr/hmr-strategy.d.ts +12 -181
- package/src/hmr/hmr-strategy.js +321 -650
- package/src/hmr/page-metadata-cache.js +43 -40
- package/src/hmr/react-hmr-dev-transform-plugins.d.ts +23 -0
- package/src/hmr/react-hmr-dev-transform-plugins.js +20 -0
- package/src/hydration/assert-no-bare-ecopages-imports.js +6 -6
- package/src/hydration/bootstrap-imports.js +30 -20
- package/src/hydration/hydration-asset.js +216 -213
- package/src/hydration/hydration-scripts.d.ts +4 -0
- package/src/hydration/hydration-scripts.js +199 -66
- package/src/hydration/hydration-scripts.test.browser.js +163 -168
- package/src/hydration/page-data-manifest.js +89 -45
- package/src/hydration/page-data-reader.js +45 -32
- package/src/hydration/page-payload.js +101 -99
- package/src/hydration/serialize-page-data-script.js +27 -28
- package/src/mdx/mdx-config-dependency.js +108 -112
- package/src/mdx/mdx-loader-plugin.js +7 -10
- package/src/page/page-module.js +72 -66
- package/src/plugin/react.constants.js +1 -4
- package/src/plugin/react.plugin.d.ts +1 -0
- package/src/plugin/react.plugin.js +227 -216
- package/src/plugin/react.types.js +1 -0
- package/src/render/component-ownership.js +42 -18
- package/src/render/component-ssr.js +168 -190
- package/src/render/eco-embed.js +8 -10
- package/src/render/errors.js +21 -16
- package/src/render/html-boundary.js +55 -51
- package/src/render/layout-compose.js +122 -94
- package/src/render/react-renderer.js +433 -468
- package/src/render/react-runtime.js +25 -20
- package/src/render/unified-layout-composition.js +74 -85
- package/src/runtime/use-sync-external-store-with-selector.js +52 -54
|
@@ -1,23 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Ownership helpers for deciding whether a component stays in the React render lane.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Reads the declared integration name for a component or layout.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Honors both the explicit `config.integration` override and injected
|
|
9
|
+
* `config.__eco.integration` metadata because pages can arrive through authored
|
|
10
|
+
* config as well as build-time component metadata.
|
|
11
|
+
*/
|
|
12
|
+
export function getComponentIntegration(component) {
|
|
13
|
+
return component?.config?.integration ?? component?.config?.__eco?.integration;
|
|
3
14
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Returns whether a component should stay inside the React render lane.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Components without explicit integration metadata are treated as React-owned
|
|
20
|
+
* because this renderer only receives them after the route pipeline has already
|
|
21
|
+
* selected the React integration.
|
|
22
|
+
*/
|
|
23
|
+
export function isReactManagedComponent(component, reactIntegrationName) {
|
|
24
|
+
const integration = getComponentIntegration(component);
|
|
25
|
+
return integration === undefined || integration === reactIntegrationName;
|
|
7
26
|
}
|
|
8
|
-
function getComponentRequires(component) {
|
|
9
|
-
|
|
27
|
+
export function getComponentRequires(component) {
|
|
28
|
+
return component?.requires;
|
|
10
29
|
}
|
|
11
|
-
|
|
12
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Commits a framework-agnostic component to React semantics.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Core keeps `EcoComponent` broad so integrations can share the same public surface;
|
|
35
|
+
* once the React renderer is executing, `createElement()` needs a concrete React
|
|
36
|
+
* component signature.
|
|
37
|
+
*/
|
|
38
|
+
export function asReactComponent(component) {
|
|
39
|
+
return component;
|
|
13
40
|
}
|
|
14
|
-
|
|
15
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Commits a mixed-shell component to the string-returning contract required by
|
|
43
|
+
* non-React layouts and HTML templates.
|
|
44
|
+
*/
|
|
45
|
+
export function asNonReactShellComponent(component) {
|
|
46
|
+
return component;
|
|
16
47
|
}
|
|
17
|
-
export {
|
|
18
|
-
asNonReactShellComponent,
|
|
19
|
-
asReactComponent,
|
|
20
|
-
getComponentIntegration,
|
|
21
|
-
getComponentRequires,
|
|
22
|
-
isReactManagedComponent
|
|
23
|
-
};
|
|
@@ -1,202 +1,180 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
/**
|
|
2
|
+
* React component SSR helpers: renderToString, foreign-subtree HTML, island attributes.
|
|
3
|
+
*/
|
|
4
|
+
import { buildIslandHostAttributes } from '@ecopages/core';
|
|
5
|
+
import { isValidElement } from 'react';
|
|
6
|
+
import { hasSingleRootElement } from './html-boundary.js';
|
|
7
|
+
import { getIslandComponentKey } from '../hydration/hydration-asset.js';
|
|
8
|
+
import { asNonReactShellComponent, asReactComponent } from './component-ownership.js';
|
|
9
|
+
import { ReactRenderError } from './errors.js';
|
|
10
|
+
export function buildHydrationProps(props) {
|
|
11
|
+
if (!props || !Object.prototype.hasOwnProperty.call(props, 'locals')) {
|
|
12
|
+
return props ?? {};
|
|
13
|
+
}
|
|
14
|
+
const { locals: _locals, ...hydrationProps } = props;
|
|
15
|
+
return hydrationProps;
|
|
12
16
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Renders a non-React layout or HTML template and enforces that mixed shells
|
|
19
|
+
* return serialized HTML.
|
|
20
|
+
*/
|
|
21
|
+
export async function renderNonReactShellComponent(Component, props, label) {
|
|
22
|
+
const output = await Component(props);
|
|
23
|
+
if (typeof output === 'string') {
|
|
24
|
+
return output;
|
|
25
|
+
}
|
|
26
|
+
throw new ReactRenderError(`${label} must return a string when used as a mixed shell for React pages.`);
|
|
19
27
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Renders one React component while preserving already-resolved child HTML.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* When nested foreign-subtree resolution has already produced child HTML, the child
|
|
33
|
+
* payload must remain raw SSR output rather than a React string child, otherwise
|
|
34
|
+
* React would escape it. This helper renders a unique token through React and swaps
|
|
35
|
+
* that token back to the resolved HTML afterward.
|
|
36
|
+
*/
|
|
37
|
+
export function renderComponentHtml(options) {
|
|
38
|
+
const { input, context, runtimeContext, runtime, normalizeUnresolvedMarkerArtifactHtml } = options;
|
|
39
|
+
const { react, reactDomServer } = runtime;
|
|
40
|
+
if (input.children === undefined) {
|
|
41
|
+
return normalizeUnresolvedMarkerArtifactHtml(reactDomServer.renderToString(react.createElement(asReactComponent(input.component), input.props)));
|
|
42
|
+
}
|
|
43
|
+
if (isValidElement(input.children)) {
|
|
44
|
+
return normalizeUnresolvedMarkerArtifactHtml(reactDomServer.renderToString(react.createElement(asReactComponent(input.component), input.props, input.children)));
|
|
45
|
+
}
|
|
46
|
+
const resolvedChildHtml = typeof input.children === 'string' ? input.children : String(input.children ?? '');
|
|
47
|
+
const rawChildrenToken = `__ECO_RAW_HTML_CHILD_${context.componentInstanceId ?? 'component'}__`;
|
|
48
|
+
if (runtimeContext) {
|
|
49
|
+
runtimeContext.rawChildrenToken = rawChildrenToken;
|
|
50
|
+
runtimeContext.rawChildrenHtml = resolvedChildHtml;
|
|
51
|
+
}
|
|
52
|
+
const html = reactDomServer.renderToString(react.createElement(asReactComponent(input.component), input.props, rawChildrenToken));
|
|
53
|
+
return normalizeUnresolvedMarkerArtifactHtml(html.split(rawChildrenToken).join(resolvedChildHtml));
|
|
45
54
|
}
|
|
46
|
-
function toReactNode(children, integrationName) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
export function toReactNode(children, integrationName) {
|
|
56
|
+
if (children === null ||
|
|
57
|
+
typeof children === 'string' ||
|
|
58
|
+
typeof children === 'number' ||
|
|
59
|
+
typeof children === 'boolean' ||
|
|
60
|
+
isValidElement(children) ||
|
|
61
|
+
Array.isArray(children)) {
|
|
62
|
+
return children;
|
|
63
|
+
}
|
|
64
|
+
throw new TypeError(`[ecopages] ${integrationName} renderer expected a React node child.`);
|
|
51
65
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Restores raw child HTML placeholders stored on the foreign-subtree runtime context.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* Queued foreign-subtree resolution may render children through a fragment path before
|
|
71
|
+
* nested integration tokens are resolved. React must never see resolved child HTML as a
|
|
72
|
+
* normal string child or it would escape it.
|
|
73
|
+
*/
|
|
74
|
+
export function restoreRuntimeChildHtml(html, runtimeContext) {
|
|
75
|
+
if (!runtimeContext?.rawChildrenToken || runtimeContext.rawChildrenHtml === undefined) {
|
|
76
|
+
return html;
|
|
77
|
+
}
|
|
78
|
+
return html.split(runtimeContext.rawChildrenToken).join(runtimeContext.rawChildrenHtml);
|
|
57
79
|
}
|
|
58
|
-
async function renderQueuedChildrenToHtml(options) {
|
|
59
|
-
|
|
60
|
-
children
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
resolveQueuedTokens
|
|
68
|
-
} = options;
|
|
69
|
-
if (children === void 0) {
|
|
70
|
-
return void 0;
|
|
71
|
-
}
|
|
72
|
-
const { react, reactDomServer } = runtime;
|
|
73
|
-
let html = normalizeUnresolvedMarkerArtifactHtml(
|
|
74
|
-
reactDomServer.renderToString(
|
|
75
|
-
react.createElement(react.Fragment, null, toReactNode(children, integrationName))
|
|
76
|
-
)
|
|
77
|
-
);
|
|
78
|
-
html = restoreRuntimeChildHtml(html, runtimeContext);
|
|
79
|
-
return await resolveQueuedTokens(html, queuedResolutionsByToken, resolveToken);
|
|
80
|
+
export async function renderQueuedChildrenToHtml(options) {
|
|
81
|
+
const { children, runtimeContext, queuedResolutionsByToken, resolveToken, runtime, integrationName, normalizeUnresolvedMarkerArtifactHtml, resolveQueuedTokens, } = options;
|
|
82
|
+
if (children === undefined) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
const { react, reactDomServer } = runtime;
|
|
86
|
+
let html = normalizeUnresolvedMarkerArtifactHtml(reactDomServer.renderToString(react.createElement(react.Fragment, null, toReactNode(children, integrationName))));
|
|
87
|
+
html = restoreRuntimeChildHtml(html, runtimeContext);
|
|
88
|
+
return await resolveQueuedTokens(html, queuedResolutionsByToken, resolveToken);
|
|
80
89
|
}
|
|
81
|
-
async function renderReactQueuedForeignSubtreeChildren(options) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
export async function renderReactQueuedForeignSubtreeChildren(options) {
|
|
91
|
+
const { currentRuntimeContext, ...rest } = options;
|
|
92
|
+
const renderedHtml = await renderQueuedChildrenToHtml({
|
|
93
|
+
...rest,
|
|
94
|
+
runtimeContext: currentRuntimeContext,
|
|
95
|
+
});
|
|
96
|
+
if (renderedHtml === undefined) {
|
|
97
|
+
return { assets: [] };
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
assets: [],
|
|
101
|
+
html: renderedHtml,
|
|
102
|
+
};
|
|
94
103
|
}
|
|
95
|
-
async function renderForeignComponentWithSerializedHtml(options) {
|
|
96
|
-
|
|
97
|
-
input
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
export async function renderForeignComponentWithSerializedHtml(options) {
|
|
105
|
+
const { input, runtimeContext, integrationName, canResolveAssets, processComponentDependencies, dedupeProcessedAssets, getRootTagName, resolveQueuedForeignSubtreeHtml, } = options;
|
|
106
|
+
let props = input.props;
|
|
107
|
+
if (input.children !== undefined) {
|
|
108
|
+
props = {
|
|
109
|
+
...input.props,
|
|
110
|
+
children: typeof input.children === 'string' ? input.children : String(input.children ?? ''),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const html = await renderNonReactShellComponent(asNonReactShellComponent(input.component), props, 'Component');
|
|
114
|
+
const hasDependencies = Boolean(input.component.config?.dependencies);
|
|
115
|
+
const assets = hasDependencies && canResolveAssets ? await processComponentDependencies([input.component]) : undefined;
|
|
116
|
+
const queuedForeignSubtreeResolution = await resolveQueuedForeignSubtreeHtml(html, runtimeContext);
|
|
117
|
+
const mergedAssets = dedupeProcessedAssets([...(assets ?? []), ...queuedForeignSubtreeResolution.assets]);
|
|
118
|
+
return {
|
|
119
|
+
html: queuedForeignSubtreeResolution.html,
|
|
120
|
+
canAttachAttributes: true,
|
|
121
|
+
rootTag: getRootTagName(queuedForeignSubtreeResolution.html),
|
|
122
|
+
integrationName,
|
|
123
|
+
assets: mergedAssets.length > 0 ? mergedAssets : undefined,
|
|
111
124
|
};
|
|
112
|
-
}
|
|
113
|
-
const html = await renderNonReactShellComponent(
|
|
114
|
-
asNonReactShellComponent(input.component),
|
|
115
|
-
props,
|
|
116
|
-
"Component"
|
|
117
|
-
);
|
|
118
|
-
const hasDependencies = Boolean(input.component.config?.dependencies);
|
|
119
|
-
const assets = hasDependencies && canResolveAssets ? await processComponentDependencies([input.component]) : void 0;
|
|
120
|
-
const queuedForeignSubtreeResolution = await resolveQueuedForeignSubtreeHtml(html, runtimeContext);
|
|
121
|
-
const mergedAssets = dedupeProcessedAssets([...assets ?? [], ...queuedForeignSubtreeResolution.assets]);
|
|
122
|
-
return {
|
|
123
|
-
html: queuedForeignSubtreeResolution.html,
|
|
124
|
-
canAttachAttributes: true,
|
|
125
|
-
rootTag: getRootTagName(queuedForeignSubtreeResolution.html),
|
|
126
|
-
integrationName,
|
|
127
|
-
assets: mergedAssets.length > 0 ? mergedAssets : void 0
|
|
128
|
-
};
|
|
129
125
|
}
|
|
130
|
-
async function renderReactManagedComponent(options) {
|
|
131
|
-
|
|
132
|
-
input
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
126
|
+
export async function renderReactManagedComponent(options) {
|
|
127
|
+
const { input, runtimeContext, runtime, integrationName, normalizeUnresolvedMarkerArtifactHtml, resolveQueuedForeignSubtreeHtml, getRootTagName, dedupeProcessedAssets, hydrationAssetService, canBuildIslandAssets, } = options;
|
|
128
|
+
const componentConfig = input.component.config;
|
|
129
|
+
const context = {
|
|
130
|
+
componentInstanceId: input.integrationContext?.componentInstanceId,
|
|
131
|
+
};
|
|
132
|
+
const hasResolvedChildHtml = input.children !== undefined;
|
|
133
|
+
let html = renderComponentHtml({
|
|
134
|
+
input,
|
|
135
|
+
context,
|
|
136
|
+
runtimeContext,
|
|
137
|
+
runtime,
|
|
138
|
+
normalizeUnresolvedMarkerArtifactHtml,
|
|
139
|
+
});
|
|
140
|
+
const queuedForeignSubtreeResolution = await resolveQueuedForeignSubtreeHtml(html, runtimeContext);
|
|
141
|
+
html = queuedForeignSubtreeResolution.html;
|
|
142
|
+
const canAttachAttributes = hasSingleRootElement(html);
|
|
143
|
+
const rootTag = getRootTagName(html);
|
|
144
|
+
const componentFile = componentConfig?.__eco?.file;
|
|
145
|
+
let rootAttributes;
|
|
146
|
+
let assets;
|
|
147
|
+
if (canAttachAttributes &&
|
|
148
|
+
componentFile &&
|
|
149
|
+
context.componentInstanceId &&
|
|
150
|
+
canBuildIslandAssets &&
|
|
151
|
+
!hasResolvedChildHtml) {
|
|
152
|
+
const componentInstanceId = context.componentInstanceId;
|
|
153
|
+
assets = await hydrationAssetService.buildComponentRenderAssets(componentFile, componentConfig);
|
|
154
|
+
rootAttributes = buildIslandHostAttributes({
|
|
155
|
+
integrationName,
|
|
156
|
+
componentInstanceId,
|
|
157
|
+
componentKey: getIslandComponentKey(componentFile, componentConfig),
|
|
158
|
+
props: buildHydrationProps(input.props),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
const mergedAssets = dedupeProcessedAssets([...(assets ?? []), ...queuedForeignSubtreeResolution.assets]);
|
|
162
|
+
return {
|
|
163
|
+
html,
|
|
164
|
+
canAttachAttributes,
|
|
165
|
+
rootTag,
|
|
166
|
+
integrationName,
|
|
167
|
+
rootAttributes,
|
|
168
|
+
assets: mergedAssets.length > 0 ? mergedAssets : undefined,
|
|
169
169
|
};
|
|
170
|
-
}
|
|
171
|
-
const mergedAssets = dedupeProcessedAssets([...assets ?? [], ...queuedForeignSubtreeResolution.assets]);
|
|
172
|
-
return {
|
|
173
|
-
html,
|
|
174
|
-
canAttachAttributes,
|
|
175
|
-
rootTag,
|
|
176
|
-
integrationName,
|
|
177
|
-
rootAttributes,
|
|
178
|
-
assets: mergedAssets.length > 0 ? mergedAssets : void 0
|
|
179
|
-
};
|
|
180
170
|
}
|
|
181
|
-
function createForeignSubtreeRuntimeContext(options) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
171
|
+
export function createForeignSubtreeRuntimeContext(options) {
|
|
172
|
+
return {
|
|
173
|
+
rendererCache: options.rendererCache,
|
|
174
|
+
componentInstanceScope: options.componentInstanceScope,
|
|
175
|
+
nextForeignSubtreeId: 0,
|
|
176
|
+
queuedResolutions: [],
|
|
177
|
+
rawChildrenToken: undefined,
|
|
178
|
+
rawChildrenHtml: undefined,
|
|
179
|
+
};
|
|
190
180
|
}
|
|
191
|
-
export {
|
|
192
|
-
buildHydrationProps,
|
|
193
|
-
createForeignSubtreeRuntimeContext,
|
|
194
|
-
renderComponentHtml,
|
|
195
|
-
renderForeignComponentWithSerializedHtml,
|
|
196
|
-
renderNonReactShellComponent,
|
|
197
|
-
renderQueuedChildrenToHtml,
|
|
198
|
-
renderReactManagedComponent,
|
|
199
|
-
renderReactQueuedForeignSubtreeChildren,
|
|
200
|
-
restoreRuntimeChildHtml,
|
|
201
|
-
toReactNode
|
|
202
|
-
};
|
package/src/render/eco-embed.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/** @jsxImportSource react */
|
|
2
|
+
import { eco } from '@ecopages/core';
|
|
3
|
+
/**
|
|
4
|
+
* Renders a foreign or same-integration eco component from a React JSX file
|
|
5
|
+
* without forcing inline mixed-JSX authoring.
|
|
6
|
+
*/
|
|
7
|
+
export function EcoEmbed({ component, props, children, }) {
|
|
8
|
+
return eco.embed(component, props, children);
|
|
8
9
|
}
|
|
9
|
-
export {
|
|
10
|
-
EcoEmbed
|
|
11
|
-
};
|
package/src/render/errors.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Errors thrown by the React integration renderer and bundling paths.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when an error occurs while rendering a React component.
|
|
6
|
+
*/
|
|
7
|
+
export class ReactRenderError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'ReactRenderError';
|
|
11
|
+
}
|
|
6
12
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Error thrown when an error occurs while bundling a React component.
|
|
15
|
+
*/
|
|
16
|
+
export class BundleError extends Error {
|
|
17
|
+
logs;
|
|
18
|
+
constructor(message, logs) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = 'BundleError';
|
|
21
|
+
this.logs = logs;
|
|
22
|
+
}
|
|
14
23
|
}
|
|
15
|
-
export {
|
|
16
|
-
BundleError,
|
|
17
|
-
ReactRenderError
|
|
18
|
-
};
|
|
@@ -1,55 +1,59 @@
|
|
|
1
|
-
const VOID_TAGS =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
const VOID_TAGS = new Set([
|
|
2
|
+
'area',
|
|
3
|
+
'base',
|
|
4
|
+
'br',
|
|
5
|
+
'col',
|
|
6
|
+
'embed',
|
|
7
|
+
'hr',
|
|
8
|
+
'img',
|
|
9
|
+
'input',
|
|
10
|
+
'link',
|
|
11
|
+
'meta',
|
|
12
|
+
'param',
|
|
13
|
+
'source',
|
|
14
|
+
'track',
|
|
15
|
+
'wbr',
|
|
16
16
|
]);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const tagName = token[1].toLowerCase();
|
|
36
|
-
const isClosing = tagText.startsWith("</");
|
|
37
|
-
const tokenSelfClosing = /\/\s*>$/.test(tagText);
|
|
38
|
-
if (VOID_TAGS.has(tagName) || tokenSelfClosing) {
|
|
39
|
-
continue;
|
|
17
|
+
/**
|
|
18
|
+
* Returns true when HTML contains exactly one root element node.
|
|
19
|
+
*
|
|
20
|
+
* Used by component-level React rendering to decide whether root attributes can
|
|
21
|
+
* be attached safely without introducing synthetic wrapper nodes.
|
|
22
|
+
*/
|
|
23
|
+
export function hasSingleRootElement(html) {
|
|
24
|
+
const firstTagMatch = html.match(/^\s*<([a-zA-Z][a-zA-Z0-9:-]*)\b[^>]*>/);
|
|
25
|
+
if (!firstTagMatch) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const firstTag = firstTagMatch[1].toLowerCase();
|
|
29
|
+
const firstTagText = firstTagMatch[0];
|
|
30
|
+
const firstTagStart = firstTagMatch.index ?? 0;
|
|
31
|
+
const firstTagEnd = firstTagStart + firstTagText.length;
|
|
32
|
+
const isSelfClosing = /\/\s*>$/.test(firstTagText);
|
|
33
|
+
if (isSelfClosing || VOID_TAGS.has(firstTag)) {
|
|
34
|
+
return html.slice(firstTagEnd).trim().length === 0;
|
|
40
35
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
const tokenRegex = /<\/?([a-zA-Z][a-zA-Z0-9:-]*)\b[^>]*>/g;
|
|
37
|
+
tokenRegex.lastIndex = firstTagEnd;
|
|
38
|
+
let depth = 1;
|
|
39
|
+
for (let token = tokenRegex.exec(html); token; token = tokenRegex.exec(html)) {
|
|
40
|
+
const tagText = token[0];
|
|
41
|
+
const tagName = token[1].toLowerCase();
|
|
42
|
+
const isClosing = tagText.startsWith('</');
|
|
43
|
+
const tokenSelfClosing = /\/\s*>$/.test(tagText);
|
|
44
|
+
if (VOID_TAGS.has(tagName) || tokenSelfClosing) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (isClosing) {
|
|
48
|
+
depth--;
|
|
49
|
+
if (depth === 0) {
|
|
50
|
+
const afterRoot = html.slice(token.index + token[0].length).trim();
|
|
51
|
+
return afterRoot.length === 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
depth++;
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
|
-
|
|
51
|
-
return false;
|
|
58
|
+
return false;
|
|
52
59
|
}
|
|
53
|
-
export {
|
|
54
|
-
hasSingleRootElement
|
|
55
|
-
};
|