Skip to content

Commit 96bcdda

Browse files
committedSep 7, 2021
perf: minor optimizations
1 parent e01b5a3 commit 96bcdda

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
 

Diff for: ‎src/client/app/data.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InjectionKey, Ref, ref, readonly, computed, inject } from 'vue'
1+
import { InjectionKey, Ref, shallowRef, readonly, computed, inject } from 'vue'
22
import { Route } from './router'
33
import serializedSiteData from '@siteData'
44
import { resolveSiteDataByRoute, PageData, SiteData } from '../shared'
@@ -20,7 +20,7 @@ export interface VitePressData<T = any> {
2020
// site data is a singleton
2121
export type SiteDataRef<T = any> = Ref<SiteData<T>>
2222

23-
export const siteDataRef: Ref<SiteData> = ref(parse(serializedSiteData))
23+
export const siteDataRef: Ref<SiteData> = shallowRef(parse(serializedSiteData))
2424

2525
function parse(data: string): SiteData {
2626
return readonly(JSON.parse(data)) as SiteData

Diff for: ‎src/client/app/router.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ export function createRouter(
7777

7878
route.path = pendingPath
7979
route.component = markRaw(comp)
80-
route.data = readonly(JSON.parse(__pageData)) as PageData
80+
route.data = import.meta.env.PROD
81+
? markRaw(JSON.parse(__pageData))
82+
: (readonly(JSON.parse(__pageData)) as PageData)
8183

8284
if (inBrowser) {
8385
nextTick(() => {
@@ -94,7 +96,7 @@ export function createRouter(
9496
})
9597
}
9698
}
97-
} catch (err) {
99+
} catch (err: any) {
98100
if (!err.message.match(/fetch/)) {
99101
console.error(err)
100102
}

0 commit comments

Comments
 (0)