From 78e16c06fcf82fc66e0cb2dbf115ff87a12d2e53 Mon Sep 17 00:00:00 2001 From: Erik Christensen Date: Tue, 13 Feb 2024 19:15:12 -0800 Subject: [PATCH] feat(core): Add env var to control default prefetch behavior --- .env.example | 5 +++++ apps/core/components/link/index.tsx | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index bfb92306c5..3a6a10d4d1 100644 --- a/.env.example +++ b/.env.example @@ -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 \ No newline at end of file diff --git a/apps/core/components/link/index.tsx b/apps/core/components/link/index.tsx index 218cba2961..7cd8c496f9 100644 --- a/apps/core/components/link/index.tsx +++ b/apps/core/components/link/index.tsx @@ -9,8 +9,10 @@ type LinkType = Omit, keyof LinkPr children?: React.ReactNode; } & React.RefAttributes; +const prefetchDefault = process.env.DEFAULT_PREFETCH_BEHAVIOR === 'true'; + export const Link = forwardRef, LinkType>( - ({ href, prefetch = false, children, className, ...rest }, ref) => { + ({ href, prefetch = prefetchDefault, children, className, ...rest }, ref) => { return (