1
1
import type { App } from 'vue'
2
- import { computed } from 'vue'
2
+ import { computed , customRef } from 'vue'
3
3
import type { Router } from 'vue-router'
4
4
import { clientDataSymbol } from './composables/index.js'
5
5
import { redirects , routes } from './internal/routes.js'
@@ -8,6 +8,7 @@ import { resolvers } from './resolvers.js'
8
8
import type {
9
9
ClientConfig ,
10
10
ClientData ,
11
+ PageChunk ,
11
12
PageData ,
12
13
PageFrontmatter ,
13
14
PageHead ,
@@ -31,19 +32,29 @@ export const setupGlobalComputed = (
31
32
const routePath = computed ( ( ) => router . currentRoute . value . path )
32
33
33
34
// load page chunk from route meta
34
- const pageChunk = computed ( ( ) => router . currentRoute . value . meta . _pageChunk ! )
35
+ const pageChunk = customRef < PageChunk > ( ( track , trigger ) => ( {
36
+ get ( ) {
37
+ track ( )
38
+ return router . currentRoute . value . meta . _pageChunk !
39
+ } ,
40
+ set ( value ) {
41
+ router . currentRoute . value . meta . _pageChunk = value
42
+ trigger ( )
43
+ } ,
44
+ } ) )
35
45
36
46
// handle page data HMR
37
47
if ( __VUEPRESS_DEV__ && ( import . meta. webpackHot || import . meta. hot ) ) {
38
48
__VUE_HMR_RUNTIME__ . updatePageData = async ( newPageData : PageData ) => {
39
49
const oldPageChunk = await routes . value [ newPageData . path ] . loader ( )
50
+ const newPageChunk = { comp : oldPageChunk . comp , data : newPageData }
40
51
routes . value [ newPageData . path ] . loader = ( ) =>
41
- Promise . resolve ( { comp : oldPageChunk . comp , data : newPageData } )
52
+ Promise . resolve ( newPageChunk )
42
53
if (
43
54
newPageData . path ===
44
55
router . currentRoute . value . meta . _pageChunk ?. data . path
45
56
) {
46
- router . currentRoute . value . meta . _pageChunk . data = newPageData
57
+ pageChunk . value = newPageChunk
47
58
}
48
59
}
49
60
}
0 commit comments