sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.41k stars 1.88k forks source link

Make easier to use View Transitions with shallow routing #11759

Open hazycora opened 7 months ago

hazycora commented 7 months ago

Describe the problem

sveltekit's onNavigate doesn't run for shallow routing as these aren't truly navigations. This means if you want to use a view transition for a shallow route you need to modify the code wherever pushState/replaceState is ran using the lower level tick function. This is a bit messy.

Describe the proposed solution

maybe onNavigate can optionally support shallow routing as well with an optional boolean property before the callback?

// I want my callback to run for shallow routing
onNavigate(true, async () => {
    // boilerplate view transition code
})
// the default behaviour would still be possible by not providing this argument or by specifying false

Alternatives considered

A separate function, onShallowNavigate or similar.

Importance

nice to have

Additional Information

No response

samal-rasmussen commented 7 months ago

So now we have a bug report and a feature request for basically the same thing: #11759

I made my issue a bug report on beforeNavigate, which is not correct, as clearly shallow routing is not navigation.

But we need a way to be able to react to shallow routing. We now have two use cases:

Also if adding a new interceptor for reacting to shallow routing, it should probably now have navigate in its name. So maybe onShallowRouting or onHistoryChange?