perf: minor optimizations

pull/384/head
Evan You 3 years ago
parent e01b5a350c
commit 96bcddabed

@ -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 { Route } from './router'
import serializedSiteData from '@siteData' import serializedSiteData from '@siteData'
import { resolveSiteDataByRoute, PageData, SiteData } from '../shared' import { resolveSiteDataByRoute, PageData, SiteData } from '../shared'
@ -20,7 +20,7 @@ export interface VitePressData<T = any> {
// site data is a singleton // site data is a singleton
export type SiteDataRef<T = any> = Ref<SiteData<T>> 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 { function parse(data: string): SiteData {
return readonly(JSON.parse(data)) as SiteData return readonly(JSON.parse(data)) as SiteData

@ -77,7 +77,9 @@ export function createRouter(
route.path = pendingPath route.path = pendingPath
route.component = markRaw(comp) 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) { if (inBrowser) {
nextTick(() => { nextTick(() => {
@ -94,7 +96,7 @@ export function createRouter(
}) })
} }
} }
} catch (err) { } catch (err: any) {
if (!err.message.match(/fetch/)) { if (!err.message.match(/fetch/)) {
console.error(err) console.error(err)
} }

Loading…
Cancel
Save