View Transitions for Multi-page Apps

By Dave Bitter

4 min read

We finally have (experimental) View Transitions for Multi-page Apps (MPA)! Let’s explore why this is cool and how we can use it.

_View Transitions_ for Multi-page Apps
Authors

Time to look at an, at the time of writing, experimental feature on the web! It might be a bit early to write about it, but View Transitions, proven by this being my third article about them, really excites me!

What are View Transitions again?

The View Transition API is an effort to bring a smoother user experience to the web much like our users are familiar with in native applications. In essence, it lets you animate elements from one view to the next one with ease.

Between “pages”

Consider this transition below:

Screen recording of the demo showing an overview with sneakers and a transition to a detailed view of a pair of sneakers

Before, you had to load the markup for the next page, put it on top of the card, make the animation, make sure to clean up the old view and finally update the URL. Quite a bit of effort for relatively simple transitions. Luckily, the View Transition API makes this incredibly easy.

Read more on how this exactly is done technically in my article The View Transitions API: Enhancing the feel of the web. This, however, only works with client-side navigation in a Single Page App (SPA)

Between “views”

But of course, this doesn’t just apply to transitioning between two “pages”. You can also use this powerful API to transition between two “views” on the page. For example, when adding or deleting an item in a grid:

Screen recording showing an item being added and the grid of cards animate into place

If you want to read more on how this is done, head over to my article Make awesome animated interactions with two lines of code.

So why the excitement for MPAs?

Well, the previous examples rely solely on having client-side JavaScript. If you don’t have an SPA, you don’t get to use it for transitioning pages. We want to be able to transition two completely separate pages, or documents to be precise.

Ease-of-use

Now, you could’ve made something yourself where you intercept the request for a page, fetch the content yourself, update the DOM and make sure that the client-side View Transition is taking care of making an animation. This, just like in the past, requires a lot of effort and introduces a whole new list of potential issues. No, we just want to easily animate between two views, they’re just two documents.

How do I use it?

Making this work for an MPA is fortunately quite similar to the approach for an SPA. If you've followed my previous articles, you'll remember that we used to call document.startViewTransition. However, that is no longer necessary. Now, all you need are the view-transition-name CSS properties as before, plus one additional piece of CSS:

@view-transition {
  navigation: auto;
}

That’s it! Adding this CSS does a couple of things. First, it creates a default "fade" transition between pages. Additionally, it ensures that any elements with the view-transition-name property (along with any other relevant CSS) will behave just as they did when using document.startViewTransition:

Screen recording of the demo showing an overview with sneakers and a transition to a detailed view of a pair of sneakers

Experimental

Yeah, so of course my demo GIF above works really well, but in practice I saw it sometimes not work at all and other times it did. Luckily, this is an enhancement and nothing breaks if it doesn’t transition. I feel like this is because of the experimental state of this API. Do however check it out and try to see if you can make a cool transition. If you want to see all the demo code, you can view the project on GitHub. If you’d like to see the demo in action, head over here. Keep in mind that at the time of writing, only Chrome has experimental support for this and you need to turn the feature flags on:

chrome://flags#view-transition
chrome://flags#view-transition-on-navigation

That’s all! See you next time when I inevitably talk about the View Transitions API again!


Upcoming events

  • Drupal CMS Launch Party

    Zoals sommigen misschien weten wordt op 15 Januari een nieuwe distributie van Drupal gelanceerd. Namelijk Drupal CMS (ook wel bekend als Starshot). Om dit te vieren gaan we op onze campus een klein eventje organiseren. We gaan die dag samen de livestream volgen waarbij het product gelanceerd wordt. De agenda is als volgt: 17u – 18u30: Drupal CMS livestream met taart 18u30 – 19u00: Versteld staan van de functionaliteiten 19u – 20u: Pizza eten en verder versteld staan van de functionaliteiten Laat ons zeker weten of je komt of niet door de invite te accepteren! Tot dan!

    | Coven of Wisdom Herentals

    Go to page for Drupal CMS Launch Party
  • Coven of Wisdom - Herentals - Winter `24 edition

    Worstelen jij en je team met het bouwen van schaalbare digitale ecosystemen of zit je vast in een props hell met React of in een ander framework? Kom naar onze meetup waar ervaren sprekers hun inzichten en ervaringen delen over het bouwen van robuuste en flexibele applicaties. Schrijf je in voor een avond vol kennis, heerlijk eten en een mix van creativiteit en technologie! 🚀 18:00 – 🚪 Deuren open 18:15 – 🍕 Food & drinks 19:00 – 📢 Building a Mature Digital Ecosystem - Maarten Heip 20:00 – 🍹 Kleine pauze 20:15 – 📢 Compound Components: A Better Way to Build React Components - Sead Memic 21:00 – 🙋‍♀️ Drinks 22:00 – 🍻 Tot de volgende keer? Tijdens deze meetup gaan we dieper in op het bouwen van digitale ecosystemen en het creëren van herbruikbare React componenten. Maarten deelt zijn expertise over het ontwikkelen van een volwassen digitale infrastructuur, terwijl Sead je laat zien hoe je 'From Props Hell to Component Heaven' kunt gaan door het gebruik van Compound Components. Ze delen praktische inzichten die je direct kunt toepassen in je eigen projecten. 📍 Waar? Je vindt ons bij iO Herentals - Zavelheide 15, Herentals. Volg bij aankomst de borden 'meetup' vanaf de receptie. 🎫 Schrijf je in! De plaatsen zijn beperkt, dus RSVP is noodzakelijk. Dit helpt ons ook om de juiste hoeveelheid eten en drinken te voorzien - we willen natuurlijk niet dat iemand met een lege maag naar huis gaat! 😋 Over iO Wij zijn iO: een groeiend team van experts die end-to-end-diensten aanbieden voor communicatie en digitale transformatie. We denken groot en werken lokaal. Aan strategie, creatie, content, marketing en technologie. In nauwe samenwerking met onze klanten om hun merken te versterken, hun digitale systemen te verbeteren en hun toekomstbestendige groei veilig te stellen. We helpen klanten niet alleen hun zakelijke doelen te bereiken. Samen verkennen en benutten we de eindeloze mogelijkheden die markten in constante verandering bieden. De springplank voor die visie is talent. Onze campus is onze broedplaats voor innovatie, die een omgeving creëert die talent de ruimte en stimulans geeft die het nodig heeft om te ontkiemen, te ontwikkelen en te floreren. Want werken aan de infinite opportunities van morgen, dat doen we vandaag.

    | Coven of Wisdom Herentals

    Go to page for Coven of Wisdom - Herentals - Winter `24 edition
  • The Test Automation Meetup

    PLEASE RSVP SO THAT WE KNOW HOW MUCH FOOD WE WILL NEED Test automation is a cornerstone of effective software development. It's about creating robust, predictable test suites that enhance quality and reliability. By diving into automation, you're architecting systems that ensure consistency and catch issues early. This expertise not only improves the development process but also broadens your skillset, making you a more versatile team member. Whether you're a developer looking to enhance your testing skills or a QA professional aiming to dive deeper into automation, RSVP for an evening of learning, delicious food, and the fusion of coding and quality assurance! 🚀🚀 18:00 – 🚪 Doors open to the public 18:15 – 🍕 Let’s eat 19:00 – 📢 First round of Talks 19:45 – 🍹 Small break 20:00 – 📢 Second round of Talks 20:45 – 🍻 Drinks 21:00 – 🙋‍♀️ See you next time? First Round of Talks: The Power of Cross-browser Component Testing - Clarke Verdel, SR. Front-end Developer at iO How can you use Component Testing to ensure consistency cross-browser? Overcoming challenges in Visual Regression Testing - Sander van Surksum, Pagespeed | Web Performance Consultant and Sannie Kwakman, Freelance Full-stack Developer How can you overcome the challenges when setting up Visual Regression Testing? Second Round of Talks: Omg who wrote this **** code!? - Erwin Heitzman, SR. Test Automation Engineer at Rabobank How can tests help you and your team? Beyond the Unit Test - Christian Würthner, SR. Android Developer at iO How can you do advanced automated testing for, for instance, biometrics? RSVP now to secure your spot, and let's explore the fascinating world of test automation together!

    | Coven of Wisdom - Amsterdam

    Go to page for The Test Automation Meetup

Share