Skip to content

Commit

Permalink
fix: do not hydrate demo page (#1550)
Browse files Browse the repository at this point in the history
* fix: do not hydrate demo page

* chore: code clean

* fix: path
  • Loading branch information
MadCcc committed Mar 17, 2023
1 parent 547a862 commit 95c940f
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/features/exportStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import type { IApi } from '@/types';
import { getExampleAssets } from './assets';

const NO_PRERENDER_ROUTES = [
// to avoid hydration error for gh-pages
// it cannot support `~` and will fall back demo single page to 404
'404',
// disable prerender for demo render page, because umi-hd doesn't support ssr
// ref: https://github.com/umijs/dumi/pull/1451
'demo-render',
Expand Down Expand Up @@ -50,4 +47,25 @@ export default (api: IApi) => {
return memo;
},
});

api.onGenerateFiles(() => {
api.writeTmpFile({
path: 'dumi/exportStaticRuntimePlugin.ts',
content: `
export function modifyClientRenderOpts(memo: any) {
const { history, hydrate } = memo;
return {
...memo,
hydrate: hydrate && !history.location.pathname.startsWith('/${SP_ROUTE_PREFIX}demos'),
};
}
`.trim(),
noPluginDir: true,
});
});

api.addRuntimePlugin(() => {
return [`@@/dumi/exportStaticRuntimePlugin.ts`];
});
};

0 comments on commit 95c940f

Please sign in to comment.