sveltejs / sveltejs/kit

`beforeInvalidate` and `afterInvalidate` events

Open
#6,375 3 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the problem

I have a progress bar at the top of my site that appears upon every navigation that happens client-side (much like the one in kit.svelte.dev). I'm using the beforeNavigate and afterNavigate events to show and then hide the progress bar.

Occasionally I need to call invalidate() to re-run all the load functions (because the authentication status has changed, for example). I would like to show the same loader when the load functions are re-running as well — because when you think about it, running invalidate() is kind of life refreshing the page.

Describe the proposed solution

It would be nice if SvelteKIt provided two other lifecycle functions called beforeInvalidate and afterInvalidate or something along those lines.

Alternatives considered

No response

Importance

nice to have

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 reading SvelteKit's existing beforeNavigate, afterNavigate, and invalidate lifecycle behavior to understand where the proposed hooks would fit. Define what beforeInvalidate and afterInvalidate should observe and when they should run, then add coverage showing the hooks around invalidation and confirming the intended event order.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.