diff --git a/src/client/app/index.ts b/src/client/app/index.ts index 2c7c66f0..5acb3be5 100644 --- a/src/client/app/index.ts +++ b/src/client/app/index.ts @@ -119,21 +119,14 @@ function newApp(): App { function newRouter(): Router { let isInitialPageLoad = inBrowser - let initialPath: string return createRouter((path) => { let pageFilePath = pathToFile(path) let pageModule = null if (pageFilePath) { + // use lean build if this is the initial page load if (isInitialPageLoad) { - initialPath = pageFilePath - } - - // use lean build if this is the initial page load or navigating back - // to the initial loaded path (the static vnodes already adopted the - // static content on that load so no need to re-fetch the page) - if (isInitialPageLoad || initialPath === pageFilePath) { pageFilePath = pageFilePath.replace(/\.js$/, '.lean.js') } diff --git a/src/node/plugin.ts b/src/node/plugin.ts index 27c8552e..563bbdf3 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -38,8 +38,7 @@ declare module 'vite' { const themeRE = /\/\.vitepress\/theme\/index\.(m|c)?(j|t)s$/ const hashRE = /\.([-\w]+)\.js$/ -const staticInjectMarkerRE = - /\b(const _hoisted_\d+ = \/\*(?:#|@)__PURE__\*\/\s*createStaticVNode)\("(.*)", (\d+)\)/g +const staticInjectMarkerRE = /\bcreateStaticVNode\((?:(".*")|('.*')), (\d+)\)/g const staticStripRE = /['"`]__VP_STATIC_START__[^]*?__VP_STATIC_END__['"`]/g const staticRestoreRE = /__VP_STATIC_(START|END)__/g @@ -325,10 +324,11 @@ export async function createVitePressPlugin( // Using a regexp relies on specific output from Vue compiler core, // which is a reasonable trade-off considering the massive perf win over // a full AST parse. - code = code.replace( - staticInjectMarkerRE, - '$1("__VP_STATIC_START__$2__VP_STATIC_END__", $3)' - ) + code = code.replace(staticInjectMarkerRE, (_, str1, str2, flag) => { + const str = str1 || str2 + const quote = str[0] + return `createStaticVNode(${quote}__VP_STATIC_START__${str.slice(1, -1)}__VP_STATIC_END__${quote}, ${flag})` + }) return code } return null