I am using sveltekit for a project. When my current page makes a fetch request that takes a while and the user navigates to another page, it does not go to that page until the fetch request finishes.
<script>
// waits for this fetch when a tag is pressed
let longFetch = fetch('/data.json');
</script>
<a href="/some-page">Some Page</a>
Is there a way to force the page to navigate regardless of ongoing requests?
None of the link options would solve this issue.
Earlier, my solution was to use AbortController, passing it to my a elements and calling controller.abort().
<script>
const controller = new AbortController();
let longFetch = fetch('/data.json', {
signal: controller.signal
});
</script>
<a href="/some-page" on:click={() => controller.close()}>Some Page</a>
But now this does not work. Looking at the network tab, when I click a link there is a __data.json request, but it's very slow and delayed until the longFetch is finished, even if it's aborted.