View Transition API just landed in Firefox, which means it’s soon fully ready to be used.
Unfortunately, I haven’t found a good way yet to make use of it with liveview.
There seems to be a hacky way available:
But this wraps way too much code inside the startViewTransition callback, not just the dom mutation. Because of that, There is a big delay between the navigation click and the end of the transition.
I have found that changing it to the code below is a big improvement in responsiveness, but of course that’s very flaky and doesn’t always work:
// Needs `@view-transition { navigation: auto; }` in CSS to work
window.addEventListener("phx:page-loading-start", (event: CustomEvent) => {
if (event.detail?.kind === "initial") {
if (!("startViewTransition" in document)) return;
document.startViewTransition(() => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, 20);
});
});
}
topbar.show(500);
});
Has anyone found a more reliable way?
What would it take to get this officially supported in liveview?
How do other frameworks handle this?
Ideally the callback that wraps the DOM update should also provide enough context such that we could pass different types to the view transition to e.g. have different transitions for forward/backwards.
Also, ideally we should be able to trigger a view transition outside of just page navigation events, like in this example






















