From 3162b969090db05068d0dd93f275d1c9bf245bfd Mon Sep 17 00:00:00 2001 From: rtrembecky Date: Sat, 21 Dec 2024 19:36:08 +0100 Subject: [PATCH] fix #551: don't prefetch media files --- src/components/Clickable/Link.tsx | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/components/Clickable/Link.tsx b/src/components/Clickable/Link.tsx index f9daaf27..a136b5a0 100644 --- a/src/components/Clickable/Link.tsx +++ b/src/components/Clickable/Link.tsx @@ -13,9 +13,27 @@ type LinkProps = { active?: boolean sx?: SxProps textSx?: SxProps -} & Pick, 'target'> +} & Pick, 'target' | 'prefetch'> + +export const Link: FC = ({ + children, + href, + disabled, + target, + variant, + invertColors, + active, + sx, + textSx, + prefetch: overridePrefetch, +}) => { + // https://nextjs.org/docs/pages/api-reference/components/link#prefetch + // by default, next.js prefetchuje stranky vsetkych linkov vo viewporte. pre media PDFka je to zbytocne heavy. + // inak aj pri `false` sa stale prefetchne pri hoveri, co je acceptable. + const isMedia = href?.startsWith('/media') + const defaultPrefetch = !isMedia + const prefetch = overridePrefetch ?? defaultPrefetch -export const Link: FC = ({children, href, disabled, target, variant, invertColors, active, sx, textSx}) => { if (disabled) { return ( = ({children, href, disabled, target, variant, component={NextLink} href={href ?? ''} target={target} + prefetch={prefetch} sx={{ ...getButtonWrapperSx({invertColors, disabled, active}), ...sx,