Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: avoid to prefetch docs links (#1731)
Browse files Browse the repository at this point in the history
* chore: avoid to prefetch docs links

* chore: disable prefetch for mobile
Kikobeats authored Jul 21, 2024
1 parent 38d6ce2 commit dfa62c9
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/hook/use-breakpoint.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { useWindowSize } from './use-window-size'

const rawBreakpoints = breakpoints.map(toRaw)

export function useBreakpoint (mediaBreakpoints) {
export function useBreakpoint (mediaBreakpoints = [0, 1, 2, 3]) {
const { width } = useWindowSize()

const index = useMemo(() => {
2 changes: 1 addition & 1 deletion src/components/patterns/Layout.js
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ const Layout = ({
component = Box,
...props
}) => {
const breakpoint = useBreakpoint([0, 1, 2, 3])
const breakpoint = useBreakpoint()
const toolbarHeight = TOOLBAR_HEIGHTS[breakpoint]

useEffect(() => {
10 changes: 9 additions & 1 deletion src/helpers/hoc/with-link.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global IntersectionObserver */

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

if (prefetch && (!href || isInternal)) {
const isPrefetch =
useBreakpoint() > 1 &&
prefetch &&
href !== '/' &&
!href.startsWith('/docs') &&
(!href || isInternal)

if (isPrefetch) {
return (
<Component {...props}>
<PrefetchLink

0 comments on commit dfa62c9

Please sign in to comment.