0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

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 <bjornlu.dev@gmail.com>

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

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>

---------

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
This commit is contained in:
voidfill 2024-08-26 13:28:27 +02:00 committed by GitHub
parent 6fcaab84de
commit 497324c4e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Prevents prefetching of the same urls with different hashes.

View file

@ -215,6 +215,9 @@ export interface PrefetchOptions {
* @param opts Additional options for prefetching. * @param opts Additional options for prefetching.
*/ */
export function prefetch(url: string, opts?: PrefetchOptions) { 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; const ignoreSlowConnection = opts?.ignoreSlowConnection ?? false;
if (!canPrefetchUrl(url, ignoreSlowConnection)) return; if (!canPrefetchUrl(url, ignoreSlowConnection)) return;
prefetchedUrls.add(url); prefetchedUrls.add(url);