sapper icon indicating copy to clipboard operation
sapper copied to clipboard

using prefetch programatically can cause a double fetch

Open kevmodrome opened this issue 6 years ago • 1 comments

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.

kevmodrome avatar Jan 19 '20 15:01 kevmodrome

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>

koffeinfrei avatar Dec 22 '20 12:12 koffeinfrei