Skip to content

Commit

Permalink
feat(client): allow disabling link auto-prefetching (#3220)
Browse files Browse the repository at this point in the history
Co-authored-by: Divyansh Singh <[email protected]>
  • Loading branch information
bonyuta0204 and brc-dd committed Nov 18, 2023
1 parent 8438e97 commit 563dc89
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/client/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
usePrefetch()
}
Expand Down
3 changes: 3 additions & 0 deletions src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ export async function resolveSiteData(
description: userConfig.description || 'A VitePress site',
base: userConfig.base ? userConfig.base.replace(/([^/])$/, '$1/') : '/',
head: resolveSiteDataHead(userConfig),
router: {
prefetchLinks: userConfig.router?.prefetchLinks ?? true
},
appearance: userConfig.appearance ?? true,
themeConfig: userConfig.themeConfig || {},
locales: userConfig.locales || {},
Expand Down
5 changes: 5 additions & 0 deletions src/node/siteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export interface UserConfig<ThemeConfig = any>

locales?: LocaleConfig<ThemeConfig>

router?: {
prefetchLinks?: boolean
}

appearance?:
| boolean
| 'dark'
Expand Down Expand Up @@ -201,6 +205,7 @@ export interface SiteConfig<ThemeConfig = any>
| 'vue'
| 'vite'
| 'shouldPreload'
| 'router'
| 'mpa'
| 'metaChunk'
| 'lastUpdated'
Expand Down
3 changes: 3 additions & 0 deletions types/shared.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ export interface SiteData<ThemeConfig = any> {
locales: LocaleConfig<ThemeConfig>
localeIndex?: string
contentProps?: Record<string, any>
router: {
prefetchLinks: boolean
}
}

export type HeadConfig =
Expand Down

0 comments on commit 563dc89

Please sign in to comment.