Make View Transition API work with react-router #10276
Replies: 4 comments 2 replies
-
we need this one. |
Beta Was this translation helpful? Give feedback.
-
Similar to how Sveltekit supports view transitions, it would be enough to have a lifecycle function which fires just at the right time. This would then work for all kinds of navigations (without custom links) and can also be ported over to Remix. |
Beta Was this translation helpful? Give feedback.
-
Note that it is unreliable to put document.startViewTransition(async () => {
await oldDomUnmounted;
}); Therefore, a reliable solution for View Transition should be implemented internally in the React Router because the |
Beta Was this translation helpful? Give feedback.
-
Good news! Initial support for View Transitions has been added in #10916 and will be released soon in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What is the new or updated feature that you are suggesting?
With Chrome 111+ comes the new View Transition API enabled in chromium browsers by default. The new feature would be to implement this API in react-router so that any added animation in CSS via
::view-transition-*
would be picked up and executed.Why do we need this feature?
Why view transitions are needed is well explained in this section of the chrome article.
Implementing this with react-router makes it very easy to focus on adding animations for page transitions using a native browser api. Acting / intercepting on navigation events and updating the DOM would then be part of react and react-router.
So as long as the used browser supports the view transition api, react-router would
startViewTransition
on navigation and trigger any transition if implemented in CSS.Advantages:
startViewTransition
would need to be handled by the library, not the animation itself.What is possible now?
As of now, you can already make since possible partly and with some drawbacks.
This rather simple, unaccessible
<CustomLink>
componentstartViewTransition
when there is anonClick
event and then usesnavigate
to the path provided viato
.This works for the case of clicking the
<button>
but is not semantically correct (should be an anchor) and is not working e.g. for browser back buttons.Status Quo on Browser Support and Implementation
Chrome, Edge and Opera already support the View Transition API (see can I use). These two make around 70% of the worldwide browser market share. Firefox is supportive about it. Safari seems supportive about it too.
References
Beta Was this translation helpful? Give feedback.
All reactions