-
Notifications
You must be signed in to change notification settings - Fork 715
[css-view-transitions-2] MPA: Reacting to the old/new page type #8683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've worked on creating choreographic page transitions in SPAs for a long while now and it was nostalgic going over the options described here as being quite familiar to when I was agonising over the different approaches. Eventually I've come to greatly appreciate the last option most in my web apps, with the named page types, as being most maintainable and logical. Storing weird state or depending on URLs has always been painful and awkward depending on designs and nested/hierarchical info architecture that don't conveniently match up. So the separation with it's own system via named page types helps with the motion design. -- |
I like the 3rd option the best.
Both of these issues might be ok but should be properly reviewed. The same principles apply to #8785 and #8790: if we expose the exact time of the transition, we expose something about a navigation that might be cross-origin. This is OK if we don't want to support same-site in the future. |
(To be clear: my view is that I would love to make these features happen on the expense of same-site cross-origin, but the latter could be an important use case for some folks) |
Would be nice if all could be done using only CSS, so evidently I am in favor of any approach that would afford this. Proposals 2 and 3 look nice, but there’s still something missing: when doing transitions between two pages of the same type, you might need some extra info to determine the “direction of animation”. Say you’re looking at a list of 100 items, paginated per 10 items, and you are currently on page 5. When going to page 4 you’d want all items (old and new) to slide to the right, whereas when going to page 6 you’d want to slide them in the opposite direction. Having just the page-type or url pattern available doesn’t cut it, as you’re doing transitions between the same type of pages. |
Ohh, that's a good use-case to capture.
Yeah, that's a significant issue, and it wasn't spotted before. It seems like there are multiple cases where risks with 3rd party CSS hold useful features back (eg #5092). I wonder if there's a general way to solve the issue. |
I've been prototyping a bit with this. Let's say, when going between "home" and "article", I want to give So, I want a rule like
In one of these cases, "article" is the old page, in the other it's the new page. There are probably cases where you need to know all three bits of information:
But in this case, and seemingly a lot of similar cases, you only need to know:
Being able to express that would reduce code. Eg: :root:vt-current-page-type(article):vt-other-page-type(home) .banner-img {
view-transition-name: banner-img;
} Compared to: :root:vt-current-page-type(article):vt-old-page-type(home),
:root:vt-current-page-type(article):vt-new-page-type(home) {
& .banner-img {
view-transition-name: banner-img;
}
} |
I still think that for most transitions we saw in the wild so far, "page type" was less the mental model than "transition type". In most cases there were a small number of transition types, plus maybe the odd customization for page type. The nice thing about transition type is that it's flexible and unopinionated - you can feed the page type/direction into it, which doesn't work in the other direction. |
Ok. The use-case I brought up is very common though. It'd be good to see how its implementation would look with the proposed solution. |
So, @flackr pointed out that "current page type" can be much better handled by a class name on |
@fantasai responding to your IRC comment, That's why #8048 (comment) focuses on URL matching as the only way to extract information about a navigation. Happy to hear alternatives! |
We implemented MPA transitions for a project some years ago and we used attributes on the clicked anchor element to trigger the right animation. The way we implemented MPA transitions before this API isn't really relevant, but we face the same problem. You need to know what kind of animation to start ahead of time. In our case we knew server-side for each url what type of page it would be. <a
class="..."
href="..."
data-transition-type="foo"
data-transition-duration="1150"
data-transition-background-color="#dedcd9"
data-transition-color="#000000"
> |
Thanks for sharing! |
Correct and I see where you are going with this :) |
This covers a few use-cases:
view-transition-name
depending on its own page type and/or the 'incoming' new page type.view-transition-name
depending on its own page type and/or the old page type.I refer to "page type" here because if you create a custom transition I think it's more likely to be from "index" to "article", even though there may be many URLs that implement the "article" layout.
Currently, with SPA transitions, we recommend using class names on the root:
Now those class names can be used in selectors to meet all of the use-cases above.
But how should we do it with MPA?
Option 1: Stick with class names
We could add events to allow MPAs to set class names on the root element:
But… part of the fun of MPA transitions is you don't need JavaScript.
Option 2: Media queries based on URL
This allows the developers to set styles depending on the next page URL (after redirects), and on the new page they can style depending on the current page and previous page URL.
URLPatterns are already defined.
However, URLs can be a little fragile. Often, you don't have all articles under
/articles/*
etc etc.Option 3: Media queries based on page type
Where pages declare their type via a meta tag:
This could be easily used by SPA transitions too.
However, is it too hard to get the incoming page type from the meta tag for use in the outgoing page?
The text was updated successfully, but these errors were encountered: