fix: fix static content removal for lean chunks due to Vue 3.5 changes (#4508)

pull/4809/head
Evan You 8 months ago committed by GitHub
parent 2e54970f71
commit 8214cae21b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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')
}

@ -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

Loading…
Cancel
Save