Skip to content

Commit 8214cae

Browse files
authoredJan 22, 2025··
fix: fix static content removal for lean chunks due to Vue 3.5 changes (#4508)
1 parent 2e54970 commit 8214cae

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed
 

‎src/client/app/index.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,14 @@ function newApp(): App {
119119

120120
function newRouter(): Router {
121121
let isInitialPageLoad = inBrowser
122-
let initialPath: string
123122

124123
return createRouter((path) => {
125124
let pageFilePath = pathToFile(path)
126125
let pageModule = null
127126

128127
if (pageFilePath) {
128+
// use lean build if this is the initial page load
129129
if (isInitialPageLoad) {
130-
initialPath = pageFilePath
131-
}
132-
133-
// use lean build if this is the initial page load or navigating back
134-
// to the initial loaded path (the static vnodes already adopted the
135-
// static content on that load so no need to re-fetch the page)
136-
if (isInitialPageLoad || initialPath === pageFilePath) {
137130
pageFilePath = pageFilePath.replace(/\.js$/, '.lean.js')
138131
}
139132

‎src/node/plugin.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ declare module 'vite' {
3838

3939
const themeRE = /\/\.vitepress\/theme\/index\.(m|c)?(j|t)s$/
4040
const hashRE = /\.([-\w]+)\.js$/
41-
const staticInjectMarkerRE =
42-
/\b(const _hoisted_\d+ = \/\*(?:#|@)__PURE__\*\/\s*createStaticVNode)\("(.*)", (\d+)\)/g
41+
const staticInjectMarkerRE = /\bcreateStaticVNode\((?:(".*")|('.*')), (\d+)\)/g
4342
const staticStripRE = /['"`]__VP_STATIC_START__[^]*?__VP_STATIC_END__['"`]/g
4443
const staticRestoreRE = /__VP_STATIC_(START|END)__/g
4544

@@ -325,10 +324,11 @@ export async function createVitePressPlugin(
325324
// Using a regexp relies on specific output from Vue compiler core,
326325
// which is a reasonable trade-off considering the massive perf win over
327326
// a full AST parse.
328-
code = code.replace(
329-
staticInjectMarkerRE,
330-
'$1("__VP_STATIC_START__$2__VP_STATIC_END__", $3)'
331-
)
327+
code = code.replace(staticInjectMarkerRE, (_, str1, str2, flag) => {
328+
const str = str1 || str2
329+
const quote = str[0]
330+
return `createStaticVNode(${quote}__VP_STATIC_START__${str.slice(1, -1)}__VP_STATIC_END__${quote}, ${flag})`
331+
})
332332
return code
333333
}
334334
return null

0 commit comments

Comments
 (0)
Please sign in to comment.