Skip to content

Commit

Permalink
fix #551: don't prefetch media files
Browse files Browse the repository at this point in the history
  • Loading branch information
rtrembecky committed Dec 21, 2024
1 parent d33bade commit 3162b96
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/components/Clickable/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,27 @@ type LinkProps = {
active?: boolean
sx?: SxProps<Theme>
textSx?: SxProps<Theme>
} & Pick<ComponentProps<typeof NextLink>, 'target'>
} & Pick<ComponentProps<typeof NextLink>, 'target' | 'prefetch'>

export const Link: FC<LinkProps> = ({
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<LinkProps> = ({children, href, disabled, target, variant, invertColors, active, sx, textSx}) => {
if (disabled) {
return (
<Box
Expand Down Expand Up @@ -47,6 +65,7 @@ export const Link: FC<LinkProps> = ({children, href, disabled, target, variant,
component={NextLink}
href={href ?? ''}
target={target}
prefetch={prefetch}
sx={{
...getButtonWrapperSx({invertColors, disabled, active}),
...sx,
Expand Down

0 comments on commit 3162b96

Please sign in to comment.