sapper
sapper copied to clipboard
using prefetch programatically can cause a double fetch
It appears that using prefetch programmatically does not work correctly.
If I add for example on:mousedown={() => prefetch(url)} it does indeed fetch the data on mousedown, however - when I release the mouse it seems to do the fetch again causing the data to be doubly fetched. I expect the data to only be fetched once.
To recreate add on:mousedown={() => prefetch('blog')} to the blog link on the sapper-template.
Running Firefox 72 on macOS Catalina.
The behavior is seen in dev, build and exported versions of the application.
I'm currently using the following workaround:
<script>
onMount(() => {
// the programmatic call to `prefetch` doesn't seem to work. triggering
// the `rel=prefetch` on the link element seems to do the trick.
link.dispatchEvent(new MouseEvent('touchstart', { 'bubbles': true }));
});
}
</script>
<a bind:this={link} rel=prefetch href={url}>link text</a>