This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix prefetching when clicking quickly back and forth (#1668)
- Loading branch information
1 parent
13b1243
commit 4a32dec
Showing
4 changed files
with
102 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
test/apps/basics/src/routes/prefetch-timing/prefetched/index.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script context="module"> | ||
export function preload() { | ||
if (typeof window !== 'undefined' && window.onPrefetched) { | ||
Promise.resolve().then(() => window.onPrefetched()); | ||
} | ||
} | ||
</script> | ||
|
||
<script> | ||
import { onMount } from 'svelte'; | ||
let prefetchlink; | ||
onMount(() => { | ||
let timeout; | ||
/** | ||
* This emulates the logic in start prefetching. Just firing after the first mouse move | ||
* would also work fine in the Puppeteer tests, just not if you try it manually. | ||
*/ | ||
prefetchlink.addEventListener('mousemove', () => { | ||
clearTimeout(timeout); | ||
if (window.onPrefetched) { | ||
timeout = setTimeout(() => { | ||
window.onPrefetched(); | ||
}, 50); | ||
} | ||
}); | ||
}); | ||
</script> | ||
|
||
<h1>Prefetched</h1> | ||
|
||
<a href="/prefetch-timing/prefetcher">prefetcher</a> | ||
<a href="/prefetch-timing/prefetched" rel="prefetch" bind:this={prefetchlink}>prefetched</a> |
13 changes: 13 additions & 0 deletions
13
test/apps/basics/src/routes/prefetch-timing/prefetcher/index.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script context="module"> | ||
export function preload() { | ||
if (typeof window !== 'undefined') { | ||
return new Promise((resolve) => { | ||
window.onPrefetched = resolve; | ||
}); | ||
} | ||
} | ||
</script> | ||
|
||
<h1>Prefetcher</h1> | ||
|
||
<a href="/prefetch-timing/prefetched" rel="prefetch">prefetched</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters