Skip to content

Commit

Permalink
perf: disable pre-render for demo pages when enable ssr (#1449)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Feb 2, 2023
1 parent 9906738 commit a8523d1
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/features/exportStatic.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}),
);
};
}
Expand Down

0 comments on commit a8523d1

Please sign in to comment.