Skip to content

Conversation

christensenep
Copy link
Contributor

What/Why?

Adds support for the DEFAULT_PREFETCH_BEHAVIOR environment variable. If set to true, Link components will default to prefetch=true when a prefetch prop is not provided. Otherwise, they will default to prefetch=false, which is the current behavior.

Testing

Tested locally, verifying that prefetching is globally disabled when DEEFAULT_PREFETCH_BEHAVIOR is any value other than true, and enabled if it is set to true.

@christensenep christensenep requested a review from a team as a code owner February 14, 2024 03:17
Copy link

vercel bot commented Feb 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
catalyst-core-kynz ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 15, 2024 0:49am
catalyst-latest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 15, 2024 0:49am
catalyst-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 15, 2024 0:49am
5 Ignored Deployments
Name Status Preview Comments Updated (UTC)
catalyst ⬜️ Ignored (Inspect) Feb 15, 2024 0:49am
catalyst-1millionproducts-store ⬜️ Ignored (Inspect) Visit Preview Feb 15, 2024 0:49am
catalyst-2000ms-api ⬜️ Ignored (Inspect) Feb 15, 2024 0:49am
catalyst-ppr ⬜️ Ignored (Inspect) Visit Preview Feb 15, 2024 0:49am
catalyst-uk ⬜️ Ignored (Inspect) Visit Preview Feb 15, 2024 0:49am

.env.example Outdated
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to prefix this with NEXT_PUBLIC_

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦

Copy link
Contributor

⚡️🏠 Lighthouse report

We ran Lighthouse against the changes and produced this report. Here's the summary:

Category Score
🟢 Performance 96
🟢 Accessibility 95
🟠 Best practices 78
🟢 SEO 92

Lighthouse ran against https://catalyst-latest-th6fst05a-bigcommerce-platform.vercel.app/

@vercel vercel bot temporarily deployed to Preview – catalyst-core-kynz February 15, 2024 00:49 Inactive
@@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const prefetchDefault = process.env.DEFAULT_PREFETCH_BEHAVIOR === 'true';
const prefetchDefault = process.env.NEXT_PUBLIC_DEFAULT_PREFETCH_BEHAVIOR === 'true';

Or does next remove NEXT_PUBLIC by default? 🤔

@christensenep
Copy link
Contributor Author

Going to close this for now

@chanceaclark chanceaclark deleted the add-prefetch-config branch January 10, 2025 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants