From a8523d1a55de8303f2541a98f8f2443da60cbeb5 Mon Sep 17 00:00:00 2001 From: Peach Date: Thu, 2 Feb 2023 17:39:19 +0800 Subject: [PATCH] perf: disable pre-render for demo pages when enable ssr (#1449) --- src/features/exportStatic.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/features/exportStatic.ts b/src/features/exportStatic.ts index 85b42c17ce..fe2d476acb 100644 --- a/src/features/exportStatic.ts +++ b/src/features/exportStatic.ts @@ -1,5 +1,6 @@ import { SP_ROUTE_PREFIX } from '@/constants'; import type { IApi } from '@/types'; +import { semver } from 'umi/plugin-utils'; import { getExampleAssets } from './assets'; export default (api: IApi) => { @@ -35,7 +36,15 @@ export default (api: IApi) => { memo.exportStatic ??= {}; memo.exportStatic.extraRoutePaths = async () => { const examples = getExampleAssets(); - const userExtraPaths: string[] = []; + const userExtraPaths: ( + | string + | { path: string; prerender: boolean } + )[] = []; + // Umi support disable prerender since 4.0.48 + const isSupportDisablePrerender = semver.gte( + api.appData.umi.version, + '4.0.48', + ); // merge all extraRoutePaths from default config & config for (const prev of prevExtraRoutePaths) { @@ -45,7 +54,13 @@ export default (api: IApi) => { } return userExtraPaths.concat( - examples.map(({ id }) => `/${SP_ROUTE_PREFIX}demos/${id}`), + examples.map(({ id }) => { + const demoPath = `/${SP_ROUTE_PREFIX}demos/${id}`; + + return isSupportDisablePrerender + ? { path: demoPath, prerender: false } + : demoPath; + }), ); }; }