Skip to content
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

Abort Stale Invalidation Request #5305

Closed
john-michael-murphy opened this issue Jun 28, 2022 · 2 comments · Fixed by #6924
Closed

Abort Stale Invalidation Request #5305

john-michael-murphy opened this issue Jun 28, 2022 · 2 comments · Fixed by #6924
Labels
feature / enhancement New feature or request
Milestone

Comments

@john-michael-murphy
Copy link

john-michael-murphy commented Jun 28, 2022

Describe the problem

Consider the scenario where several invalidate requests to the same dependency are triggered in rapid succession (say because of an updating query parameter, e.g. ?search=foo).

The order in which these requests return from the server is not guaranteed, which means it's possible that the last resolving revalidation will be stale.

Describe the proposed solution

I wonder if we allow an optional abort signal, where AbortSignal implements the canonical Abort API.

function invalidate(
  dependency: string | ((href: string) => boolean)
  options?: { signal?: AbortSignal } 
): Promise<void>;

Alternatives considered

Sveltekit's invalidate function could manage this automatically, but I worry there are scenarios where one might need multiple inflight invalidation requests.

Importance

would make my life easier

Additional Information

As always, thanks so much for all the great work! Sveltekit is such a gamechanger for NYTs!

@Rich-Harris Rich-Harris added this to the 1.0 milestone Jul 20, 2022
@benmccann benmccann added the feature / enhancement New feature or request label Jul 27, 2022
dummdidumm pushed a commit that referenced this issue Sep 1, 2022
Closes #6354.

Related to #6489, #6274 and #5305 

Co-authored-by: Rich Harris <[email protected]>
Co-authored-by: icalvin102 <[email protected]>
Co-authored-by: Immanuel Calvin Herchenbach <[email protected]>
@dummdidumm
Copy link
Member

dummdidumm commented Sep 20, 2022

I think the problem is not a race condition, but that invalidate blocks all other invalidation requests while one invalidation is running, which in this case means getting outdated results. It would probably be better to remove this logic and let invalidates run as they come, and only remove them once navigation has settled. This would also solve multiple inflight invalidations with different values, as the last one wins due to some token check, which means the last request will run with all added up invalidations.

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]>
@Carlos-err406
Copy link

Carlos-err406 commented Oct 29, 2024

hello, im facing this issue, where i have to run several invalidations that can overlap, but im only interested on the last one and i can't find any way to abort the staled invalidations.

any help or workarounds on how to do so, would be very appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants