sveltejs / sveltejs/kit

Cancel stale invalidation requests

Open
#14,358 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

load / layout
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

I have a site where all and every state is "stored" in query params. A search will write to query params while a user is typing. My load function is performing a search based on the query params provided.
Depending on the speed with which the user is typing, requests can pile up which leads to an increasingly long load time untill all requests are answered when im actually only interested in the very last one. Debouncing search input is not an option for me since it would introduce delay in the results as well and im okay with my API being hammered by lots of requests.

Describe the proposed solution

A solution to this Issue would be to cancel all stale invalidation requests instead of leaving them pending until they have finished.
In the load function I would then expect the request.signal to properly report the request being cancled, also in a way where i can propagate this abort signal to any external fetch requests.
This way i would not waste resources on the client and backend.

Alternatives considered

I have considered using pure client side api requests which i can properly cancel using the abort controller.
In this case, this doesnt work well for me since I load initial data via datastream through the load function and changing query params would invalidate the load function as well. Im sure there are ways around it by setting query params without the use of sveltekit, this doesnt seem like a great solution for me though and would rather have it work in a simple way with an abort signal being passed through. I'm open to suggestions fro an alternative though if its not too hacky.

Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing SvelteKit's invalidation and load-request handling, focusing on how request.signal is created and exposed. Done means stale invalidation requests are cancelled, request.signal reports the cancellation, and the signal can be passed to external fetch requests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.