Skip to content

Commit

Permalink
fix(astro): Prevent prefetching of same urls with different hashes (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>

* Update .changeset/nasty-ladybugs-whisper.md

Co-authored-by: Bjorn Lu <[email protected]>

---------

Co-authored-by: Bjorn Lu <[email protected]>
  • Loading branch information
voidfill and bluwy authored Aug 26, 2024
1 parent 6fcaab8 commit 497324c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-ladybugs-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Prevents prefetching of the same urls with different hashes.
3 changes: 3 additions & 0 deletions packages/astro/src/prefetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 497324c

Please sign in to comment.