Skip to content

Commit

Permalink
fix: fix static content removal for lean chunks due to Vue 3.5 changes (
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored Jan 22, 2025
1 parent 2e54970 commit 8214cae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
9 changes: 1 addition & 8 deletions src/client/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

Expand Down
12 changes: 6 additions & 6 deletions src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8214cae

Please sign in to comment.