Skip to content

Commit

Permalink
feat(core): Add env var to control default prefetch behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
christensenep committed Feb 14, 2024
1 parent 57996e8 commit 78e16c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ AUTH_SECRET=
# https://turbo.build/repo/docs/core-concepts/remote-caching#artifact-integrity-and-authenticity-verification
# This can also be generated with `openssl rand -hex 32`, but do not re-use the value from AUTH_SECRET
TURBO_REMOTE_CACHE_SIGNATURE_KEY=

# Controls the default behavior of Link components when a `prefetch` prop is not provided.
# If set to `true`, Link components will default to `prefetch=true`.
# Otherwise, Link components will default to `prefetch=false`.
DEFAULT_PREFETCH_BEHAVIOR=false
4 changes: 3 additions & 1 deletion apps/core/components/link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ type LinkType = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof LinkPr
children?: React.ReactNode;
} & React.RefAttributes<HTMLAnchorElement>;

const prefetchDefault = process.env.DEFAULT_PREFETCH_BEHAVIOR === 'true';

export const Link = forwardRef<ElementRef<'a'>, LinkType>(
({ href, prefetch = false, children, className, ...rest }, ref) => {
({ href, prefetch = prefetchDefault, children, className, ...rest }, ref) => {
return (
<NextLink
className={cn(
Expand Down

0 comments on commit 78e16c0

Please sign in to comment.