From d8fc9e15bd2ae4c945b5a3856a6ce3b5629e8b29 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Wed, 6 Dec 2023 19:26:05 +0100 Subject: [PATCH] Prefetch links on hover by default (#1242) Co-authored-by: Paul Valladares <85648028+dreyfus92@users.noreply.github.com> --- .changeset/sour-guests-tease.md | 24 ++++++++++++++++++++++++ package.json | 2 +- packages/starlight/index.ts | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .changeset/sour-guests-tease.md diff --git a/.changeset/sour-guests-tease.md b/.changeset/sour-guests-tease.md new file mode 100644 index 00000000000..3fb73a89981 --- /dev/null +++ b/.changeset/sour-guests-tease.md @@ -0,0 +1,24 @@ +--- +'@astrojs/starlight': minor +--- + +Enables link prefetching on hover by default + +Astro v4’s [prefetch](https://docs.astro.build/en/guides/prefetch) support is now enabled by default. If `prefetch` is not set in `astro.config.mjs`, Starlight will use `prefetch: { prefetchAll: true, defaultStrategy: 'hover' }` by default. + +If you want to preserve previous behaviour, disable link prefetching in `astro.config.mjs`: + +```js +import { defineConfig } from 'astro/config'; +import starlight from '@astrojs/starlight'; + +export default defineConfig({ + // Disable link prefetching: + prefetch: false, + + integrations: [ + starlight({ + // ... + }), + ], +}); diff --git a/package.json b/package.json index 3ffa2345b37..18de4e46b99 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ { "name": "/_astro/*.js", "path": "examples/basics/dist/_astro/*.js", - "limit": "21 kB" + "limit": "22 kB" }, { "name": "/_astro/*.css", diff --git a/packages/starlight/index.ts b/packages/starlight/index.ts index 5aa4cd50b04..3b3ba76bf22 100644 --- a/packages/starlight/index.ts +++ b/packages/starlight/index.ts @@ -76,6 +76,8 @@ export default function StarlightIntegration({ config.markdown.shikiConfig.theme !== 'github-dark' ? {} : { theme: 'css-variables' }, }, scopedStyleStrategy: 'where', + // If not already configured, default to prefetching all links on hover. + prefetch: config.prefetch ?? { prefetchAll: true }, }); },