diff --git a/examples/ssr-demo/.umirc.ts b/examples/ssr-demo/.umirc.ts
index 53274d948833..dcbe04b2c93d 100644
--- a/examples/ssr-demo/.umirc.ts
+++ b/examples/ssr-demo/.umirc.ts
@@ -9,7 +9,7 @@ export default {
scripts: [`https://a.com/b.js`],
ssr: {
builder: 'webpack',
- renderFromRoot: false,
+ __SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: false,
},
exportStatic: {},
styles: [`body { color: red; }`, `https://a.com/b.css`],
diff --git a/packages/preset-umi/src/commands/build.ts b/packages/preset-umi/src/commands/build.ts
index 93c7ed2f7756..8bf0d1aba42d 100644
--- a/packages/preset-umi/src/commands/build.ts
+++ b/packages/preset-umi/src/commands/build.ts
@@ -179,8 +179,9 @@ umi build --clean
const { vite } = api.args;
const args = await getMarkupArgs({ api });
- // renderFromRoot = true, 将 html 中的 title, metas 标签逻辑全部交给 metadataLoader 合并逻辑处理
- const markupArgs = api.config.ssr?.renderFromRoot
+ // __SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = true, 将 html 中的 title, metas 标签逻辑全部交给 metadataLoader 合并逻辑处理
+ const markupArgs = api.config.ssr
+ ?.__SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
? (omit(args, [
MetadataLoaderOmitKeys.Title,
MetadataLoaderOmitKeys.Meta,
diff --git a/packages/preset-umi/src/features/ssr/ssr.ts b/packages/preset-umi/src/features/ssr/ssr.ts
index 23a25fec5bc2..df0613afe597 100644
--- a/packages/preset-umi/src/features/ssr/ssr.ts
+++ b/packages/preset-umi/src/features/ssr/ssr.ts
@@ -29,7 +29,7 @@ export default (api: IApi) => {
serverBuildTarget: zod.enum(['express', 'worker']),
platform: zod.string(),
builder: zod.enum(['esbuild', 'webpack']),
- renderFromRoot: zod.boolean(),
+ __SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: zod.boolean(),
})
.deepPartial();
},
diff --git a/packages/preset-umi/src/features/tmpFiles/tmpFiles.ts b/packages/preset-umi/src/features/tmpFiles/tmpFiles.ts
index 31497b4e5a62..ba647856f63e 100644
--- a/packages/preset-umi/src/features/tmpFiles/tmpFiles.ts
+++ b/packages/preset-umi/src/features/tmpFiles/tmpFiles.ts
@@ -489,7 +489,8 @@ if (process.env.NODE_ENV === 'development') {
const umiPluginPath = winPath(join(umiDir, 'client/client/plugin.js'));
const umiServerPath = winPath(require.resolve('@umijs/server/dist/ssr'));
- const renderFromRoot = api.config.ssr?.renderFromRoot ?? false;
+ const __SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED =
+ api.config.ssr?.__SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ?? false;
const mountElementId = api.config.mountElementId;
const routesWithServerLoader = Object.keys(routes).reduce<
@@ -537,7 +538,7 @@ if (process.env.NODE_ENV === 'development') {
metas,
scripts: scripts || [],
}),
- renderFromRoot,
+ __SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
mountElementId,
},
});
diff --git a/packages/preset-umi/templates/server.tpl b/packages/preset-umi/templates/server.tpl
index 322c46939eff..7598d8962723 100644
--- a/packages/preset-umi/templates/server.tpl
+++ b/packages/preset-umi/templates/server.tpl
@@ -55,7 +55,7 @@ const createOpts = {
createHistory,
ServerInsertedHTMLContext,
htmlPageOpts: {{{htmlPageOpts}}},
- renderFromRoot: {{{renderFromRoot}}},
+ __SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {{{__SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED}}},
mountElementId: '{{{mountElementId}}}'
};
diff --git a/packages/renderer-react/src/browser.tsx b/packages/renderer-react/src/browser.tsx
index d9c9cd3cbb35..5b2c843edead 100644
--- a/packages/renderer-react/src/browser.tsx
+++ b/packages/renderer-react/src/browser.tsx
@@ -102,10 +102,9 @@ export type RenderClientOpts = {
*/
rootElement?: HTMLElement;
/**
- * ssr 是否从 app root 根节点开始 render
- * @doc 默认 false, 从 app root 开始 render,为 true 时从 html 开始
+ * 内部流程, 渲染特殊 html 节点, 不要使用!!!
*/
- renderFromRoot?: boolean;
+ __SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?: boolean;
/**
* 当前的路由配置
*/
@@ -391,7 +390,9 @@ export function renderClient(opts: RenderClientOpts) {
};
ReactDOM.hydrateRoot(
- opts.renderFromRoot ? rootElement : document,
+ opts.__SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
+ ? rootElement
+ : document,
,
diff --git a/packages/renderer-react/src/html.tsx b/packages/renderer-react/src/html.tsx
index 176d1cbc2419..431783fdab3d 100644
--- a/packages/renderer-react/src/html.tsx
+++ b/packages/renderer-react/src/html.tsx
@@ -11,7 +11,23 @@ function isUrl(str: string) {
str.startsWith('../')
);
}
-
+const GlobalDataScript = (props: IHtmlProps) => {
+ const { loaderData, htmlPageOpts, manifest } = props;
+ return (
+
+ );
+};
function normalizeScripts(script: IScript, extraProps = {}) {
if (typeof script === 'string') {
return isUrl(script)
@@ -86,17 +102,30 @@ export function Html({
loaderData,
manifest,
htmlPageOpts,
- renderFromRoot,
+ __SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
mountElementId,
}: React.PropsWithChildren) {
// TODO: 处理 head 标签,比如 favicon.ico 的一致性
// TODO: root 支持配置
- if (renderFromRoot) {
+ if (__SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) {
return (
- <>
-
- {children}
- >
+
+
+
+