Skip to content

Commit dfa62c9

Browse files
authored
chore: avoid to prefetch docs links (#1731)
* chore: avoid to prefetch docs links * chore: disable prefetch for mobile
1 parent 38d6ce2 commit dfa62c9

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/components/hook/use-breakpoint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useWindowSize } from './use-window-size'
55

66
const rawBreakpoints = breakpoints.map(toRaw)
77

8-
export function useBreakpoint (mediaBreakpoints) {
8+
export function useBreakpoint (mediaBreakpoints = [0, 1, 2, 3]) {
99
const { width } = useWindowSize()
1010

1111
const index = useMemo(() => {

src/components/patterns/Layout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const Layout = ({
3131
component = Box,
3232
...props
3333
}) => {
34-
const breakpoint = useBreakpoint([0, 1, 2, 3])
34+
const breakpoint = useBreakpoint()
3535
const toolbarHeight = TOOLBAR_HEIGHTS[breakpoint]
3636

3737
useEffect(() => {

src/helpers/hoc/with-link.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* global IntersectionObserver */
22

3+
import { useBreakpoint } from '../../components/hook/use-breakpoint'
34
import { ArrowUpRight as ExternalIcon } from 'react-feather'
45
import React, { useRef, useState, useEffect } from 'react'
56
import { useLocation } from '@gatsbyjs/reach-router'
@@ -134,7 +135,14 @@ export const withLink = Component => {
134135
return { className: 'active' }
135136
}
136137

137-
if (prefetch && (!href || isInternal)) {
138+
const isPrefetch =
139+
useBreakpoint() > 1 &&
140+
prefetch &&
141+
href !== '/' &&
142+
!href.startsWith('/docs') &&
143+
(!href || isInternal)
144+
145+
if (isPrefetch) {
138146
return (
139147
<Component {...props}>
140148
<PrefetchLink

0 commit comments

Comments
 (0)