@ecopages/react 0.2.0-beta.31 → 0.2.0-beta.33
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,21 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Resolves the React and react-dom/server modules used for SSR.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Prefers the app's own React install so SSR identity matches the app bundle.
|
|
6
|
+
* Falls back to the integration's React when the app package cannot resolve them.
|
|
7
|
+
*/
|
|
8
|
+
import { createRequire } from 'node:module';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
export function resolveReactRuntimeModules(rootDir) {
|
|
11
|
+
const appPackageJsonPath = path.resolve(rootDir || process.cwd(), 'package.json');
|
|
12
|
+
try {
|
|
13
|
+
const requireFromApp = createRequire(appPackageJsonPath);
|
|
14
|
+
return {
|
|
15
|
+
react: requireFromApp('react'),
|
|
16
|
+
reactDomServer: requireFromApp('react-dom/server'),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
const requireFromIntegration = createRequire(import.meta.url);
|
|
21
|
+
return {
|
|
22
|
+
react: requireFromIntegration('react'),
|
|
23
|
+
reactDomServer: requireFromIntegration('react-dom/server'),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
18
26
|
}
|
|
19
|
-
export {
|
|
20
|
-
resolveReactRuntimeModules
|
|
21
|
-
};
|
|
@@ -1,89 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
const composablePage = assertComposablePage(page);
|
|
22
|
-
const configLayouts = composablePage.config?.layouts ?? composablePage.config?.layoutEntries?.map((entry) => entry.component) ?? [];
|
|
23
|
-
const layoutComponents = shellLayouts.length > 0 ? shellLayouts.map((layout) => layout.component) : configLayouts;
|
|
24
|
-
if (layoutComponents.length === 0) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
return layoutComponents.every((component) => isReactManagedComponent(component, reactIntegrationName));
|
|
1
|
+
/**
|
|
2
|
+
* Unified React layout + page composition for SSR document shells.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* When every shell layout is React-managed, compose one element tree via
|
|
6
|
+
* {@link composeLayoutPageTree} / {@link composeLayoutPageTreeFromShell} instead of
|
|
7
|
+
* rendering each tier separately. This keeps SSR DOM shape aligned with client
|
|
8
|
+
* hydration through `@ecopages/react/layout-compose`.
|
|
9
|
+
*/
|
|
10
|
+
import { hasSingleRootElement } from './html-boundary.js';
|
|
11
|
+
import { isReactManagedComponent } from './component-ownership.js';
|
|
12
|
+
import { assertComposablePage, composeLayoutPageTree, composeLayoutPageTreeFromShell, resolveLayoutContextFromShell, } from './layout-compose.js';
|
|
13
|
+
export function composeReactLayoutPageTree(Page, pageProps, shellEntries, options) {
|
|
14
|
+
const hasNormalizedLayouts = Boolean(Page.config?.layoutEntries?.length) || Boolean(Page.config?.layouts?.length);
|
|
15
|
+
if (hasNormalizedLayouts) {
|
|
16
|
+
return composeLayoutPageTree(Page, pageProps, options);
|
|
17
|
+
}
|
|
18
|
+
return composeLayoutPageTreeFromShell(Page, pageProps, shellEntries, options);
|
|
28
19
|
}
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
20
|
+
export function shouldUseUnifiedReactLayoutComposition(options) {
|
|
21
|
+
const { page, shellLayouts, reactIntegrationName } = options;
|
|
22
|
+
if (!isReactManagedComponent(page, reactIntegrationName)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const composablePage = assertComposablePage(page);
|
|
26
|
+
const configLayouts = composablePage.config?.layouts ?? composablePage.config?.layoutEntries?.map((entry) => entry.component) ?? [];
|
|
27
|
+
const layoutComponents = shellLayouts.length > 0 ? shellLayouts.map((layout) => layout.component) : configLayouts;
|
|
28
|
+
if (layoutComponents.length === 0) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return layoutComponents.every((component) => isReactManagedComponent(component, reactIntegrationName));
|
|
39
32
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
getQueuedForeignSubtreeResolutionContext,
|
|
49
|
-
resolveQueuedForeignSubtreeHtml
|
|
50
|
-
} = options;
|
|
51
|
-
const pageComponent = assertComposablePage(page.component);
|
|
52
|
-
const shellEntries = context.layouts.map((layout) => ({
|
|
53
|
-
component: layout.component,
|
|
54
|
-
props: layout.props
|
|
55
|
-
}));
|
|
56
|
-
const { react, reactDomServer } = runtime;
|
|
57
|
-
const tree = composeReactLayoutPageTree(pageComponent, page.props, shellEntries, {
|
|
58
|
-
context: resolveLayoutContextFromShell(page.props, shellEntries),
|
|
59
|
-
react
|
|
60
|
-
});
|
|
61
|
-
const runtimeInput = {
|
|
62
|
-
component: page.component,
|
|
63
|
-
props: page.props,
|
|
64
|
-
integrationContext: {
|
|
65
|
-
rendererCache: context.rendererCache
|
|
33
|
+
export function resolveComposeChildren(options) {
|
|
34
|
+
const { page, shellLayouts, reactIntegrationName, composeChildren } = options;
|
|
35
|
+
if (!shouldUseUnifiedReactLayoutComposition({
|
|
36
|
+
page: page.component,
|
|
37
|
+
shellLayouts,
|
|
38
|
+
reactIntegrationName,
|
|
39
|
+
})) {
|
|
40
|
+
return undefined;
|
|
66
41
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
42
|
+
return (context) => composeChildren(page, context);
|
|
43
|
+
}
|
|
44
|
+
export async function composeReactLayoutPageChildren(options) {
|
|
45
|
+
const { page, context, runtime, integrationName, normalizeUnresolvedMarkerArtifactHtml, getRootTagName, getQueuedForeignSubtreeResolutionContext, resolveQueuedForeignSubtreeHtml, } = options;
|
|
46
|
+
const pageComponent = assertComposablePage(page.component);
|
|
47
|
+
const shellEntries = context.layouts.map((layout) => ({
|
|
48
|
+
component: layout.component,
|
|
49
|
+
props: layout.props,
|
|
50
|
+
}));
|
|
51
|
+
const { react, reactDomServer } = runtime;
|
|
52
|
+
const tree = composeReactLayoutPageTree(pageComponent, page.props, shellEntries, {
|
|
53
|
+
context: resolveLayoutContextFromShell(page.props, shellEntries),
|
|
54
|
+
react,
|
|
55
|
+
});
|
|
56
|
+
const runtimeInput = {
|
|
57
|
+
component: page.component,
|
|
58
|
+
props: page.props,
|
|
59
|
+
integrationContext: {
|
|
60
|
+
rendererCache: context.rendererCache,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
const runtimeContext = getQueuedForeignSubtreeResolutionContext(runtimeInput);
|
|
64
|
+
const html = normalizeUnresolvedMarkerArtifactHtml(reactDomServer.renderToString(tree));
|
|
65
|
+
const resolved = await resolveQueuedForeignSubtreeHtml(html, runtimeContext);
|
|
66
|
+
const primaryRender = {
|
|
67
|
+
html: resolved.html,
|
|
68
|
+
canAttachAttributes: hasSingleRootElement(resolved.html),
|
|
69
|
+
rootTag: getRootTagName(resolved.html),
|
|
70
|
+
integrationName,
|
|
71
|
+
assets: resolved.assets.length > 0 ? resolved.assets : undefined,
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
children: resolved.html,
|
|
75
|
+
layoutRenders: [],
|
|
76
|
+
primaryRender,
|
|
77
|
+
};
|
|
83
78
|
}
|
|
84
|
-
export {
|
|
85
|
-
composeReactLayoutPageChildren,
|
|
86
|
-
composeReactLayoutPageTree,
|
|
87
|
-
resolveComposeChildren,
|
|
88
|
-
shouldUseUnifiedReactLayoutComposition
|
|
89
|
-
};
|
|
@@ -1,56 +1,54 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps -- shim mirrors upstream ref-based hook semantics */
|
|
2
|
+
import { useDebugValue, useEffect, useMemo, useRef, useSyncExternalStore } from 'react';
|
|
2
3
|
const objectIs = Object.is;
|
|
3
|
-
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
4
|
+
export function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
5
|
+
const instRef = useRef({ hasValue: false, value: undefined });
|
|
6
|
+
const memoizedSelectionRef = useMemo(() => {
|
|
7
|
+
let hasMemo = false;
|
|
8
|
+
let memoizedSnapshot;
|
|
9
|
+
let memoizedSelection;
|
|
10
|
+
const maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
|
|
11
|
+
const memoizedSelector = (nextSnapshot) => {
|
|
12
|
+
if (!hasMemo) {
|
|
13
|
+
hasMemo = true;
|
|
14
|
+
memoizedSnapshot = nextSnapshot;
|
|
15
|
+
const nextSelection = selector(nextSnapshot);
|
|
16
|
+
const inst = instRef.current;
|
|
17
|
+
if (isEqual !== undefined && inst.hasValue) {
|
|
18
|
+
const currentSelection = inst.value;
|
|
19
|
+
if (isEqual(currentSelection, nextSelection)) {
|
|
20
|
+
memoizedSelection = currentSelection;
|
|
21
|
+
return currentSelection;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
memoizedSelection = nextSelection;
|
|
25
|
+
return nextSelection;
|
|
26
|
+
}
|
|
27
|
+
const currentSelection = memoizedSelection;
|
|
28
|
+
if (objectIs(memoizedSnapshot, nextSnapshot)) {
|
|
29
|
+
return currentSelection;
|
|
30
|
+
}
|
|
31
|
+
const nextSelection = selector(nextSnapshot);
|
|
32
|
+
if (isEqual !== undefined && isEqual(currentSelection, nextSelection)) {
|
|
33
|
+
memoizedSnapshot = nextSnapshot;
|
|
34
|
+
return currentSelection;
|
|
35
|
+
}
|
|
36
|
+
memoizedSnapshot = nextSnapshot;
|
|
37
|
+
memoizedSelection = nextSelection;
|
|
38
|
+
return nextSelection;
|
|
39
|
+
};
|
|
40
|
+
return [
|
|
41
|
+
() => memoizedSelector(getSnapshot()),
|
|
42
|
+
maybeGetServerSnapshot === null ? undefined : () => memoizedSelector(maybeGetServerSnapshot()),
|
|
43
|
+
];
|
|
44
|
+
}, [getSnapshot, getServerSnapshot, selector, isEqual]);
|
|
45
|
+
const value = useSyncExternalStore(subscribe, memoizedSelectionRef[0], memoizedSelectionRef[1]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
instRef.current = {
|
|
48
|
+
hasValue: true,
|
|
49
|
+
value,
|
|
50
|
+
};
|
|
51
|
+
}, [value]);
|
|
52
|
+
useDebugValue(value);
|
|
53
|
+
return value;
|
|
53
54
|
}
|
|
54
|
-
export {
|
|
55
|
-
useSyncExternalStoreWithSelector
|
|
56
|
-
};
|