feat(client): allow disabling link auto-prefetching (#3220)

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
pull/3233/head
bonyuta0204 2 years ago committed by GitHub
parent 8438e971dd
commit 563dc89975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -48,7 +48,7 @@ const VitePressApp = defineComponent({
}) })
}) })
if (import.meta.env.PROD) { if (import.meta.env.PROD && site.value.router.prefetchLinks) {
// in prod mode, enable intersectionObserver based pre-fetch // in prod mode, enable intersectionObserver based pre-fetch
usePrefetch() usePrefetch()
} }

@ -243,6 +243,9 @@ export async function resolveSiteData(
description: userConfig.description || 'A VitePress site', description: userConfig.description || 'A VitePress site',
base: userConfig.base ? userConfig.base.replace(/([^/])$/, '$1/') : '/', base: userConfig.base ? userConfig.base.replace(/([^/])$/, '$1/') : '/',
head: resolveSiteDataHead(userConfig), head: resolveSiteDataHead(userConfig),
router: {
prefetchLinks: userConfig.router?.prefetchLinks ?? true
},
appearance: userConfig.appearance ?? true, appearance: userConfig.appearance ?? true,
themeConfig: userConfig.themeConfig || {}, themeConfig: userConfig.themeConfig || {},
locales: userConfig.locales || {}, locales: userConfig.locales || {},

@ -69,6 +69,10 @@ export interface UserConfig<ThemeConfig = any>
locales?: LocaleConfig<ThemeConfig> locales?: LocaleConfig<ThemeConfig>
router?: {
prefetchLinks?: boolean
}
appearance?: appearance?:
| boolean | boolean
| 'dark' | 'dark'
@ -201,6 +205,7 @@ export interface SiteConfig<ThemeConfig = any>
| 'vue' | 'vue'
| 'vite' | 'vite'
| 'shouldPreload' | 'shouldPreload'
| 'router'
| 'mpa' | 'mpa'
| 'metaChunk' | 'metaChunk'
| 'lastUpdated' | 'lastUpdated'

3
types/shared.d.ts vendored

@ -126,6 +126,9 @@ export interface SiteData<ThemeConfig = any> {
locales: LocaleConfig<ThemeConfig> locales: LocaleConfig<ThemeConfig>
localeIndex?: string localeIndex?: string
contentProps?: Record<string, any> contentProps?: Record<string, any>
router: {
prefetchLinks: boolean
}
} }
export type HeadConfig = export type HeadConfig =

Loading…
Cancel
Save