kit icon indicating copy to clipboard operation
kit copied to clipboard

Make easier to use View Transitions with shallow routing

Open hazycora opened this issue 2 years ago • 1 comments

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

hazycora avatar Jan 30 '24 04:01 hazycora

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:

  • Confirmation modal when leaving edited form
  • View transitions

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?

samal-rasmussen avatar Feb 09 '24 05:02 samal-rasmussen