New View Transition Stuff 2025-01-15 In this episode, Jake goes through some of the newer features of the View Transition API, along with some vaguer ideas that are planned for the future.
Resources
Transcript Surma: All right, Jake, amuse me! Jake: Alright, I suppose I'd better do an intro. Hello! Welcome to another episode of OTMT Jake: with me, Jake. We're getting better at that. And thanks to Shopify for letting us do this Surma: And me Surma. Jake: every now and then. Don't want to spoil some of the magic. This is the third episode we're Jake: recording in a row. We normally do two, but you went and, like, split your episode into Jake: two. That's good. I am not going to do that. I really hope I'm not. I don't think I've Surma: Ah, yeah, I milked it. Surma: I guess I should, like, share my thoughts. Jake: got that much content. But yeah, I'm having to sort of bring the happiness, sort of force Jake: the happiness out right now, because I'm actually in quite a bad mood. Because I moved house Jake: about a year ago. And so I've had to have the process of buying furniture. And I bought, Surma: Hmm. Jake: you know, I've got a little kitchen island. Surma: Oh, look at you! You've climbed your way up the social ladder. Surma: You're now a kitchen island owner. Jake: Yeah, that's, that's, I'm doing all right. Surma: That's a kitchen on a separate island in the Bahamas, right? Jake: Yes, that's right. It's a tax haven, the kitchen island. That's why. And that took a lot of doing, Jake: mate. That took a lot of doing. The forms I had to fill in. Yeah, so I had to get some Jake: barstools for the kitchen island. So I bought some. I know, got some gas lift ones, you know, Surma: Ah, the pain. Your struggles in life. Surma: Gas lift? Jake: good. You know, you know what I mean? Like, it's got the little lever and it goes Surma: Oh! Jake: upy downy. Yeah. Surma: Ah, yes. Surma: Oh, I always wanted one that has, like, really a lot of pressure, Jake: So you just eject yourself out. Yeah, that would, that would be good. No, these aren't like that. Surma: so you can catapult yourself onto the couch. Jake: They, they come ready assembled, which is great for me, because I am not. Surma: As in, you don't have to pressurize them yourself? Jake: No, well, I mean, the whole unit, it's, you know, there's like, there's your barstool. Surma: Nice. Jake: It's like, right, that's a barstool. That's a usable barstool. All I need to do now is just Jake: put it into the position, you know, that's it. Like no assembly required, I guess is what I Surma: Nice. Jake: mean. Right. Which is good because it's the kind of thing I'll mess up. And as I was, you know, Jake: taking the second of my barstools downstairs, I discovered that this one was not ready assembled Jake: or not properly readily assembled as the, the bottom half of it detached itself. Jake: And this is the heavy part. This is the part that sits on the ground and keeps the whole thing Jake: balanced. Detached itself and started bouncing down my stairs, laying waste through my house, Surma: Nice. Jake: creating a series of holes in the wall and floor and banisters. Surma: And that's where you regretted building your house made of glass. Jake: It was as soon as, you know, because you know, it's happening because I was carrying the thing Jake: downstairs and all of a sudden it just kind of got lighter. And then there was a thud and I was Jake: like, oh, I know what's happened here. And then as I watched this thing go, bang, bang, bang, bang. Surma: You really, like, you can really observe the misery happening in those moments, can't you? Jake: I wasn't, you know, time slows and it's like, well, there's nothing I could do about that. Jake: Yeah. Yeah. It's kind of like, I'm, God, I'm going to be really sad about this once I have Jake: time to feel feelings rather than just watching it. So, so I am. Yeah. So, you know, there's a Jake: bunch of emails. Well, whatever. Hopefully. Yeah. Yeah. That's right. Yeah. Just put a frame Surma: That's not fun. Surma: Or you could just, like, you know, frame it and call it art. Jake: around it, sign it, date it, sell it. There we go. That's pays for itself. Surma: It's a subtle critique of social dynamics in the modern era. Jake: My odes to this particular furniture company, which I won't name because I don't know, Jake: I might name, I might name them if the compensation process doesn't go through. Jake: But in the meantime, let's assume it's all going to be fine. Surma: So, should we, yeah, talk about, yeah. Jake: Should we talk about the web? Oh no. Oh yeah. The way you went. Surma: You talked so much, can I at least ask the question if we should talk about the web? Surma: Come on, mate. Jake: Well, should we, I mean, should we talk about the web? Should we just do? Surma: Let's talk about the web. Surma: Come on! Jake: All right. Let's all right. Let's talk about the web. Jake: I struggled for a topic. So always in that situation, Jake: stick to what you know, that's, that's what I say. So I'm going to talk about few transitions. Surma: Oh, I thought you were talking about checkered backgrounds. Jake: That's the other thing I know about. But no, this time, this time it's few transitions, Jake: but I wanted to, I want to talk about some of the upcoming features, like the things that have Surma: Yeah. Jake: landed relatively recently. And like the things that are just being talked about that might arrive Jake: at some point. Cause you know, the few transitions have shipped in both Chrome and Safari. They're Jake: they're all hat now, but there's, there's been a bunch of work happening in the background, Jake: I know. And it was a lot quicker than what happened with service workers put it that way. Surma: How proud are you of that, though? Jake: So that's that, that is satisfying. No, it's really, it's actually really nice to see. Surma: That something that you worked on is in Safari? Surma: That doesn't happen. Jake: It's a nice high level feature. So Safari tends to go for that kind of thing, but it's yeah, Surma: Yeah. Jake: it's, it was nice to see in web standard speed. And it's, it's, it's, it's, it's, it's, it's, Jake: it's, it's, it's, it's, it's, it's, it's, it's, it's, it's, it's, it's, it's, it's, it's, it's, Jake: in web standard speed, a fast turnaround on, on that kind of thing. Surma: Yeah, absolutely. Jake: So I guess I'll, you know, a recap, quick recap. What are view transitions? I don't know. Jake: You give a bunch of elements, view transition names in your CSS, you call document dot start Surma: Yeah. Jake: view transition, and that browser captures the current state and everything with a view Jake: transition name is captured separately. Great. It's like little screenshots. Amazing. Jake: Then you change your DOM in whatever way you want to using a framework, not using a framework, Jake: whatever. And then the browser creates an animation from those old states to those new Jake: states. So yes, the, the old states screenshots me, and this isn't good because you can animate Jake: something which isn't there anymore, which is kind of the biggest problem we set out to solve Jake: with this. Cause if you're just changing between like two tabs, it's an accessibility nightmare, Surma: Yeah. Jake: but it's also difficult implementation wise to like keep both views around for a bit while Jake: you're animating from one to the other. So yeah, it solves, solves that problem. Jake: They're just screenshots. There's no accessibility issues. Whereas the new states are live screenshots. Jake: They kind of work like bitmaps, but they're being constantly updated with the actual real DOM. Surma: Oh. Jake: And then, yeah, it's a default animation, which animates the size and position of everything, Jake: which has the same view transition name in both states. And it crossfades from the, the, Surma: Yeah. Jake: the old screenshot to this new view and that can all be customized. And that's, Jake: that's a view transition. But I want to talk about some of the new bits and the features Surma: Lovely. Jake: in development and view transitions. They're a very like visual feature. So what better place Jake: to discuss it than on a podcast? So, you know, use, use your imagination throughout, I suppose. Surma: Yeah. Jake: All right. Entry and exit animation. So this is, this is an old feature, but I think not many Jake: people seem to know about it who I, who I talked to. So you, you've got these like old and new Jake: states, like I mentioned, the old ones are screenshots, the new ones are live screenshots, Jake: and they both exist in this like image pair pseudo element. You can use the only child Jake: pseudo selector, like pseudo class to match states where there is only one of those. Jake: Like, so there's only an old state or there's only a new state. Surma: Okay. Jake: Yes, because you, so you've got, colon, colon, view dash transition dash old. And then you pass Surma: But do you, can you also know which it is? Surma: Ah. Jake: in the, the name of the, you know, the, the one you're targeting, the view transition name. Jake: And then at the end, you just pop on colon only child, which means that there's only a new state Surma: That's nice. Jake: and you can give it different animations in that case, which means you can create like a, Jake: a different entry animation. So yeah, like you could have a sidebar, but you can say, right, Surma: Yeah. Jake: all right, but if the new state of the sidebar is the only child, then I'll slide it in from the Jake: right, you know, assuming that's where the sidebar is. And then that animation would only happen Jake: when it's, it wasn't there in the previous state, it's there in the new state. So you Jake: create an entry animation and you can do the reverse for, for an exit animation. Yay. Surma: Very nice. Jake: So this next one I wanted to talk about, this is not just about view transitions, but it is Surma: Yes. Jake: definitely relevant. So in Safari in particular, this is where I first noticed this. You can do a Jake: some number of fingers on the track pad swipe to go back and forward between pages. Have you Jake: seen this? I always turn this feature off. Yes. Well, some people don't. And it also, Surma: Yes. Surma: I was just going to say, I turn it off immediately. Jake: and it also happens on iOS as well. Jake: Oh, Surma: Sitting next to someone working on a laptop, and he asked, Surma: a mate of mine, and he asked for help, Surma: and he had his touchpad on the non-inverted scrolling, Surma: you know, like the scrolling from the 2000s, Surma: where you scroll, you move your fingers up, Surma: you scroll up. Jake: every now and then I'll encounter a device, which doesn't have the option to do it the new way. Jake: Cause I got used to the new way so quickly. I know a lot of people didn't last place. I Surma: Yeah. Jake: encountered it actually on an Android tablet. I was trying to see how far I could get with Jake: an Android tablet as a developer machine. Um, and you can connect to a keyboard, Jake: you can connect to mouse, but that was one of the things that the mouse used the Jake: wrong direction, scrolling the old direction, scrolling, and there was no option to change it. Jake: I was like, well, no, I can't, can't possibly use this. Yeah, absolutely. Surma: It's a red flag for a psychopath, isn't it? Surma: Okay, well, back to view transitions. Jake: Yes. So in Safari on both iOS and desktop, and, you know, I think other browsers do this as well Jake: is as you are doing the drag gesture to go back, it gives you a preview of the previous, Surma: Yeah. Jake: of the state you're going back to like a screenshot. But the bad news is Safari, Surma: Yes. Surma: Yes, yes, yes. Jake: the browsers, they do this even for same document transitions. Surma: Which is annoying if you have your own animation implemented. Jake: Now you're onto something. Exactly. And in fact, Safari does it even for just like Jake: you click on a link with a hash, you know, it's going to a different scroll position. Surma: Yes. Jake: Like they do it for this as well. So yeah, exactly what happened. And the thing you see Surma: Yes. Surma: Yes. Jake: when you drag across, it's like a screenshot taken just before the navigation. So you're Surma: Yes. Jake: looking at your new state, you start dragging to go back to the old state, you see the old state Jake: and you drag all the way across and you let go. And then that just does the navigation. Surma: Yes. Surma: Yes. Jake: It snaps back to the new state and does a lovely little Jake: web page transition into the old state. And it looks awful. Surma: Yes. Surma: I mean, it seems easy to fix from Safari's point, if there is view transitions. Surma: Don't do it. Jake: Well, so this has been a problem before view transitions, right? Like this, any kind of state Surma: Ah, true, yeah, any custom, yeah, okay. Jake: change. Yeah. So the fix here is a property has UA visual transition, which will appear on Jake: navigation event objects and pop state event objects. And it's basically telling you, Surma: Ah. Jake: look, the browser's already done it for you. So you might not want to do your own. Surma: Oh, so my ability to implement navigations is being taken away from me, Surma: rather than me signaling to the browser, saying, I got this, let me do it. Jake: Exactly. Yeah. Well, yeah, maybe I do. Yeah, I do hope in future that would do as a way to say, Surma: That seems the wrong way around. Surma: And... Jake: look, no, I would actually like to do my own transition if you don't mind. But that's not Jake: the way it is now. But at least you can avoid the double transition. Jake: Yes. Yes. Yeah. Same. But hey, that's in Safari 18 and Chrome 118. So lucky, lucky you. But yes, Surma: Yes, it definitely is a solution to give a better user experience. Surma: As a developer, I'm a bit miffed. Jake: it does. It does solve a real problem. But yes, I hope it's not. Yeah. We've got transitions now. Surma: Woo! Jake: Can I use them? No. Browsers have got their own now. So it's pointless. Okay. Jake: Never mind. Fair enough. But yes, there is a solution to that small problem. Jake: Next thing. All right. View transition class. Okay. So each view transition name on the page Surma: Uh-huh. Jake: needs to be unique. All the elements that are involved in the transition, it needs to have a Surma: Yes. Jake: unique name, because this is how the browser determines that the old thing is the same as Jake: the new thing. And it just does that because they have the same name. So if there's two things, Surma: Yes. Jake: it's like, well, no, which is it? So that doesn't work. But it means that when you're defining your Surma: Yes. Jake: animation, like you might have a group of cards and you give them view transition name card one, Surma: Yes. Jake: card two, card three, or whatever. But that means in your animation, you have to say, Surma: Yes. Jake: okay, I want card one to animate like this. I want card two to animate like this. I want Surma: Yes. Jake: card three to animate like this. When usually they all animate the same. Like it's the same CSS Jake: to make that animation work. That's where view transition class comes in. So you can give Surma: Uh-huh. Jake: everything a unique name, but then you can give them all the same class, which means that whereas Jake: that you would do colon, colon, view transition group, and then give it a name. Instead, you can Jake: give it dots and the class name that you've given it. And this is not the same as the class name of Surma: Right. Jake: the element. This is that view transition class and you assign it that way. So they're similar Surma: Yes. Jake: to classes in HTML, but they're at a CSS level, but do roughly the same job. Surma: Can I combine that with, like, Jake: Yeah. Yeah. So interestingly, you, in a basic card reordering thing, Surma: nth child? Surma: You know, if I have, like, a list of cards Surma: and I want every second one to go to the left and every... Surma: The odd ones to the left, the even ones to the right, Surma: that would work with this? Surma: Brilliant. Jake: if you do your, like, okay, even cards do this, odd cards do that. You open yourself up to the Surma: Yeah. Jake: problem of like, well, what if the class names are different in the new state to the old state, Jake: which is fun, but the solution there is the new state class names win. Surma: Yeah. Jake: That's it. So, which is actually interesting because if you want it to do your odd and even Jake: thing, it's like, well, do you want it to be odd and even from the end state or from the new state, Jake: which is kind of fun, but yeah, it's all, it's all, it's all a solvable problem, but yes, you Jake: can use nth child. Just, just be aware that it's going to be nth child from the new state rather Surma: Yes, that's definitely important to keep in mind. Jake: than the old state. Yeah. And that was in Chrome 1.2.5 and Safari 18.2. Like, so soon, not, not Jake: out yet, but soon ish. That's cool. Yeah. Now here's a feature that I'm mentioning this for Jake: completeness really, because I think it's a, I don't know. I don't know how much I care about Surma: Wow, you got me excited. Jake: this one. Hey, I'm not DevRel for it anymore. I don't have to. It's great. I could be entirely Surma: You got me excited. Surma: This... Jake: honest. That was always entirely honest, I think. Right. It's common for view transitions to be Jake: different depending on where you're coming from and where you're going to. And they, you know, Jake: so, so from your article page to your homepage might be a different transition than from a Jake: article page to an article page. Sure. And also if it's a back button, you might have animations Surma: That makes sense. Surma: Yeah. Jake: that are different from if it's not back, you know, if it's a forward or a link click or whatever. Jake: The way I've always solved this is just by putting a class on the HTML element dynamically, Surma: Yeah. Jake: and then I can give different things, view transition names. I can give, you know, Jake: different animations to the groups and the old, the new states, all of that sort of stuff. Jake: And then just when the animation is complete, I remove that class. Yay. But there's a feature to Jake: kind of do that for you. So when you call start view transition, you can pass in types, Surma: Yeah. Jake: which are similar to classes. We keep running out of names for just like words you give us Jake: that come out at the other end of the API somewhere. And types, it just means you, Jake: you get a selector. I think it's like view transition, active view transition type. Jake: And you can use that as a pseudo class to hang the rest of your styles off. Surma: Oh, okay. Jake: You know, to say, right, oh, if it's this type of transition, then I want, you know, Surma: Yeah. Jake: capture these different elements and animate it in this different way. Jake: And I guess the nice thing about it is it removes that pseudo class for you Jake: once the transition is complete. Surma: I mean, these are always the things that I feel like Surma: when you build them yourselves, Surma: there is a weird code branch Surma: where then the class doesn't get removed Surma: and then everything gets in a jumble, Surma: so having this, like, baked in, done right, Surma: is really valuable. Jake: Yeah. And I do think actually there's a, if you're doing the class name thing yourself, Surma: Ah, yeah. Jake: I do think there's a race condition if another view transition comes in, Surma: Ah, yeah. Jake: before the other one ends. And I think the timing that you get to remove the class name is too late. Jake: So yeah, the types thing is like, I would definitely use the types thing Jake: now instead of the class name thing. But whatever. Surma: The amount of times I've had weird animations Surma: because if you press the back button twice Surma: just slowly enough that the first animation has started Surma: but not quick enough that... Surma: So slow that it has also fully ended Jake: Exactly. Surma: and then you have, like, two overlapping animations Surma: and, like, it's... Surma: You have to implement a whole state machine and everything Surma: and, yeah, it is such a convenient thing Surma: to not have to do yourself anymore. Jake: Yes, I agree. So yeah, small benefit, but it is a nice little, nice little feature. And that was Jake: that was Safari one, Safari technical preview that's in. So well, I was about, I got my words Surma: Safari 1? Surma: Safari 1. Jake: mixed up. It's like Chrome 1.2.5 and Safari technical preview. But yeah, so coming soon Jake: to Safari, but it's already shipped in Chrome. All right. This next one, this next one's a big Jake: one. I think Chrome 1.2.6, this landed in Safari 18.2, which is the next version that is cross Jake: document view transitions. So like, you know, you can do view transitions without JavaScript. Surma: Oh. Jake: We've wanted that, right? Surma: Yeah! Surma: So this is, like, non-spa, almost. Jake: Exactly. Yeah, you can do it like with entirely without JavaScript view transitions. The way it Surma: It's just, like, literally static sites I can... Surma: Eleventy! Surma: My Eleventy blog. Jake: works is both pages needs to be same origin right now. There might be ways of making it same sites, Jake: but they're not there yet. But yeah, two pages of the same origin. They both opt in via CSS rule. Jake: It's at view transition. And it's a, it's a block. And in there you put navigation call on auto. Surma: Oh, I thought you put yes. Surma: Yes, please. Surma: And that's the opt-in. Jake: Yes, please. That's happened before in the web platform, Jake: like autocomplete the autocomplete attributes accepts the values. Yes. And no, Surma: Not true, false! Surma: But yes. Jake: no, not true false. No, no, no. Because true false. And that's, oh, it's beautiful, Jake: isn't it? Because in the world of ARIA, you have ARIA visible, which is, yeah, ARIA hidden, Surma: Yes. Jake: actually it's ARIA hidden, which is set to true or false the string true or false, Jake: because it's an attribute. And then you've got like disabled or you've got the hidden attributes Surma: Mm-hm. Jake: in HTML, which is doesn't matter what the string value is. If you do hidden equals false, Jake: it gets hidden because it's the thing exists. So it's there. And then you've got autocomplete Jake: with yes, no values, which is, ah, yes, beautiful. What a beautiful platform we have. Jake: What a beautiful platform we have. I mean, I can kind of, the reason autocomplete did that is Surma: It is. Surma: Wonderful. Jake: because it's a truthy default, which you can't express with a Boolean attribute. Anyway, this Jake: is a tangent. Cross-document view transitions. That's what everyone wants to hear about. Jake: So yes, so you've got the navigation auto, and that means like on navigations that were Jake: started within the page. So like link clicks, form submissions, and then also like JavaScript Surma: I... Surma: I'm... Surma: I'm not sure what you're saying. Jake: triggered navigations will be a candidate for a view transition, but also back and forward button. Surma: I'm not sure what you're saying. Surma: I'm not sure what you're saying. Surma: What are you saying? Jake: Ah, the things which aren't included is the reload button and URL modification, Jake: like URL bar stuff, even if it lands same origin. Surma: That is genuinely exciting to me. Surma: Like, that's actually something where I Surma: may sit down and throw it at my blog just for the lols Surma: because it's also, like... Surma: It's one of... Surma: Such a classic case of progressive enhancement Surma: because, you know, if a browser doesn't understand it Surma: everything stays as it is. Jake: Exactly. Surma: Happy days. Jake: Yeah, absolutely. Yeah, it's on my to-do list. Add it to my blog. I started working on it on Surma: But if the browser does support it Surma: look at my spinning page while you navigate. Jake: a flight and then ran out of time and then never picked it up again, like so many little hack Jake: projects. But yes, it's something I really want to do. So there's a rule that your navigation Jake: has to be fast, and that means four seconds in Chrome. Surma: 4 seconds is a lot of spinning, mate. Jake: Exactly. Oh, no, your transition can be as slow as you want, I think, but it means that the new Surma: Oh. Jake: document needs to be there within four seconds. Surma: There, as in loaded. Surma: It doesn't... Jake: Ready, ready to transition, which doesn't have to be too long. Surma: Not transition... Surma: Right. Surma: 4 seconds seems lenient? Surma: What I... Surma: Oh, does that mean, like, Surma: I am on, like, 2G airplane WiFi Surma: that the transition will obviously not start Surma: until the document is ready? Jake: Well, so here's the thing. So when it comes to this, it doesn't prevent streaming. So you're... Surma: But if it doesn't get ready Surma: until 4 seconds Surma: then it goes to good old streaming in? Surma: No, but you wouldn't see it if you have a transition. Surma: Right? Jake: Ah, yeah, you could, because the new state is all like live, right? It's not just a screenshot. Jake: So your new state could be sort of rendering in, Jake: particularly things like images, which could be loading in. Surma: I assumed that Surma: I would obviously keep the new content Surma: off... Surma: Wait. Surma: The transition starts before the new document is ready? Surma: In a cross-document transition? Jake: Well, define ready is really the... Okay, good definition, actually. Well done. Surma: Dom ready. Surma: There's an event for that! Jake: So there is an event for that. So no, it's not. So a couple of other features have arrived. Jake: So you can do link rel equals expect, and then you can href for a local element. Surma: ... Jake: So like, you know, hash, whatever, to point to an element. Surma: Like a sentinel that... Jake: Yeah, sure. Surma: As you mark as Surma: this is my marker for Surma: I'm ready? Surma: Oh, so this would basically allow you to be like Surma: I need to go until here Surma: to know that my above the fold Surma: is fully renderable. Jake: Yeah, exactly, exactly. Yeah, like my main content area or something like that. Surma: Clever! Surma: ... Jake: And yes, and then, so in that tag, you also have blocking equals render. Surma: Did you say that's a link tag? Jake: Yes. Oh, that's a good question. I don't know for sure. It would have to be discovered. Surma: Does it have to be in the head? Surma: Because one thing that's always difficult with frameworks Surma: is... Surma: head stuff. Surma: Not... Surma: It's solvable, but, you know, Surma: just thinking out loud. Jake: I guess in the body element, you're running race conditions, right? Jake: Like, so there's a possibility that tag is not discovered by the time it Surma: ... Jake: knows it needs to wait for it. You know what I mean? Jake: Like, if you put that at the bottom of your document, you run a high risk of it not being... Jake: It's kind of pointless, isn't it? Because you would then Jake: need another tag to tell it to wait for that tag. Surma: No, no, no, I think Surma: of course I would put it as high up as possible, Surma: but, you know, if you run like your Surma: your good old DIY Jake: Yes. It's interesting. I don't... I mean, my guess would be by default, it's a race condition in the body. Surma: static side generator that uses Surma: Preact, it's a lot easier to put something in the body Surma: than it is to put in the head. Surma: ... Jake: I don't know if they've put in some code to say, like, once the head is passed, then that's it. Jake: I don't know which of those it is. It will be one of those, though, I bet. Jake: But yes, but you can also use blocking equals render on scripts and on style sheets as well. Surma: Nice! Jake: Yeah. I mean, blocking render is a risky thing for performance, but like you say, Jake: sometimes it is key to a transition to wait for a particular element to be there or Surma: ... Jake: wait for a particular script to have loaded or something like that. Jake: So that's possible. And you also get, like, you get a page swap event Jake: on the old page just before it goes away and a page reveal event on the new page just as it arrives. Surma: Hmm... Jake: Because we already have page hide and page show, but they run at the wrong time. Jake: So they had to make their own new events. Page show in particular. Jake: Yeah. When do you think page show fires? Take a guess. Surma: Is this from the page lifecycle API? Jake: Yes. These page hide and page show came in around bfcache. Surma: Or is it even from before that? Surma: So page height, page show Jake: Yeah. Yes, exactly. Surma: is separate from visibility, right? Surma: Like just because a window is Surma: in the background or something Surma: probably does not file. Surma: ... Jake: Yeah. Page hide and page show is like you've navigated away from this. Surma: Is it like when the document is actually Surma: about to be evicted from memory? Surma: Like so long off the screen Surma: but maybe still kept alive? Jake: Oh, no. Do we have an event for that? I can't remember if we did in the end. Surma: I wonder if that would be probably lifecycle API. Jake: I don't think we did. Yeah, it's lifecycle. Surma: Where you're like, oh, you now need to like Surma: store some of your stuff in local storage Surma: if you want to keep it around or something. Jake: The big issue here is the page show event, which like with bfcache, it fires at roughly the right Surma: ... Jake: time. So, you know, you click back and it brings the page out of bfcache. Jake: The page show event fires. Everyone's happy. Jake: If you do a forward navigation and it's not bfcache, it has to load it from the network. Jake: Page show fires along with the onload event of the window. Jake: So that's all images have loaded, Jake: which I would argue the page has been showing for some time before that. Surma: Oh yeah. Jake: So, yeah. Oh, ages ago. Surma: Yeah, DomReady would have arguably been better. Jake: Oh, yeah. Dom ready would have been. Well, but still, you know, just tell me when it's shown. Surma: Still not ideal, but better. Jake: Yeah. Yeah. I would say once the old page is not showing anymore and the new one is Jake: has got a realm, you know, I guess there's always that issue of, well, it can't just be when it's Jake: got a realm because there needs to be enough JavaScript running for you to be able to listen Jake: to the event. Oh, you have to call start to get it. Surma: Unless you introduce something like Surma: I guess you can't, you know, with postMessage Surma: you can, there's actually like an implicit queue Surma: until an event listener is registered. Surma: Yeah. Jake: So the way it works is it's just before the first render is this new page reveal event. Surma: Right. Jake: Page swap is just before the last render. Jake: And that next render will be the final render of that page. Jake: And so this is where you can customise the transition with JavaScript. Surma: When you say just before the first render Jake: So you can like. Surma: like enough for me to like still Surma: muck about with positioning and Jake: Yep, that's exactly what it's for. Surma: nice. So before the first layout. Jake: And it's before the new state is captured in terms of the view transition. Surma: Brilliant. Jake: So you can use that time to go and add view transition name Jake: to particular things to set up your view transition types. Jake: And you get information about the navigation. Jake: You get the previous navigation object and the current one. Jake: So you can go, oh, this was a navigation. Jake: This was a transition from my article page to my home page. Surma: ... Jake: So I'll do something in particular different because of that. Jake: So that's all there for you. Jake: So yeah, that's cross document view transitions. Jake: And yes, there is a question of can we do same site at some point, Jake: which would be useful for going from your thing.com to profile.thing.com or whatever. Surma: But I guess cross-origin is out of the question? Jake: Entirely cross-site would be out of the question, I think. Surma: ... Jake: Or at the very least, it would be a very like a cut down version Jake: because you don't want it to be an avenue for sites to be sending data to each other. Surma: I wonder if, you know, if you could opt in via course Surma: or something, you know, if I say like Surma: hey, I'm cool to be transitioned in by Jake: It's been a while since I've paged this into my brain, Surma: domainlol.com Jake: but that opting in is fine. Jake: And that's what would have to happen even for the same site cases. Jake: I think the worry is where it's not the sites agreeing to it. Surma: ... Jake: That's the problem. Jake: It's the user agreeing to it. Jake: That's the problem. Jake: So it's the privacy issue rather than security issue. Surma: Oh, you can make things look, yeah, okay. Jake: Yeah, it's about transferring data from about the user. Surma: Yeah, maybe. Jake: They keep trying to shut down all of these avenues of having sites Surma: ... Jake: communicate that sort of stuff. Jake: And so it's just not wanting to introduce a new one of those. Surma: Hmm. Yes, yes, yes. Jake: All right. Jake: So far, it's all been stuff that's actually shipped in Chrome, at least. Jake: And it's in development in Safari, aside from the cross-origin stuff. Jake: But I wanted to talk, I had a little look around the CSS working group Jake: and about stuff that's kind of being worked on, Surma: ... Jake: but hasn't kind of got to a full release yet. Jake: I'm going to start talking about things that have been developed the most Jake: through to things that have been developed the least, I think. Jake: So the one that is actually, Jake: I see an experimental implementation of this in Chrome. Jake: It's nested view transitions. Surma: Oh lord. Jake: When you have a view transition, you've given all of the things, Jake: your view transition name, and that creates these view transition groups. Jake: Those view transition groups are all siblings of each other. Surma: ... Jake: So although your DOM is like a complex tree, the transition is flat. Surma: Uh-huh. Jake: And that's pretty useful because it means you can, like, Jake: animate something going from one container Jake: or appearing to go from one container to another, Jake: even though the container is like overflow hidden or whatever. Jake: So that flat tree is pretty good because it's just not a problem anymore. Jake: It's entirely flat. Jake: But sometimes you don't want that. Jake: You want your transitioning thing to be inside another thing, Surma: ... Jake: which is transitioning. Jake: And so, and particularly when you have clipping involved, Jake: or that you want the thing to be transitioning up and down, Jake: but the outside thing is rotating or something like that. Jake: And doing that is too... Surma: Oh, so you want to like maintain Surma: like the relative positioning Surma: between elements sometimes, because by default Surma: currently that's all gone. Jake: Exactly. Jake: Exactly. Surma: ... Jake: Yes. Jake: So that's the feature. Jake: So it's basically, you have view-transition-group. Surma: ... Jake: In the same place, you would do view-transition-name. Jake: And you give it the name of another... Jake: Your container would have view-transition-name-container. Jake: And the thing inside it would have view-transition-group-container. Jake: And then it knows, ah, okay. Jake: So this view transition group is going to go inside that other view transition group. Surma: Gotcha. Surma: It's about position and scale then, right? Surma: Like if I scale up the container Jake: Yeah. Surma: all the children get scaled up, if I spin Surma: the container all the children inside Surma: get the same thing, but if I move the children Surma: they, yeah, do their movement but Surma: with the group parent, the container Surma: being the origin rather than the page. Jake: Yeah. Jake: So imagine you've got a container which has a list of items within it. Jake: Those items are reordering themselves Jake: while the container moves from one side of the screen to the other. Surma: Okay, cool. Jake: Yeah. Jake: So that grouping would help there, Jake: especially if you've got a particular easing on the outer container. Surma: ... Jake: You don't want to have to then add that into all of the children elements, Jake: but you would only... Jake: Especially if the container has a very particular easing curve, Jake: whereas you want the things inside it to have a different easing curve. Jake: That becomes really difficult to do in the current model. Surma: And I can nest that Surma: multiple levels. Jake: Yes, you can. Surma: So basically edit with a view transition Surma: by default, all the hierarchy Jake: Yeah. Surma: you know from DOM is gone Surma: because you just basically have some Surma: free floating screenshots Jake: Exactly. Surma: and this kind of lets you rebuild a new Surma: hierarchy which can be completely Surma: independent from the DOM hierarchy. Jake: Exactly. Jake: And then you can give the outer view transition group overflow-clip to regain some clipping. Surma: Ah, yeah, that's very powerful. Jake: That's powerful. Jake: So yeah, I'm looking forward to that. Jake: There's definitely times I've not been able to use view transitions Jake: because that feature was missing. Jake: And then there's a series of little feature ideas for... Jake: So I mentioned before that if you're reordering a group of cards or something, Surma: ... Jake: you have to give each one a view transition in card one, view transition in card two. Jake: I mean, you probably wouldn't give them card one, card two. Jake: You would give them some form of ID which represents the data that's in that card Jake: because it's not positional. Jake: You care about it because you can reorder the position, Jake: but you care about it in terms of the content that's in it. Jake: Very much like key when you're doing key in React, right? Jake: So you're keying each element. Jake: But what folks are looking at is, Surma: ... Jake: is there a way we can do it without having to name each element manually? Jake: And so there's a few different proposals around this. Jake: One is, well, no, view transition name match-element is one. Surma: Is this the return of XPath? Jake: And this says element identity defines what's the same before and after. Surma: Identity as in ID? Jake: No, as in equals, equals, equals. Surma: Oh, wait, but how Surma: how would that work? Jake: Well, cross document, it doesn't. Surma: Ah, for spa it does though. Surma: I get you. Jake: Yes. Surma: If you take good care of your react Surma: elements, then yes, this could work Surma: very well. Jake: You've hit upon one of the things that I worry about with this feature. Jake: It seems to me that the CSS working group are very excited about this because it just works. Jake: And what I've been trying to tell them is it just doesn't. Jake: Like, I mean, they understand that it doesn't work cross document, right? Surma: ... Jake: No one's under that illusion. Surma: Yeah. Jake: But view transitions right now are page transitions Jake: because they are scoped to the whole document. Jake: That might not always be true. Jake: We'll talk about that in a minute. Jake: But it's scoped to the whole document. Jake: You can only have one view transition happening at once. Jake: And yeah, the document is the scope. Jake: So they're page transitions. Jake: When I built my simple demos of view transitions, I hooked into the navigation API, Jake: which tells me when something's trying to do a navigation. Jake: I canceled the default. Surma: ... Jake: And I went and got, I did a fetch request to the page, the target page, if it was same origin. Jake: And I got the HTML and I blatted it onto the page using innerHTML. Surma: Yeah. Jake: And that means match-element would not work for me in that case. Surma: No, exactly. Jake: Because even though my heading in this particular example, Jake: or my sidebar, was being recreated from scratch, Jake: even if it was visually identical, it's a new element. Jake: So match-element would not work for me. Jake: And then if I was using something like React, Surma: ... Jake: then there is a greater chance that match-element would work. Jake: But I don't think most people know when it would work and when it wouldn't. Jake: Because it's all the dipping algorithm, right? Jake: It's an optimization, whether it reuses the element or whether it doesn't. Jake: You get some control over it with the key prop. Jake: But, you know, sometimes it will seem from the outside that React has decided, Jake: no, I'm just going to recreate that element. Jake: Because it's not in one of those situations where I can reuse it. Surma: Yeah, and with frameworks you could Surma: even be in a world where in Surma: the current release it happens Surma: to work on the next release. Surma: They have decided to like do Surma: like buffer swapping almost like Surma: element swapping where they prepare the next Jake: Yes. Surma: elements that is replacing Surma: the old element and they look the same. Surma: They do the same, but they're not the same Surma: in terms of referential equality. Surma: It seems Surma: it seems like a bit like a foot gun. Surma: Yeah, it's it's it feels a bit like Surma: it looks like it's going to be on paper, but it doesn't Surma: hold up in reality unless you hand craft Surma: both your DOM and your animations. Jake: Yeah, so the original proposal was just to call this auto. Jake: And I'm glad they haven't. Jake: Because, again, I agree with you. Jake: And I have used the word foot gun in the CSS working group multiple times Jake: trying to tell them that this is not a silver bullet, right? Jake: This is not the solution to all problems. Surma: Yeah. Jake: And I think they've been swayed by a lot of CodePen demos Jake: of, like, rearranging a group of cards, like, you know, randomizing a list. Surma: ... Jake: And it's like, oh, I just want to, you know, I just wanted to figure it out. Jake: And it's like, yeah, it does work in that case. Jake: But I don't think it scales to actual use cases. Jake: Those demos of reordering cards, I don't think they work in production Jake: as well as people think. Jake: And I know this because at Shopify, we couldn't make it work. Surma: Yeah. Jake: And so the reason we couldn't make it work is, you know, we got so far with it. Surma: ... Jake: We had, like, an interface where it was, like, a filtering. Jake: And it would reorder, like, a list. Jake: But the box that controlled the filtering slightly overlapped the list, Jake: which meant it's like, okay, so now that box that controls the filtering, Jake: we need to give that a view transition name Jake: so it can sit on top of the things moving around in the list. Surma: Yeah, it has to be its own screenshot. Jake: Has to be its own screenshot. Jake: And then, right, okay, we solved that. Jake: But then the fact that that is not interactive during the animation Surma: ... Jake: became really apparent and became a bug. Jake: So what we really wanted was scoped view transitions. Jake: Like, we really want a way to say, Jake: I want a view transition that is limited to this element on the page Surma: Yeah. Jake: rather than being for the whole document. Jake: And then you can just have your little, you know, Jake: your sorting, filtering UI overlaying all over the top just fine. Jake: Why not? Jake: Because the view transition is limited to the list. Surma: It sounds a bit like the first step is being Surma: taken with a nested view transition almost right Surma: like it's a similar pattern. Jake: Ah, well, the nested one is more about, like, Jake: the grouping of the pseudo element groups, Jake: whereas this is taking that whole tree Jake: and putting it onto an element rather than on the HTML element. Jake: No, but those two features would work together, for sure. Surma: Yeah. Jake: And then in that case, I think match element becomes more interesting. Jake: But again, it's still a bit of a bit of a foot gun. Jake: I feel it's something people will go, oh, this will be handy. Surma: ... Jake: And then they'll use it and then find that, Jake: like, their animation only kind of works sometimes. Jake: And then fall back to using view transition name because that's the reliable one. Surma: Here's maybe a curveball Surma: for the view transition Surma: name where Surma: I give a DOM element a name. Surma: Can I use the Surma: attribute function? Jake: Yes. Jake: Now, here, if I've got, you're good at this. Jake: This is the next thing I wanted to talk about. Jake: So this is something else they're looking at, Jake: is being able to use the attribute function. Jake: So you can bring an ID or a whatever. Surma: ... Surma: Well, the thing is Surma: we are talking about handcrafted DOM. Jake: So you can bring an ID or a whatever. Surma: This will probably work fine. Surma: But in framework land Surma: the problem is you're not necessarily controlling Surma: the DOM creation and modification. Surma: But whenever you render lists Surma: in most frameworks, you often do set Surma: a key property so that the framework Surma: knows which Surma: elements correspond to each other. Jake: But that doesn't fall down to a attribute. Surma: No, but you could. Jake: I would say it's like, well, you just do an inline style Jake: and give it a view transition name. Surma: ... Jake: This is another feature where I'm like, cool. Jake: I'm glad you'll be able to do this. Jake: But I do not think it's as useful as people think it's going to be. Surma: Well, at least it's a half decent Surma: escape hatch I feel like Surma: because if I take Surma: infinite scroller Surma: off the shelf components Surma: right, and I do not Jake: Yeah. Surma: exactly control Surma: how these individual items Surma: are rendered to the DOM Surma: but it turns out there is Surma: maybe a data attribute on them. Jake: Yes. Surma: Then being able to do Surma: use the attribute function to Jake: I like that. Surma: link to that data attribute Surma: seems useful. Jake: Yes. Jake: And I think exactly what you said is the right way I would go about it. Jake: So it's by having a special data attribute to control this Jake: or some other attribute on a custom element, whatever. Jake: The thing that's being thrown around the CSS working group is using the ID attribute. Surma: ... Jake: So specifically, the idea that's coming from a couple of folks in the group Jake: is that view transition name auto will use the ID attribute if it's there. Jake: Otherwise, it will fall back to match element. Surma: But that's not how IDs are used. Surma: Right? Like if I go from Surma: one view to the next and I have Jake: So Surma: my list of albums Surma: and I click an album and on the next page Surma: it's about the album Surma: the ID on one Surma: would be big as important main album Surma: cover and the other one is a list item Surma: I probably wouldn't even have an ID. Jake: yeah, for that particular case, it doesn't work at all. Jake: But for things like header and sidebar, it might. Jake: I mean, I don't think people use IDs that all that often anymore. Surma: Yeah... Jake: But it is a reasonable way to say, right, if two things have the same ID, Jake: it's fair. Jake: You have a reasonable confidence of saying they're the same. Surma: I mean Surma: that's true. Like if they have the same ID Surma: they probably have the same Surma: identity. That's true. Surma: I feel like, why limit it to ID? Surma: With the attribute function Jake: Yes, indeed. Surma: I could say ID or anything else. Jake: What I don't like about this proposal, I think my biggest issue with it is Jake: it means like view transition name auto. Jake: It's like, oh, that's just going to do it all for me. Jake: I'll use that. Jake: But it's mixing in this match element behavior, Jake: which we've already decided between the two of us is a foot gun. Surma: Yeah... Jake: But you don't know that's what you're getting, Jake: because it's kind of just hidden behind the word auto. Jake: And also, one pattern we see on like big websites is this pattern where Surma: ... Jake: you click on a thing, and it will do an SPA navigation, Jake: unless it knows that there's an update to the site, Jake: in which case it will do a full navigation to pick up the new version of the site, Jake: kind of almost in secret. Jake: It's a nice little thing where it doesn't have to show you, Jake: by the way, there's an update available, press here. Jake: It just kind of gives you the update automatically. Surma: Hmm... Jake: And it's nice that you can have view transitions in your same document, Jake: but then you could have the same view transition cross document in that case. Surma: ... Jake: But this means if you're using auto and you test it, Jake: it seems to work because, I don't know, Jake: the ID is pretty good and the match element's working well. Jake: In that cross document case, it's going to all fall down Jake: because match element isn't going to work. Jake: It's going to seem to kind of work Jake: because your things with IDs are going to work, Jake: but the rest is all going to behave weirdly. Jake: And it's going to be like, oh, that half worked. Jake: Great. That's the worst kind of debugging, right? Surma: ... Jake: Now to find out which things didn't work properly and which ones did. Jake: Yeah, it seems like a foot gun to me. Jake: So I don't like that. Jake: I like that match element exists, Jake: and I like that I could get the thing from an attribute. Jake: I don't know how often I would use those features personally. Jake: Maybe with scoped view transitions, match element a bit more, Jake: but we're nowhere near that yet. Jake: It's just a kind of, you know, sketch right now. Jake: So I'm hoping we can block this like auto thing. Surma: ... Jake: Otherwise, you know, we're going to have, Jake: I think we'll end up writing documentation saying, Jake: hey, if you transition name auto is a thing, don't use it. Jake: It's rubbish. It's rubbish and confusing, Surma: ... Jake: which would be sad, but there you go. Surma: ... Surma: Yeah, I hope that if that is Surma: you know, if it's not just Surma: you, but it's not because I tend to agree Surma: so it's at least the two of us Surma: if there's some more people who agree Surma: with that sentiment then maybe the Surma: working group Surma: might cause correct. That'd be the hope. Surma: It would be really sad to see something Surma: launch that is a foot gun. Jake: It would be sad to see something launch that's a foot gun. Jake: But unfortunately, I'm adding this note in after we recorded Jake: to let you know that Safari in Safari 18.2 just went ahead Jake: and shipped view transition name auto, Jake: even though it was being actively disputed in the CSS working group. Jake: It's not great, but it is something that happened. Surma: ... Surma: ... Jake: Happy days. Jake: Anyway, back to the episode. Surma: ... Surma: ... Jake: I was looking around at other auto values in CSS, Surma: ... Jake: and I think some of them like image height auto Surma: ... Surma: ... Jake: has, you know, given us aspect ratio on images recently. Surma: ... Surma: ... Surma: I think the only time I ever type auto Surma: is margin zero auto. Surma: ... Jake: Right. Let's talk about that. Surma: ... Jake: I think that's badly named because what does that mean? Surma: ... Surma: It is! Surma: Oh no! I've activated Surma: your tweet trap card! Surma: ... Jake: Yes, I think it's. Surma: ... Jake: I think seriously, if that feature was invented now, Surma: ... Surma: ... Jake: you would do margin zero one FR to mean I want the margin Surma: ... Surma: ... Jake: to be a fraction of the remaining space. Surma: ... Surma: Yeah, but that wasn't a thing! Surma: That came with flex. Jake: No, no, no. Jake: I realized that, but I said that's why I'm saying if we did it now, Surma: That wasn't a thing. That unit was on... Surma: ... Jake: but OK, let's say they're inventing it back in a day. Surma: ... Surma: ... Jake: What if it was margin zero distribute, you know, Surma: ... Surma: ... Jake: like name it something that describes what it does. Surma: ... Surma: ... Surma: But I think auto was already a keyword Surma: that we're not gonna invent. I think at that time Surma: it was just like, just use one of the keywords Surma: we already have. We don't want to fix the parser. Surma: ... Jake: Well, that's bad for the future, isn't it? Surma: ... Jake: So I don't know if that's the reason. Surma: ... Surma: ... Jake: I suppose. Jake: But yeah, maybe that's the case. Surma: ... Surma: ... Jake: Maybe it was just not wanting to have extra words in there. Surma: ... Surma: ... Surma: ... Jake: Yeah, but it's only sometimes the thing you want, right? Surma: ... Surma: ... Surma: ... Jake: It's anyway. Surma: ... Jake: Yes. OK. Jake: I hope that all turns out OK, but it's, you know, if it doesn't, Surma: ... Surma: ... Jake: then we can, you know, it's down to dev rel people Surma: ... Jake: to just guide developers away from the foot guns. Surma: ... Surma: ... Jake: Whatever, whatever. Surma: ... Jake: It'll be fine. Surma: ... Jake: Yeah, I mean, that's pretty much we've been talking long enough. Surma: ... Jake: There are a few more features, but they're smaller ones. Surma: ... Jake: So we can maybe revisit this as they become sort of more real proposals. Surma: ... Surma: ... Surma: ... Surma: ... Jake: But that's kind of where we're at. Surma: ... Jake: I think there's a lot to be excited about. Jake: I think the biggest one is those scoped view transitions for single page apps. Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Jake: Absolutely. Jake: Yes. Jake: Yeah, particularly the ones that have already shipped, like CrossDocument. Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Jake: Our ex-colleague Brahmus is the one who wrote the CrossDocument view transitions guide, Surma: ... Jake: I guess. Surma: ... Jake: It's really good. Jake: I was able to lead on that to kind of double check some of the content here as well. Surma: ... Surma: ... Jake: So I will link to that and a bunch of other CSS issues and stuff. Surma: ... Jake: So yeah, go and play with that. Surma: Nice Jake: I think it's great to see that this stuff hasn't just shipped half a thing. Surma: ... Surma: ... Surma: ... Jake: It's done the thing of minimum viable product, Surma: ... Jake: but it is being actively worked on in quite a significant way, which is great for the web. Surma: ... Surma: ... Surma: ... Jake: All right. Surma: ... Jake: That's all I got. Jake: Should we go away now? Surma: ... Surma: ... Surma: ... Surma: ... Jake: I think so. Surma: ... Jake: All right then, mate. Surma: ... Jake: Nothing left to say except... Surma: Surma: ... Jake: Happy next time! Surma: ... Jake: Bye! Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ... Surma: ...