From 497324c4e87538dc1dc13aea3ced9bd3642d9ba6 Mon Sep 17 00:00:00 2001 From: voidfill <71205200+voidfill@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:28:27 +0200 Subject: [PATCH] fix(astro): Prevent prefetching of same urls with different hashes (#11713) * fix(astro): prevent prefetching of the same urls with different hashes * add changeset * Update packages/astro/src/prefetch/index.ts Co-authored-by: Bjorn Lu * Update .changeset/nasty-ladybugs-whisper.md Co-authored-by: Bjorn Lu --------- Co-authored-by: Bjorn Lu --- .changeset/nasty-ladybugs-whisper.md | 5 +++++ packages/astro/src/prefetch/index.ts | 3 +++ 2 files changed, 8 insertions(+) create mode 100644 .changeset/nasty-ladybugs-whisper.md diff --git a/.changeset/nasty-ladybugs-whisper.md b/.changeset/nasty-ladybugs-whisper.md new file mode 100644 index 000000000000..d922187e5cb0 --- /dev/null +++ b/.changeset/nasty-ladybugs-whisper.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Prevents prefetching of the same urls with different hashes. diff --git a/packages/astro/src/prefetch/index.ts b/packages/astro/src/prefetch/index.ts index 177945f379a5..3eb8cd57018e 100644 --- a/packages/astro/src/prefetch/index.ts +++ b/packages/astro/src/prefetch/index.ts @@ -215,6 +215,9 @@ export interface PrefetchOptions { * @param opts Additional options for prefetching. */ export function prefetch(url: string, opts?: PrefetchOptions) { + // Remove url hash to avoid prefetching the same URL multiple times + url = url.replace(/#.*/, ''); + const ignoreSlowConnection = opts?.ignoreSlowConnection ?? false; if (!canPrefetchUrl(url, ignoreSlowConnection)) return; prefetchedUrls.add(url);