Skip to content

Commit

Permalink
perf: minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 7, 2021
1 parent e01b5a3 commit 96bcdda
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/client/app/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InjectionKey, Ref, ref, readonly, computed, inject } from 'vue'
import { InjectionKey, Ref, shallowRef, readonly, computed, inject } from 'vue'
import { Route } from './router'
import serializedSiteData from '@siteData'
import { resolveSiteDataByRoute, PageData, SiteData } from '../shared'
Expand All @@ -20,7 +20,7 @@ export interface VitePressData<T = any> {
// site data is a singleton
export type SiteDataRef<T = any> = Ref<SiteData<T>>

export const siteDataRef: Ref<SiteData> = ref(parse(serializedSiteData))
export const siteDataRef: Ref<SiteData> = shallowRef(parse(serializedSiteData))

function parse(data: string): SiteData {
return readonly(JSON.parse(data)) as SiteData
Expand Down
6 changes: 4 additions & 2 deletions src/client/app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export function createRouter(

route.path = pendingPath
route.component = markRaw(comp)
route.data = readonly(JSON.parse(__pageData)) as PageData
route.data = import.meta.env.PROD
? markRaw(JSON.parse(__pageData))
: (readonly(JSON.parse(__pageData)) as PageData)

if (inBrowser) {
nextTick(() => {
Expand All @@ -94,7 +96,7 @@ export function createRouter(
})
}
}
} catch (err) {
} catch (err: any) {
if (!err.message.match(/fetch/)) {
console.error(err)
}
Expand Down

0 comments on commit 96bcdda

Please sign in to comment.