@ecopages/react 0.2.0-beta.3 → 0.2.0-beta.31
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 +168 -6
- package/package.json +51 -26
- package/src/bundling/bootstrap-package-paths.d.ts +5 -0
- package/src/bundling/bootstrap-package-paths.js +6 -0
- package/src/{services/react-bundle.service.d.ts → bundling/bundle.d.ts} +21 -8
- package/src/{services/react-bundle.service.js → bundling/bundle.js} +53 -21
- package/src/bundling/discover-layout-runtime-modules.d.ts +32 -0
- package/src/bundling/discover-layout-runtime-modules.js +180 -0
- package/src/bundling/runtime-alias-map.d.ts +10 -0
- package/src/{utils/react-runtime-alias-map.js → bundling/runtime-alias-map.js} +13 -2
- package/src/{services/react-runtime-bundle.service.d.ts → bundling/runtime-bundle.d.ts} +30 -5
- package/src/{services/react-runtime-bundle.service.js → bundling/runtime-bundle.js} +104 -8
- package/src/bundling/runtime-mode.d.ts +9 -0
- package/src/bundling/runtime-mode.js +6 -0
- package/src/bundling/runtime-modules.d.ts +29 -0
- package/src/bundling/runtime-modules.js +38 -0
- package/src/client-graph/ast-transform.d.ts +18 -0
- package/src/{utils/client-graph-boundary-plugin.js → client-graph/ast-transform.js} +15 -232
- package/src/{utils/client-graph-boundary-cache.d.ts → client-graph/boundary-cache.d.ts} +0 -5
- package/src/{utils/client-graph-boundary-cache.js → client-graph/boundary-cache.js} +1 -3
- package/src/{utils/client-graph-boundary-plugin.d.ts → client-graph/boundary-plugin.d.ts} +4 -13
- package/src/client-graph/boundary-plugin.js +107 -0
- package/src/{utils → client-graph}/component-config-traversal.js +4 -2
- package/src/{utils → client-graph}/reachability-analyzer.d.ts +2 -2
- package/src/{utils → client-graph}/reachability-analyzer.js +4 -1
- package/src/client-graph/specifier-classification.d.ts +75 -0
- package/src/client-graph/specifier-classification.js +155 -0
- package/src/{react-hmr-strategy.d.ts → hmr/hmr-strategy.d.ts} +19 -6
- package/src/{react-hmr-strategy.js → hmr/hmr-strategy.js} +154 -133
- package/src/{services/react-hmr-page-metadata-cache.d.ts → hmr/page-metadata-cache.d.ts} +5 -1
- package/src/{services/react-hmr-page-metadata-cache.js → hmr/page-metadata-cache.js} +8 -2
- package/src/hydration/assert-no-bare-ecopages-imports.d.ts +4 -0
- package/src/hydration/assert-no-bare-ecopages-imports.js +7 -0
- package/src/hydration/bootstrap-imports.d.ts +25 -0
- package/src/hydration/bootstrap-imports.js +23 -0
- package/src/{services/react-hydration-asset.service.d.ts → hydration/hydration-asset.d.ts} +33 -33
- package/src/{services/react-hydration-asset.service.js → hydration/hydration-asset.js} +63 -56
- package/src/hydration/hydration-scripts.d.ts +100 -0
- package/src/hydration/hydration-scripts.js +350 -0
- package/src/{utils → hydration}/hydration-scripts.test.browser.js +11 -5
- package/src/hydration/page-data-manifest.d.ts +58 -0
- package/src/hydration/page-data-manifest.js +53 -0
- package/src/hydration/page-data-reader.d.ts +31 -0
- package/src/hydration/page-data-reader.js +64 -0
- package/src/hydration/page-payload.d.ts +67 -0
- package/src/hydration/page-payload.js +104 -0
- package/src/hydration/serialize-page-data-script.d.ts +27 -0
- package/src/hydration/serialize-page-data-script.js +31 -0
- package/src/{services/react-mdx-config-dependency.service.d.ts → mdx/mdx-config-dependency.d.ts} +5 -5
- package/src/{services/react-mdx-config-dependency.service.js → mdx/mdx-config-dependency.js} +8 -10
- package/src/mdx/mdx-loader-plugin.d.ts +2 -0
- package/src/mdx/mdx-loader-plugin.js +11 -0
- package/src/page/page-module.d.ts +46 -0
- package/src/page/page-module.js +72 -0
- package/src/{react.plugin.d.ts → plugin/react.plugin.d.ts} +8 -3
- package/src/{react.plugin.js → plugin/react.plugin.js} +78 -54
- package/src/plugin/react.types.d.ts +149 -0
- package/src/render/component-ownership.d.ts +50 -0
- package/src/render/component-ownership.js +23 -0
- package/src/render/component-ssr.d.ts +113 -0
- package/src/render/component-ssr.js +202 -0
- package/src/render/errors.d.ts +16 -0
- package/src/render/errors.js +18 -0
- package/src/render/layout-compose.d.ts +66 -0
- package/src/render/layout-compose.js +106 -0
- package/src/render/react-renderer.d.ts +138 -0
- package/src/render/react-renderer.js +481 -0
- package/src/render/react-runtime.d.ts +13 -0
- package/src/render/react-runtime.js +21 -0
- package/src/render/unified-layout-composition.d.ts +53 -0
- package/src/render/unified-layout-composition.js +89 -0
- package/src/react-renderer.d.ts +0 -233
- package/src/react-renderer.js +0 -622
- package/src/react.types.d.ts +0 -88
- package/src/services/pages-index.d.ts +0 -64
- package/src/services/pages-index.js +0 -73
- package/src/services/react-page-module.service.d.ts +0 -88
- package/src/services/react-page-module.service.js +0 -166
- package/src/services/react-page-payload.service.d.ts +0 -46
- package/src/services/react-page-payload.service.js +0 -67
- package/src/utils/hydration-scripts.d.ts +0 -92
- package/src/utils/hydration-scripts.js +0 -358
- package/src/utils/react-mdx-loader-plugin.d.ts +0 -3
- package/src/utils/react-mdx-loader-plugin.js +0 -45
- package/src/utils/react-runtime-alias-map.d.ts +0 -8
- /package/src/{utils → app}/client-only.d.ts +0 -0
- /package/src/{utils → app}/client-only.js +0 -0
- /package/src/{utils → app}/dynamic.d.ts +0 -0
- /package/src/{utils → app}/dynamic.js +0 -0
- /package/src/{utils → app}/dynamic.test.browser.d.ts +0 -0
- /package/src/{utils → app}/dynamic.test.browser.js +0 -0
- /package/src/{utils/react-dom-runtime-interop-plugin.d.ts → bundling/runtime-interop-plugin.d.ts} +0 -0
- /package/src/{utils/react-dom-runtime-interop-plugin.js → bundling/runtime-interop-plugin.js} +0 -0
- /package/src/{utils → client-graph}/component-config-traversal.d.ts +0 -0
- /package/src/{utils → client-graph}/declared-modules.d.ts +0 -0
- /package/src/{utils → client-graph}/declared-modules.js +0 -0
- /package/src/{declarations.d.ts → contracts/declarations.d.ts} +0 -0
- /package/src/{router-adapter.d.ts → contracts/router-adapter.d.ts} +0 -0
- /package/src/{router-adapter.js → contracts/router-adapter.js} +0 -0
- /package/src/{utils → hmr}/hmr-scripts.d.ts +0 -0
- /package/src/{utils → hmr}/hmr-scripts.js +0 -0
- /package/src/{utils → hydration}/hydration-scripts.test.browser.d.ts +0 -0
- /package/src/{react.constants.d.ts → plugin/react.constants.d.ts} +0 -0
- /package/src/{react.constants.js → plugin/react.constants.js} +0 -0
- /package/src/{react.types.js → plugin/react.types.js} +0 -0
- /package/src/{eco-embed.d.ts → render/eco-embed.d.ts} +0 -0
- /package/src/{eco-embed.js → render/eco-embed.js} +0 -0
- /package/src/{utils → render}/html-boundary.d.ts +0 -0
- /package/src/{utils → render}/html-boundary.js +0 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { getDevPageDataReaderBootstrapSource } from "./page-data-reader.js";
|
|
2
|
+
function getPageDataReaderSource(options) {
|
|
3
|
+
if (options.pageDataReaderImportPath) {
|
|
4
|
+
return `import { readPageDataDocument, getPageDataFromDocument as getPageData } from "${options.pageDataReaderImportPath}";`;
|
|
5
|
+
}
|
|
6
|
+
return getDevPageDataReaderBootstrapSource();
|
|
7
|
+
}
|
|
8
|
+
function getImportStatement(importPath, isMdx, pageLayoutNormalizationImportPath) {
|
|
9
|
+
return isMdx ? `import * as MDXModule from "${importPath}";
|
|
10
|
+
import { ensurePageConfigLayouts } from "${pageLayoutNormalizationImportPath}";
|
|
11
|
+
const Page = MDXModule.default;
|
|
12
|
+
if (MDXModule.config) {
|
|
13
|
+
Page.config = MDXModule.config;
|
|
14
|
+
ensurePageConfigLayouts(Page.config);
|
|
15
|
+
}` : `import Page from "${importPath}";`;
|
|
16
|
+
}
|
|
17
|
+
function getHmrImportStatement(isMdx) {
|
|
18
|
+
return isMdx ? `const NewPage = newModule.default;
|
|
19
|
+
if (newModule.config) {
|
|
20
|
+
NewPage.config = newModule.config;
|
|
21
|
+
ensurePageConfigLayouts(NewPage.config);
|
|
22
|
+
}` : "const NewPage = newModule.default;";
|
|
23
|
+
}
|
|
24
|
+
function getComponentType(isMdx) {
|
|
25
|
+
return isMdx ? "MDX" : "React";
|
|
26
|
+
}
|
|
27
|
+
function getPageRootCleanupScript() {
|
|
28
|
+
return `window.__ECO_PAGES__ = window.__ECO_PAGES__ || {};
|
|
29
|
+
window.__ECO_PAGES__.react = window.__ECO_PAGES__.react || {};
|
|
30
|
+
window.__ECO_PAGES__.react.cleanupPageRoot = () => {
|
|
31
|
+
const activeRoot = window.__ECO_PAGES__.react?.pageRoot || root;
|
|
32
|
+
if (!activeRoot) {
|
|
33
|
+
window.__ECO_PAGES__.react.pageRoot = null;
|
|
34
|
+
window.__ECO_PAGES__?.navigation?.releaseOwnership?.("react-router");
|
|
35
|
+
delete window.__ECO_PAGES__.page;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
window.__ECO_PAGES__.react.pageRoot = null;
|
|
39
|
+
window.__ECO_PAGES__?.navigation?.releaseOwnership?.("react-router");
|
|
40
|
+
delete window.__ECO_PAGES__.page;
|
|
41
|
+
root = null;
|
|
42
|
+
activeRoot.unmount();
|
|
43
|
+
};`;
|
|
44
|
+
}
|
|
45
|
+
function getRouterBootstrapRegistrationScript() {
|
|
46
|
+
return `const currentOwnerState = window.__ECO_PAGES__?.navigation?.getOwnerState?.();
|
|
47
|
+
if (!(currentOwnerState?.owner === "react-router" && currentOwnerState.canHandleSpaNavigation)) {
|
|
48
|
+
window.__ECO_PAGES__?.navigation?.register({
|
|
49
|
+
owner: "react-router",
|
|
50
|
+
cleanupBeforeHandoff: async () => {
|
|
51
|
+
window.__ECO_PAGES__?.react?.cleanupPageRoot?.();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
window.__ECO_PAGES__?.navigation?.claimOwnership?.("react-router");
|
|
55
|
+
}`;
|
|
56
|
+
}
|
|
57
|
+
function getReuseExistingRouterRootScript() {
|
|
58
|
+
return `const shouldReuseExistingRouterRoot = () => {
|
|
59
|
+
const ownerState = window.__ECO_PAGES__?.navigation?.getOwnerState?.();
|
|
60
|
+
return Boolean(
|
|
61
|
+
window.__ECO_PAGES__.react?.pageRoot &&
|
|
62
|
+
ownerState?.owner === "react-router" &&
|
|
63
|
+
ownerState.canHandleSpaNavigation
|
|
64
|
+
);
|
|
65
|
+
};`;
|
|
66
|
+
}
|
|
67
|
+
function getRerunRegistrationScript(scriptId) {
|
|
68
|
+
return `window.__ECO_PAGES__ = window.__ECO_PAGES__ || {};
|
|
69
|
+
window.__ECO_PAGES__.rerunScripts = window.__ECO_PAGES__.rerunScripts || {};
|
|
70
|
+
window.__ECO_PAGES__.rerunScripts[${JSON.stringify(scriptId)}] = mount;`;
|
|
71
|
+
}
|
|
72
|
+
function getRouterHmrHandlerScript(options) {
|
|
73
|
+
const { importPath, isMdx } = options;
|
|
74
|
+
return ` window.__ECO_PAGES__.hmrHandlers["${importPath}"] = async (newUrl) => {
|
|
75
|
+
try {
|
|
76
|
+
const newModule = await import(newUrl);
|
|
77
|
+
const nextProps = getPageData();
|
|
78
|
+
${getHmrImportStatement(isMdx)}
|
|
79
|
+
const currentPageLayoutStack = (Component) =>
|
|
80
|
+
(Component.config?.layouts ?? []).map((layout) => layout?.config?.__eco?.file ?? '').join('|');
|
|
81
|
+
const currentPageLayoutStackKey = currentPageLayoutStack(Page);
|
|
82
|
+
const nextPageLayoutStackKey = currentPageLayoutStack(NewPage);
|
|
83
|
+
|
|
84
|
+
if (window.__ECO_PAGES__?.navigation?.getOwnerState().owner === "react-router") {
|
|
85
|
+
await window.__ECO_PAGES__?.navigation?.reloadCurrentPage?.({
|
|
86
|
+
clearCache: currentPageLayoutStackKey !== nextPageLayoutStackKey,
|
|
87
|
+
moduleUrl: newUrl,
|
|
88
|
+
source: "react-router"
|
|
89
|
+
});
|
|
90
|
+
console.log("[ecopages] ${getComponentType(isMdx)} component updated via router");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const nextPageData = readPageDataDocument();
|
|
95
|
+
window.__ECO_PAGES__.page = {
|
|
96
|
+
module: nextPageData.moduleUrl || pageModuleUrl,
|
|
97
|
+
props: nextProps
|
|
98
|
+
};
|
|
99
|
+
root.render(createTree(NewPage, nextProps));
|
|
100
|
+
console.log("[ecopages] ${getComponentType(isMdx)} component updated");
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error("[ecopages] Failed to hot-reload ${getComponentType(isMdx)} component:", e);
|
|
103
|
+
}
|
|
104
|
+
};`;
|
|
105
|
+
}
|
|
106
|
+
function getNonRouterHmrHandlerScript(options) {
|
|
107
|
+
const { importPath, isMdx } = options;
|
|
108
|
+
return ` window.__ECO_PAGES__.hmrHandlers["${importPath}"] = async (newUrl) => {
|
|
109
|
+
try {
|
|
110
|
+
const newModule = await import(newUrl);
|
|
111
|
+
${getHmrImportStatement(isMdx)}
|
|
112
|
+
root.render(createTree(NewPage, props));
|
|
113
|
+
console.log("[ecopages] ${getComponentType(isMdx)} component updated");
|
|
114
|
+
} catch (e) {
|
|
115
|
+
console.error("[ecopages] Failed to hot-reload ${getComponentType(isMdx)} component:", e);
|
|
116
|
+
}
|
|
117
|
+
};`;
|
|
118
|
+
}
|
|
119
|
+
function createScriptWithRouter(options) {
|
|
120
|
+
const {
|
|
121
|
+
importPath,
|
|
122
|
+
isMdx,
|
|
123
|
+
router,
|
|
124
|
+
reactImportPath,
|
|
125
|
+
reactDomClientImportPath,
|
|
126
|
+
routerImportPath,
|
|
127
|
+
scriptId,
|
|
128
|
+
hmrEnabled
|
|
129
|
+
} = options;
|
|
130
|
+
const pageModuleUrlExpression = options.pageModuleUrlExpression ?? "import.meta.url";
|
|
131
|
+
const { components, getRouterProps } = router;
|
|
132
|
+
if (!routerImportPath) {
|
|
133
|
+
throw new Error("routerImportPath is required when router adapter is configured");
|
|
134
|
+
}
|
|
135
|
+
const pageLayoutNormalizationImportPath = options.pageLayoutNormalizationImportPath;
|
|
136
|
+
const hmrInit = hmrEnabled ? `window.__ECO_PAGES__.hmrHandlers = window.__ECO_PAGES__.hmrHandlers || {};
|
|
137
|
+
` : "";
|
|
138
|
+
const hmrHandler = hmrEnabled ? getRouterHmrHandlerScript({ importPath, isMdx }) : "";
|
|
139
|
+
return `
|
|
140
|
+
import { hydrateRoot } from "${reactDomClientImportPath}";
|
|
141
|
+
import { createElement } from "${reactImportPath}";
|
|
142
|
+
import { ${components.router}, ${components.pageContent} } from "${routerImportPath}";
|
|
143
|
+
${getPageDataReaderSource(options)}
|
|
144
|
+
${getImportStatement(importPath, isMdx, pageLayoutNormalizationImportPath)}
|
|
145
|
+
const pageModuleUrl = ${pageModuleUrlExpression};
|
|
146
|
+
export default Page;
|
|
147
|
+
export const config = Page.config;
|
|
148
|
+
const isActivePageEntry = Boolean(document.querySelector('script[data-eco-script-id="${scriptId}"]'));
|
|
149
|
+
|
|
150
|
+
if (isActivePageEntry) {
|
|
151
|
+
|
|
152
|
+
window.__ECO_PAGES__ = window.__ECO_PAGES__ || {};
|
|
153
|
+
${hmrInit}window.__ECO_PAGES__.react = window.__ECO_PAGES__.react || {};
|
|
154
|
+
window.__ECO_PAGES__.react.pageRoot = window.__ECO_PAGES__.react.pageRoot || null;
|
|
155
|
+
let root = window.__ECO_PAGES__.react.pageRoot;
|
|
156
|
+
${getPageRootCleanupScript()}
|
|
157
|
+
${getRouterBootstrapRegistrationScript()}
|
|
158
|
+
${getReuseExistingRouterRootScript()}
|
|
159
|
+
|
|
160
|
+
const initialPageData = readPageDataDocument();
|
|
161
|
+
const props = initialPageData.props;
|
|
162
|
+
|
|
163
|
+
window.__ECO_PAGES__.page = {
|
|
164
|
+
module: initialPageData.moduleUrl || pageModuleUrl,
|
|
165
|
+
props
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const createTree = (Component, props) => {
|
|
169
|
+
const pageContent = createElement(${components.pageContent});
|
|
170
|
+
return createElement(${components.router}, ${getRouterProps("Component", "props")}, pageContent);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const mount = () => {
|
|
174
|
+
const pageData = readPageDataDocument();
|
|
175
|
+
const props = pageData.props;
|
|
176
|
+
window.__ECO_PAGES__.page = {
|
|
177
|
+
module: pageData.moduleUrl || pageModuleUrl,
|
|
178
|
+
props
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
if (shouldReuseExistingRouterRoot()) {
|
|
182
|
+
root = window.__ECO_PAGES__.react.pageRoot;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (window.__ECO_PAGES__.react?.pageRoot) {
|
|
187
|
+
root = window.__ECO_PAGES__.react.pageRoot;
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
root = hydrateRoot(document.body, createTree(Page, props), {
|
|
192
|
+
onRecoverableError: (err) => console.warn("[ecopages] Hydration error:", err)
|
|
193
|
+
});
|
|
194
|
+
window.__ECO_PAGES__.react.pageRoot = root;
|
|
195
|
+
${hmrHandler}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
${getRerunRegistrationScript(scriptId)}
|
|
199
|
+
|
|
200
|
+
if (document.readyState === "loading") {
|
|
201
|
+
document.addEventListener("DOMContentLoaded", mount);
|
|
202
|
+
} else {
|
|
203
|
+
mount();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
`.trim();
|
|
207
|
+
}
|
|
208
|
+
function createScriptWithoutRouter(options) {
|
|
209
|
+
const { importPath, isMdx, reactImportPath, reactDomClientImportPath, scriptId, hmrEnabled } = options;
|
|
210
|
+
const pageModuleUrlExpression = options.pageModuleUrlExpression ?? "import.meta.url";
|
|
211
|
+
const layoutComposeImportPath = options.layoutComposeImportPath;
|
|
212
|
+
const pageLayoutNormalizationImportPath = options.pageLayoutNormalizationImportPath;
|
|
213
|
+
const hmrInit = hmrEnabled ? `window.__ECO_PAGES__.hmrHandlers = window.__ECO_PAGES__.hmrHandlers || {};
|
|
214
|
+
` : "";
|
|
215
|
+
const hmrHandler = hmrEnabled ? getNonRouterHmrHandlerScript({ importPath, isMdx }) : "";
|
|
216
|
+
return `
|
|
217
|
+
import { hydrateRoot } from "${reactDomClientImportPath}";
|
|
218
|
+
import { createElement } from "${reactImportPath}";
|
|
219
|
+
import { composeLayoutPageTree } from "${layoutComposeImportPath}";
|
|
220
|
+
${getPageDataReaderSource(options)}
|
|
221
|
+
${getImportStatement(importPath, isMdx, pageLayoutNormalizationImportPath)}
|
|
222
|
+
const pageModuleUrl = ${pageModuleUrlExpression};
|
|
223
|
+
export default Page;
|
|
224
|
+
export const config = Page.config;
|
|
225
|
+
const isActivePageEntry = Boolean(document.querySelector('script[data-eco-script-id="${scriptId}"]'));
|
|
226
|
+
|
|
227
|
+
if (isActivePageEntry) {
|
|
228
|
+
|
|
229
|
+
window.__ECO_PAGES__ = window.__ECO_PAGES__ || {};
|
|
230
|
+
${hmrInit}window.__ECO_PAGES__.react = window.__ECO_PAGES__.react || {};
|
|
231
|
+
window.__ECO_PAGES__.react.pageRoot = window.__ECO_PAGES__.react.pageRoot || null;
|
|
232
|
+
let root = window.__ECO_PAGES__.react.pageRoot;
|
|
233
|
+
${getPageRootCleanupScript()}
|
|
234
|
+
|
|
235
|
+
const initialPageData = readPageDataDocument();
|
|
236
|
+
const props = initialPageData.props;
|
|
237
|
+
|
|
238
|
+
window.__ECO_PAGES__.page = {
|
|
239
|
+
module: initialPageData.moduleUrl || pageModuleUrl,
|
|
240
|
+
props
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const createTree = (Component, props) => composeLayoutPageTree(Component, props);
|
|
244
|
+
|
|
245
|
+
const mount = () => {
|
|
246
|
+
const pageData = readPageDataDocument();
|
|
247
|
+
const props = pageData.props;
|
|
248
|
+
window.__ECO_PAGES__.page = {
|
|
249
|
+
module: pageData.moduleUrl || pageModuleUrl,
|
|
250
|
+
props
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
if (window.__ECO_PAGES__.react?.pageRoot) {
|
|
254
|
+
root = window.__ECO_PAGES__.react.pageRoot;
|
|
255
|
+
root.render(createTree(Page, props));
|
|
256
|
+
} else {
|
|
257
|
+
root = hydrateRoot(document.body, createTree(Page, props), {
|
|
258
|
+
onRecoverableError: (err) => console.warn("[ecopages] Hydration error:", err)
|
|
259
|
+
});
|
|
260
|
+
window.__ECO_PAGES__.react.pageRoot = root;
|
|
261
|
+
}
|
|
262
|
+
${hmrHandler}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
${getRerunRegistrationScript(scriptId)}
|
|
266
|
+
|
|
267
|
+
if (document.readyState === "loading") {
|
|
268
|
+
document.addEventListener("DOMContentLoaded", mount);
|
|
269
|
+
} else {
|
|
270
|
+
mount();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
`.trim();
|
|
274
|
+
}
|
|
275
|
+
function createHydrationScript(options) {
|
|
276
|
+
return options.router ? createScriptWithRouter(options) : createScriptWithoutRouter(options);
|
|
277
|
+
}
|
|
278
|
+
function createIslandHydrationScript(options) {
|
|
279
|
+
const targetSelector = JSON.stringify(options.targetSelector);
|
|
280
|
+
const componentRef = JSON.stringify(options.componentRef ?? "");
|
|
281
|
+
const componentFile = JSON.stringify(options.componentFile ?? "");
|
|
282
|
+
const scriptId = options.scriptId;
|
|
283
|
+
if (options.minify) {
|
|
284
|
+
return `import{createRoot as cr}from"${options.reactDomClientImportPath}";import{createElement as ce}from"${options.reactImportPath}";import*as M from"${options.importPath}";const r=${componentRef};const f=${componentFile};const mv=Object.values(M);const c=mv.find((e)=>{if(typeof e!=="function")return false;const ec=e.config?.__eco;if(!ec)return false;if(r&&ec.id===r)return true;if(f&&ec.file===f)return true;return false;})??(typeof M.default==="function"?M.default:mv.find((e)=>typeof e==="function")??null);const m=()=>{const ts=document.querySelectorAll(${targetSelector});if(!c||ts.length===0)return;ts.forEach((t)=>{if(!(t instanceof HTMLElement))return;const p=JSON.parse(atob(t.getAttribute("data-eco-props")||"e30="));const ct=document.createElement("eco-island");ct.style.display="block";t.replaceWith(ct);cr(ct).render(ce(c,p))})};window.__ECO_PAGES__=window.__ECO_PAGES__||{};window.__ECO_PAGES__.rerunScripts=window.__ECO_PAGES__.rerunScripts||{};window.__ECO_PAGES__.rerunScripts[${JSON.stringify(scriptId)}]=m;document.readyState==="loading"?document.addEventListener("DOMContentLoaded",m,{once:true}):m()`;
|
|
285
|
+
}
|
|
286
|
+
return `
|
|
287
|
+
import { createRoot } from "${options.reactDomClientImportPath}";
|
|
288
|
+
import { createElement } from "${options.reactImportPath}";
|
|
289
|
+
import * as ComponentModule from "${options.importPath}";
|
|
290
|
+
|
|
291
|
+
const resolveComponent = () => {
|
|
292
|
+
const id = ${componentRef};
|
|
293
|
+
const file = ${componentFile};
|
|
294
|
+
const moduleValues = Object.values(ComponentModule);
|
|
295
|
+
|
|
296
|
+
const matchByMetadata = moduleValues.find((entry) => {
|
|
297
|
+
if (typeof entry !== "function") return false;
|
|
298
|
+
const config = entry.config;
|
|
299
|
+
const eco = config?.__eco;
|
|
300
|
+
if (!eco) return false;
|
|
301
|
+
if (id && eco.id === id) return true;
|
|
302
|
+
if (file && eco.file === file) return true;
|
|
303
|
+
return false;
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
if (matchByMetadata && typeof matchByMetadata === "function") {
|
|
307
|
+
return matchByMetadata;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const defaultExport = ComponentModule.default;
|
|
311
|
+
if (typeof defaultExport === "function") {
|
|
312
|
+
return defaultExport;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const firstFunction = moduleValues.find((entry) => typeof entry === "function");
|
|
316
|
+
return typeof firstFunction === "function" ? firstFunction : null;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const mount = () => {
|
|
320
|
+
const targets = document.querySelectorAll(${targetSelector});
|
|
321
|
+
const Component = resolveComponent();
|
|
322
|
+
if (!Component || targets.length === 0) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
targets.forEach((target) => {
|
|
326
|
+
if (!(target instanceof HTMLElement)) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
const props = JSON.parse(atob(target.getAttribute("data-eco-props") || "e30="));
|
|
330
|
+
const container = document.createElement("eco-island");
|
|
331
|
+
container.style.display = "block";
|
|
332
|
+
target.replaceWith(container);
|
|
333
|
+
const root = createRoot(container);
|
|
334
|
+
root.render(createElement(Component, props));
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
${getRerunRegistrationScript(scriptId)}
|
|
339
|
+
|
|
340
|
+
if (document.readyState === "loading") {
|
|
341
|
+
document.addEventListener("DOMContentLoaded", mount, { once: true });
|
|
342
|
+
} else {
|
|
343
|
+
mount();
|
|
344
|
+
}
|
|
345
|
+
`.trim();
|
|
346
|
+
}
|
|
347
|
+
export {
|
|
348
|
+
createHydrationScript,
|
|
349
|
+
createIslandHydrationScript
|
|
350
|
+
};
|
|
@@ -62,7 +62,11 @@ export function PageContent() {
|
|
|
62
62
|
importPath,
|
|
63
63
|
reactImportPath,
|
|
64
64
|
reactDomClientImportPath,
|
|
65
|
-
routerImportPath
|
|
65
|
+
routerImportPath,
|
|
66
|
+
layoutComposeImportPath: createModuleUrl("export function composeLayoutPageTree() { return null; }"),
|
|
67
|
+
pageLayoutNormalizationImportPath: createModuleUrl(
|
|
68
|
+
"export function ensurePageConfigLayouts(config) { return config; }"
|
|
69
|
+
)
|
|
66
70
|
};
|
|
67
71
|
}
|
|
68
72
|
describe("createHydrationScript browser execution", () => {
|
|
@@ -107,9 +111,10 @@ describe("createHydrationScript browser execution", () => {
|
|
|
107
111
|
const script = createHydrationScript({
|
|
108
112
|
...runtimeModules,
|
|
109
113
|
scriptId: "ecopages-react-page",
|
|
110
|
-
|
|
114
|
+
hmrEnabled: true,
|
|
111
115
|
isMdx: false,
|
|
112
|
-
router: routerAdapter
|
|
116
|
+
router: routerAdapter,
|
|
117
|
+
pageDataReaderImportPath: new URL("./page-data-reader.js", import.meta.url).href
|
|
113
118
|
});
|
|
114
119
|
const moduleUrl = createModuleUrl(script);
|
|
115
120
|
await importModule(moduleUrl, "ecopages-react-page");
|
|
@@ -177,9 +182,10 @@ describe("createHydrationScript browser execution", () => {
|
|
|
177
182
|
const script = createHydrationScript({
|
|
178
183
|
...runtimeModules,
|
|
179
184
|
scriptId: "ecopages-react-page-rerun",
|
|
180
|
-
|
|
185
|
+
hmrEnabled: true,
|
|
181
186
|
isMdx: false,
|
|
182
|
-
router: routerAdapter
|
|
187
|
+
router: routerAdapter,
|
|
188
|
+
pageDataReaderImportPath: new URL("./page-data-reader.js", import.meta.url).href
|
|
183
189
|
});
|
|
184
190
|
const moduleUrl = createModuleUrl(script);
|
|
185
191
|
await importModule(moduleUrl, "ecopages-react-page-rerun");
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versioned React page-data document payload.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* The `__ECO_PAGE_DATA__` script emits this envelope so client navigation can
|
|
6
|
+
* read module identity without parsing generated hydration JavaScript. Older
|
|
7
|
+
* documents may still contain a flat props object; consumers must detect both.
|
|
8
|
+
*
|
|
9
|
+
* Compatibility matrix:
|
|
10
|
+
* - new client / new document: prefer `schemaVersion:1` envelope (`moduleUrl` + `props`)
|
|
11
|
+
* - new client / old document: accept legacy flat props; module discovery uses
|
|
12
|
+
* `window.__ECO_PAGES__.page.module` or `script[data-eco-page-bootstrap="react-router"]`
|
|
13
|
+
* - old client / new document: old clients that only read flat props should be
|
|
14
|
+
* upgraded; envelope consumers must unwrap `props` before hydration
|
|
15
|
+
* - malformed / unknown schema (numeric `schemaVersion` present but envelope invalid):
|
|
16
|
+
* empty props and no module URL from the manifest
|
|
17
|
+
* - HMR: `moduleUrlOverride` still bypasses document discovery
|
|
18
|
+
* - legacy flat props may include a string `schemaVersion` field without being treated as an envelope
|
|
19
|
+
*/
|
|
20
|
+
export declare const ECO_PAGE_DATA_SCHEMA_VERSION: 1;
|
|
21
|
+
export type EcoPageDataProps = Record<string, unknown>;
|
|
22
|
+
export type EcoPageDataManifestV1 = {
|
|
23
|
+
schemaVersion: typeof ECO_PAGE_DATA_SCHEMA_VERSION;
|
|
24
|
+
navigationOwner: 'react-router';
|
|
25
|
+
moduleUrl: string;
|
|
26
|
+
props: EcoPageDataProps;
|
|
27
|
+
};
|
|
28
|
+
export type EcoPageDataDocumentPayload = EcoPageDataManifestV1 | EcoPageDataProps;
|
|
29
|
+
/**
|
|
30
|
+
* Returns whether a parsed JSON value is a versioned page-data envelope.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isEcoPageDataManifestV1(value: unknown): value is EcoPageDataManifestV1;
|
|
33
|
+
/**
|
|
34
|
+
* Extracts browser page props from either a v1 envelope or a legacy flat payload.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveEcoPageDataProps(payload: unknown): EcoPageDataProps;
|
|
37
|
+
/**
|
|
38
|
+
* Extracts the page module URL from a v1 envelope when present.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveEcoPageDataModuleUrl(payload: unknown): string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Builds the canonical v1 page-data envelope for React documents.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createEcoPageDataManifestV1(input: {
|
|
45
|
+
moduleUrl: string;
|
|
46
|
+
props: EcoPageDataProps;
|
|
47
|
+
}): EcoPageDataManifestV1;
|
|
48
|
+
/**
|
|
49
|
+
* Normalizes flat page props or an existing envelope into the document payload shape.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* Shared by server serializers and `EcoPropsScript` so envelope rules stay in one place.
|
|
53
|
+
* A valid v1 envelope is returned as-is; `options.moduleUrl` is ignored in that case.
|
|
54
|
+
* Flat props wrap into a v1 envelope only when `options.moduleUrl` is provided.
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolvePageDataDocumentPayload(data: EcoPageDataDocumentPayload, options?: {
|
|
57
|
+
moduleUrl?: string;
|
|
58
|
+
}): EcoPageDataDocumentPayload;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const ECO_PAGE_DATA_SCHEMA_VERSION = 1;
|
|
2
|
+
function isEcoPageDataManifestV1(value) {
|
|
3
|
+
if (typeof value !== "object" || value === null) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
const candidate = value;
|
|
7
|
+
return candidate.schemaVersion === ECO_PAGE_DATA_SCHEMA_VERSION && candidate.navigationOwner === "react-router" && typeof candidate.moduleUrl === "string" && typeof candidate.props === "object" && candidate.props !== null && !Array.isArray(candidate.props);
|
|
8
|
+
}
|
|
9
|
+
function isMalformedPageDataEnvelope(payload) {
|
|
10
|
+
return "schemaVersion" in payload && typeof payload.schemaVersion === "number";
|
|
11
|
+
}
|
|
12
|
+
function resolveEcoPageDataProps(payload) {
|
|
13
|
+
if (isEcoPageDataManifestV1(payload)) {
|
|
14
|
+
return payload.props;
|
|
15
|
+
}
|
|
16
|
+
if (typeof payload === "object" && payload !== null && !Array.isArray(payload)) {
|
|
17
|
+
if (isMalformedPageDataEnvelope(payload)) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
return payload;
|
|
21
|
+
}
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
function resolveEcoPageDataModuleUrl(payload) {
|
|
25
|
+
return isEcoPageDataManifestV1(payload) ? payload.moduleUrl : null;
|
|
26
|
+
}
|
|
27
|
+
function createEcoPageDataManifestV1(input) {
|
|
28
|
+
return {
|
|
29
|
+
schemaVersion: ECO_PAGE_DATA_SCHEMA_VERSION,
|
|
30
|
+
navigationOwner: "react-router",
|
|
31
|
+
moduleUrl: input.moduleUrl,
|
|
32
|
+
props: input.props
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function resolvePageDataDocumentPayload(data, options) {
|
|
36
|
+
if (isEcoPageDataManifestV1(data)) {
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
const props = { ...data };
|
|
40
|
+
const moduleUrl = options?.moduleUrl;
|
|
41
|
+
if (!moduleUrl) {
|
|
42
|
+
return props;
|
|
43
|
+
}
|
|
44
|
+
return createEcoPageDataManifestV1({ moduleUrl, props });
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
ECO_PAGE_DATA_SCHEMA_VERSION,
|
|
48
|
+
createEcoPageDataManifestV1,
|
|
49
|
+
isEcoPageDataManifestV1,
|
|
50
|
+
resolveEcoPageDataModuleUrl,
|
|
51
|
+
resolveEcoPageDataProps,
|
|
52
|
+
resolvePageDataDocumentPayload
|
|
53
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type EcoPageDataProps } from './page-data-manifest.js';
|
|
2
|
+
export type ReadPageDataDocumentResult = {
|
|
3
|
+
moduleUrl?: string;
|
|
4
|
+
props: EcoPageDataProps;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Reads `__ECO_PAGE_DATA__`, supporting both v1 envelopes and legacy flat props.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Always returns unwrapped `props`. `moduleUrl` is set only when the document
|
|
11
|
+
* carries a valid v1 envelope.
|
|
12
|
+
*/
|
|
13
|
+
export declare function readPageDataDocument(): ReadPageDataDocumentResult;
|
|
14
|
+
/**
|
|
15
|
+
* Returns page props from `__ECO_PAGE_DATA__` for hydration and HMR handlers.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getPageDataFromDocument(): EcoPageDataProps;
|
|
18
|
+
/**
|
|
19
|
+
* Inlined browser bootstrap for generated hydration scripts.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Hydration and HMR entry modules are evaluated as native browser ESM. Bare
|
|
23
|
+
* package imports such as `@ecopages/react/page-data-reader` are not resolvable
|
|
24
|
+
* there, so the reader algorithm is embedded. Keep this string aligned with
|
|
25
|
+
* {@link readPageDataDocument} / {@link getPageDataFromDocument}.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getDevPageDataReaderBootstrapSource(): string;
|
|
28
|
+
/**
|
|
29
|
+
* Minified equivalent of {@link getDevPageDataReaderBootstrapSource}.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getProdPageDataReaderBootstrapSource(): string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ECO_PAGE_DATA_SCHEMA_VERSION,
|
|
3
|
+
resolveEcoPageDataModuleUrl,
|
|
4
|
+
resolveEcoPageDataProps
|
|
5
|
+
} from "./page-data-manifest.js";
|
|
6
|
+
function readPageDataDocument() {
|
|
7
|
+
const element = document.getElementById("__ECO_PAGE_DATA__");
|
|
8
|
+
if (!element?.textContent) {
|
|
9
|
+
return { props: {} };
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
const parsed = JSON.parse(element.textContent);
|
|
13
|
+
const moduleUrl = resolveEcoPageDataModuleUrl(parsed) ?? void 0;
|
|
14
|
+
return {
|
|
15
|
+
...moduleUrl && { moduleUrl },
|
|
16
|
+
props: resolveEcoPageDataProps(parsed)
|
|
17
|
+
};
|
|
18
|
+
} catch {
|
|
19
|
+
return { props: {} };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function getPageDataFromDocument() {
|
|
23
|
+
return readPageDataDocument().props;
|
|
24
|
+
}
|
|
25
|
+
function getDevPageDataReaderBootstrapSource() {
|
|
26
|
+
return `const readPageDataDocument = () => {
|
|
27
|
+
const el = document.getElementById("__ECO_PAGE_DATA__");
|
|
28
|
+
if (!el?.textContent) {
|
|
29
|
+
return { props: {} };
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(el.textContent);
|
|
33
|
+
if (
|
|
34
|
+
parsed &&
|
|
35
|
+
parsed.schemaVersion === ${ECO_PAGE_DATA_SCHEMA_VERSION} &&
|
|
36
|
+
parsed.navigationOwner === "react-router" &&
|
|
37
|
+
typeof parsed.moduleUrl === "string" &&
|
|
38
|
+
parsed.props &&
|
|
39
|
+
typeof parsed.props === "object" &&
|
|
40
|
+
!Array.isArray(parsed.props)
|
|
41
|
+
) {
|
|
42
|
+
return { moduleUrl: parsed.moduleUrl, props: parsed.props };
|
|
43
|
+
}
|
|
44
|
+
if (parsed && typeof parsed === "object" && typeof parsed.schemaVersion === "number") {
|
|
45
|
+
return { props: {} };
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
props: parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {},
|
|
49
|
+
};
|
|
50
|
+
} catch {
|
|
51
|
+
return { props: {} };
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const getPageData = () => readPageDataDocument().props;`;
|
|
55
|
+
}
|
|
56
|
+
function getProdPageDataReaderBootstrapSource() {
|
|
57
|
+
return `const rd=()=>{const e=document.getElementById("__ECO_PAGE_DATA__");if(!e?.textContent)return{props:{}};try{const p=JSON.parse(e.textContent);if(p&&p.schemaVersion===${ECO_PAGE_DATA_SCHEMA_VERSION}&&p.navigationOwner==="react-router"&&typeof p.moduleUrl==="string"&&p.props&&typeof p.props==="object"&&!Array.isArray(p.props))return{moduleUrl:p.moduleUrl,props:p.props};if(p&&typeof p==="object"&&typeof p.schemaVersion==="number")return{props:{}};return{props:p&&typeof p==="object"&&!Array.isArray(p)?p:{}}}catch{return{props:{}}}};const gd=()=>rd().props;`;
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
getDevPageDataReaderBootstrapSource,
|
|
61
|
+
getPageDataFromDocument,
|
|
62
|
+
getProdPageDataReaderBootstrapSource,
|
|
63
|
+
readPageDataDocument
|
|
64
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { EcoComponentConfig, HtmlTemplateProps, IntegrationRendererRenderOptions, RequestLocals } from '@ecopages/core';
|
|
2
|
+
import type { HtmlDocumentContribution } from '@ecopages/core/route-renderer/orchestration/integration-renderer';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
type PagePayloadOptions = {
|
|
5
|
+
pageProps?: HtmlTemplateProps['pageProps'];
|
|
6
|
+
params: IntegrationRendererRenderOptions<ReactNode>['params'];
|
|
7
|
+
query: IntegrationRendererRenderOptions<ReactNode>['query'];
|
|
8
|
+
safeLocals?: RequestLocals;
|
|
9
|
+
};
|
|
10
|
+
type PagePackage = IntegrationRendererRenderOptions<ReactNode>['pagePackage'];
|
|
11
|
+
/**
|
|
12
|
+
* Builds the serialized page payload React exposes to document shells and the browser.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Keeps hydration payload shaping away from the renderer so orchestration stays
|
|
16
|
+
* focused on component composition instead of document serialization rules.
|
|
17
|
+
*/
|
|
18
|
+
export declare class PagePayloadService {
|
|
19
|
+
/**
|
|
20
|
+
* Resolves the browser-importable page module URL from processed page entry assets.
|
|
21
|
+
*/
|
|
22
|
+
resolvePageModuleUrl(pagePackage: PagePackage | undefined, options: {
|
|
23
|
+
routerEnabled: boolean;
|
|
24
|
+
}): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Creates the `__ECO_PAGE_DATA__` script for router hydration.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* When `moduleUrl` is present, emits the v1 envelope via
|
|
30
|
+
* {@link serializePageDataManifestScript}. Otherwise emits legacy flat props
|
|
31
|
+
* for non-router shells.
|
|
32
|
+
*/
|
|
33
|
+
buildRouterPageDataScript(pageProps: HtmlTemplateProps['pageProps'] | undefined, moduleUrl?: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Builds shared document html contributions for router-backed React pages rendered
|
|
36
|
+
* through a non-React HTML shell.
|
|
37
|
+
*/
|
|
38
|
+
buildNonReactDocumentContributions(options: {
|
|
39
|
+
htmlTemplate: {
|
|
40
|
+
config?: EcoComponentConfig;
|
|
41
|
+
} | null | undefined;
|
|
42
|
+
pageProps: Record<string, unknown>;
|
|
43
|
+
pageModuleUrl?: string;
|
|
44
|
+
reactIntegrationName: string;
|
|
45
|
+
routerEnabled: boolean;
|
|
46
|
+
}): HtmlDocumentContribution[] | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Builds the browser-safe page-props object embedded into the final HTML.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* Narrower than the full server render input: only routing data, public page
|
|
52
|
+
* props, and explicitly allowed locals. Page module identity is threaded via
|
|
53
|
+
* `HtmlTemplateProps.pageModuleUrl`, not serialized page props.
|
|
54
|
+
*/
|
|
55
|
+
buildSerializedPageProps(options: PagePayloadOptions): HtmlTemplateProps['pageProps'];
|
|
56
|
+
/**
|
|
57
|
+
* Extracts the declared subset of locals for client-side hydration.
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* On dynamic pages with `cache: 'dynamic'`, middleware populates `locals` with
|
|
61
|
+
* request-scoped data. Only keys declared via `Page.requires` are serialized.
|
|
62
|
+
* On static pages, `locals` is a Proxy that throws `LocalsAccessError`; this
|
|
63
|
+
* method returns `undefined` instead of throwing.
|
|
64
|
+
*/
|
|
65
|
+
getSerializableLocals(locals: RequestLocals | undefined, requiredLocals?: string | readonly string[]): RequestLocals | undefined;
|
|
66
|
+
}
|
|
67
|
+
export {};
|