Skip to content

Invalidate doesn't work while prefetching #6902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dummdidumm opened this issue Sep 19, 2022 · 1 comment · Fixed by #6924
Closed

Invalidate doesn't work while prefetching #6902

dummdidumm opened this issue Sep 19, 2022 · 1 comment · Fixed by #6924
Labels
bug Something isn't working p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. prefetch
Milestone

Comments

@dummdidumm
Copy link
Member

Describe the bug

Calling invalidate or invalidateAll doesn't behave as expected when a prefetch is happening. load_route returns early in this case, swallowing the invalidate calls.

Reproduction

This thread has more info: https://discord.com/channels/457912077277855764/1013838400601731152

Logs

No response

System Info

Irrelevant

Severity

annoyance

Additional Information

In general I think we need to have some more stateful logic around invalidation - how they interact with redirects etc.

@dummdidumm dummdidumm added bug Something isn't working p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. labels Sep 19, 2022
@dummdidumm dummdidumm added this to the 1.0 milestone Sep 19, 2022
@ollema
Copy link

ollema commented Sep 20, 2022

Figured I could post this here as well for those without discord:


I found how to more reliably trigger the issue now and I was able to record it with some timestamps.

In this video:

  • I first demo the expected behaviour when a user signs in or out

  • Then I attempt to not trigger the load function in +layout.server.svelte by

    1. Signing in
    2. Waiting a couple of seconds to show that it should not be a matter of load being triggered too often
    3. Clicking about
    4. Quickly clicking sign out
    5. After a couple of attempts, I was able to reproduce it on video! You can see that:
21:34:31 signing out - calling `await invalidateAll()` - should trigger `load`
21:34:40 signing out - calling `await invalidateAll()` - should trigger `load`

are both printed before the:

21:34:40 load triggered

Here's the interesting part:

I believe that this issue is related to prefetching!

My about page is very simple:

<main>about sersophane</main>

<footer />

in my Nav.svelte component that is used in my root +layout.svelte I have:

...
<a data-sveltekit-prefetch href="/about" class:selected={section === 'about'}>about</a>
...

I found that if I remove data-sveltekit-prefetch I can no longer trigger it! (or at least it is much much more rare, it has not happened to me yet).

demo.mov

dummdidumm added a commit that referenced this issue Sep 20, 2022
- Fixes #6844, invalidation is now only reset after navigation settled
- Fixes #5305, newer invalidations are no longer swalloed by ongoing older ones
- Fixes #6902, the pending prefetch is reset upon invalidation
Rich-Harris added a commit that referenced this issue Sep 21, 2022
* [fix] tighten up navigation and invalidation logic

- Fixes #6844, invalidation is now only reset after navigation settled
- Fixes #5305, newer invalidations are no longer swalloed by ongoing older ones
- Fixes #6902, the pending prefetch is reset upon invalidation

* fix redirect token logic

* batch synchronous invalidations

* tests

* tweak load cache timing and reduce code a little

* Apply suggestions from code review

Co-authored-by: Rich Harris <[email protected]>

* lint

Co-authored-by: Rich Harris <[email protected]>
Co-authored-by: Rich Harris <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. prefetch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants