Skip to content

Commit

Permalink
fix(client): make page data hmr work as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Apr 8, 2021
1 parent a8c43c0 commit 374ae43
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/@vuepress/client/src/injections/pageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const resolvePageData = async (routePath: string): Promise<PageData> => {
if (import.meta.webpackHot || import.meta.hot) {
// reuse vue HMR runtime
__VUE_HMR_RUNTIME__.updatePageData = (data: PageData) => {
pagesData.value[data.path] = () => Promise.resolve(data)
if (data.key === pageData.value.key) {
pageData.value = data
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@vuepress/client/src/injections/pagesData.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { readonly, ref } from 'vue'
import { ref } from 'vue'
import type { Ref } from 'vue'
import type { PageData } from '@vuepress/shared'
import { pagesData as pagesDataRaw } from '@internal/pagesData'

export type PagesData = Record<string, () => Promise<PageData>>
export type PagesDataRef = Ref<PagesData>

export const pagesData: PagesDataRef = ref(readonly(pagesDataRaw) as PagesData)
export const pagesData: PagesDataRef = ref(pagesDataRaw)

export const usePagesData = (): PagesDataRef => {
return pagesData
Expand Down

0 comments on commit 374ae43

Please sign in to comment.