-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
treat invalidation as navigation #6522
Conversation
🦋 Changeset detectedLatest commit: 830c0cb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for kit-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Correct me if I'm wrong but I believe this also closes #6375 |
Yep, you're right — nice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good implementation-wise, therefore approving, but not 100% sure about adding invalidating
to it yet.
I can't think of a good API for this so take with a grain of salt, but IMO the only acceptable way for this to become part of navigation is if it was opt-in somehow. Requiring users to guard against |
|
||
invalidating = null; | ||
force_invalidation = false; | ||
stores.navigating.set(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this result in a wrong navigation
state when the user clicks on a link while the invalidating is in progress?
Would probably only be noticeable on a slow connection.
I agree with @madeleineostoja, so what about something similar to @lukaszpolowczyk's suggestion where beforeNavigate(({ type }) => {
// show loader — now `type` could also be `invalidation`
}, { includeInvalidation: true }); This wouldn't help in the case of the The only other alternative I guess is to have a different pair of lifecycle function specific to invalidation: beforeInvalidate(() => {
// foo bar buzz
});
afterInvalidate(() => {
// foo bar buzz
}); |
I think I like that proposal. It's a little clunky, but much safer at the cost of a little verbosity. I'd name the option something shorter but that's neither here nor there. |
I'm going to close this since the consensus (and I think I agree) seems to be against this solution. |
Update: since #6537 was merged, the only change this PR makes is to treat invalidation is equivalent to navigation for the purposes of
beforeNavigate
,afterNavigate
andnavigating
. Leaving it here until we make a final decision, but there's some valid scepticism about whether this is the right move.Original PR message follows.
closes #6517
closes #4383
closes #6498
closes #6375
possibly #4447 too?
This adds a
type
property to theNavigation
object found in various places:The type is one of the following:
load
— we just got here for the first time.from
isnull
in this caselink
— the user clicked a linkgoto
— the app calledgoto
programmaticallypopstate
— the user hit the back/forward button, or we're traversing the history some other wayinvalidation
— the app calledinvalidate(...)
orinvalidateAll()
. This is a breaking change — invalidations weren't previously treated as navigationsunload
— the page is being unloaded because the user clicked an external link, or submitted a form, or reloaded the page, etc.to
will benull
in this caseIn the
popstate
case, there's an additionaldelta
property, where -1 means navigating back and +1 means navigating forwards (but this can be any non-zero integer).Todo
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0