-
Notifications
You must be signed in to change notification settings - Fork 677
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
[css-view-transitions-2] Declarative opt-in for cross-document navigations #8048
Comments
The current proposed API is using a meta tag for this, similar to other Document global settings like viewport meta tag. But doing this in CSS would be better, for the reasons Jake mentioned like conditionally doing this based on prefers-reduced-motion. |
Would it be useful for this to be more fine-grained? I.e. allow transitions from certain pages/domains but not others? |
Yes, that absolutely should be a goal. My preference would be to allow pages to declare themselves to be of a particular type, which is just an ident. Then you can express that you're happy to perform a transition from "article" to "profile" or whatever. Although, if we go with URLs, https://wicg.github.io/urlpattern/ will be handy. |
We chatted with @tabatkins and he's happy with the general shape of the syntax here. We would need to define what the CSSOM looks like. It might be worth making @cross-document-transition {
state: allow;
} …which would allow us to add other descriptors in future. In the new page, the opt-in would need to be present before first render. This works out, since CSS in the head is render-blocking. |
Perhaps it can be a pseudo-state of the ::root:has(::view-transition:cross-document) {
view-transition-name: "none" !important;
} |
Not a fan of this Iterating on the at-rule – which makes more sense to me – here’s two variants on that:
|
Oh, wait … that second one doesn’t make sense on its own, as that one doesn’t set anything – it only detects stuff 🤦♂️ |
The @media (prefers-reduced-motion) {
::view-transition:cross-document {
display: none;
}
} This allows more fine-grained control over how things behave if this is a cross-document transition rather than totally disabling the transition. For totally disabling the transitions based on media queries, I'd suggest adding a <meta name="view-transition:referrer" content="same-origin">
<meta name="view-transition:media" content="(prefers-reduce-motion:no-preference)"> I'm offering these alternatives because I don't see how using CSS to declare something that's completely global plays to what CSS is good at, and it's also not very consistent with other things CSS does. |
|
They give meaning to all kind of names, but they don't affect the style directly. |
Thinking about this again. I see the problem the opt-in tries to solve as mismatch between same-origin transitions. It's not a security problem, but rather an issue of unintended visual effects by having e.g. an SPA transition in both documents lead to a spurious MPA transition between the two documents. IMO any kind of boolean opt-in doesn't solve this, either in HTML or CSS. Instead, I propose something a bit more flexible and : the The purpose in doing something like that is to ensure a match in a flexible way, that's still ergonomic and consistent with how SPA navigations declare matching. |
The problem with this is that UA CSS implicitly adds a If we're introducing something new (like |
Agreed, but we can flesh this out. The main concept is that this opt in should be by name matching rather than Boolean. Regarding cross-origin, I think it's a much bigger discussion. This might end up being something with security implications, in which case we would want to have a meta thing, or add a new css property. I don't think that should stop us from having a flexible opt-in for same-origin transitions. |
I don't think we'll be able to ship this for all cross-origin...ever. I specifically meant the same-site case, the security/privacy implications there are not as strict as different domains?
The fundamental issue with either, a boolean or name matching, is that the syntax is not extendible to even same-origin cases like a subset of pages. For example: / * Opt-in for all same-origin navigations */
@view-transition same-origin;
/* Opt-in for same-origin navigations only to URLs which match this pattern */
@view-transition urlPattern(...); I don't see how name matching or a boolean can be extended to cover this use-case. We've talked about an option like a media query which matches based on old/new URL that potentially could : @media (old-url: urlPattern(...)) {
:root { view-transition-name: foo }
} But that's harder to do since now we have to define the exact time in the old/new Document's lifecycle when this media query activates. I think it's the same problem as defining events to be dispatched on the 2 Documents that you've thought out. |
I'm not sure that
makes any sense. Should it maybe be
or something else? |
This doesn't work because it doesn't let you customize classes etc based on URL.
Other suggestions? |
Perhaps @view-transition navigation(same-origin) {
behavior: trigger;
} Later it can be extended like @view-transition navigation back from same-origin to urlpattern("...") {
behavior: trigger;
} |
Some more bikeshedding options: @nav-transition same-origin { behavior: trigger };
@view-transition same-origin-navigation { behavior: trigger }
@navigation-behavior same-origin { view-transition: trigger; } |
Wouldn't this just be an explicit opt-out (which is the default). If an opt-out that's the default seems redundant, could we just omit trigger entirely? (i.e. the existence of the at-rule implies opt-in). Examples: @view-transition same-origin-navigation;
@view-transition same-origin-navigation and history-back {
typeNames: slide-in reverse;
} |
It came out in the TAG review that a standalone rule like |
@noamr how does this syntax deal with #8784? We want transitions to not occur for reloads by default but let authors configure it. Since this can be done in script using the |
In short, The nice thing about reload is that it replaces both the URLs AND the navigation type, so we don't have to bother with composing reloads with other qualifier. A VT-navigation rule is either |
I'm trying to understand what our base qualifiers are. IIUC, the idea is that going forward these base qualifiers can be combined with each other (using and/or operators). I was expecting those to be:
But sounds like you're suggesting |
You're right that redirects might make it so that a reload doesn't necessarily mean the same URL/origin, so perhaps it needs to be About the qualifiers, I'd prefer to look at them more from a user intent standpoint rather than from technical history/navigation terms like push/replace. "reload" and "back" are clear user experience intents, also "forward", "jump to some place in history", or "jump to a random URL in this origin" (address bar, bookmark, extension etc), and of course a normal navigation like links/forms. The way I see it, the opt-in rule applies to some of these intents. By default, probably to navigate+forward+back, and arguably jump. It applies to reload only if explicit. So |
Sorry I'm still not following how we're dealing with the combination of nav type + from/to url. Every combination of these 2 is possible. So if an author has CSS like:
What happens if there is a reload which results in a same-site navigation? Your comment above sounds like all the qualifiers are a combination of nav type and from/to url. "same-origin" means any same-origin url of type "navigate", "back" and "forward". Presumably "same-site" would cover the same nav types. And "reload" means only same-origin reload navigations?
Asking this right now because IMO "same-origin" should only be about the from/to url. Overloading the nav type into it is not a good idea. So I'd expect |
My interpretation of what @noamr is saying is that we can treat I agree with @khushalsagar that my understand of same-origin is to be specifically about The syntax that I like is something like
Where
with an explicit note that explains that if So with this syntax, I think we can express everything? To answer @khushalsagar's question, in this syntax |
I think so. Mainly because a reload with cross-origin redirects is something that feels unexpected and uncommon. Edge case?
Yes exactly
I see the value in having a clean separation between URLs and types, and having But I think there is greater value in reasonable defaults. Putting UX first, view transitions on reload is something unexpected and needs to be handled a bit like an edge case, and in most cases not have a transition there at all unless explicitly requested. The same argument for reasonable defaults (which I think is consistent with a lot of CSS) goes for having reloads be same-origin only by default. As for being conceptually clean, I'd say that in this case |
My concern wasn't with the default, but whether the non-default case is possible : reload with a same-site navigation. In general, I'd say our syntax should ensure that any combination of mutually exclusive navigation params (same vs cross doc, from/to url and nav type) can be expressed. We should have a good reason to disallow a combination and it being an edge case is not a good one. The syntax @vmpstr proposed above sounds good in that regard. One thing I'd say is to include
where
A few more clarifications around it:
@noamr does that sound reasonable to you? If the above sounds good then a couple of questions come to mind:
|
I wouldn't do the same-doc thing in CSS at all, rather have this in JS - something like
Not sure yet, I don't think we're there but sounds OK for now.
It's not strictly necessary. I think it was your suggestion to make it explicit when reading that this only applies to same origin navigation. I'm ok with also making it an implicit default. It wouldn't be the first thing in the web platform that's implicitly same-origin by default. |
Ok. I'm fine with punting on this.
Aren't we resolving on a syntax which requires an "and" relationship between the qualifiers? I figured that's why we should make sure this is fine right now.
I suggested this because it wasn't clear to me how the syntax will be extended to support same-site. Now that its more clearly laid out, it makes sense to be able to omit it. |
We're not suggesting the qualifiers yet. But I imagine having and/or/() like media queries.
Great. Let's suggest this when we discuss the name. |
It's likely fine, I'm just convincing myself that we'll be able to add both and/or operators with the qualifiers later. For example, having no qualifiers implicitly expands to both default values + "and" operator between them. But the author will be able to override the defaults by providing an explicit value for each qualifier + whether its "and"/"or". @view-transition { ... }
/* The above expands to the following */
@view-transition <<route>> and <<navtype>> and /* any other potential qualifiers */ { ... }
@view-transition <<route>> or <<navtype>> { ... }
/* The above will expand to the following */
@view-transition <<route>> or <<navtype>> and /* any other potential qualifiers */ { ... }
SGTM! |
What are the other potential qualifiers?
I think this would expand to |
Same vs cross-doc was the only other one I had, but I can see that being specified in JS instead of CSS. Can't think of anything else but it's good to ensure its possible to add more going forward.
Hmmm, that took me by surprise. Reading the author declaration, that's not what I would've expected. FWIW, @vmpstr pointed out that this use-case can be achieved with 2 blocks like: @view-tranition <<route>> and all-nav-types { ... }
@view-tranition all-routes and <<navtype>> { ... } So whichever expansion we take, we won't be limiting authors. We can decide based on what authors would intuitively expect. |
One minor comment on
It could be useful to provide an identifier for a multi-entry jump e.g. Jumping between two arbitrary pages that are many navigations apart might generate unexpected motion with VT API annotations, and it would be great to have a way to explicitly disable this or specify a simpler animation like a full-page cross-fade. This could apply to the opt-in here, and would also be useful for the actual CSS styling specified. Using cascading rules to override will give power to customize e.g.
(not bikeshedding here with the syntax, just the functionality) |
Suggesting that |
The idea sounds nice but its unfortunate that navigation type in CSS will diverge from navigation type in JS defined by the navigation API. This might be inevitable if we can't change the JS navigation type in a backwards compatible way but worth trying to keep these consistent to the extent possible. @domenic @natechapin FYI. Could we organize the CSS navigation types as sub-types of the JS versions?
|
Cross-document transitions need some way for both the old & new page to opt-in to a transition.
The SPA API uses JS for this, but it would be nice if cross-document transitions didn't depend on JS.
It feels like this should be in CSS, so it can be influenced by media queries, particularly
prefers-reduced-motion
.The tricky part here is it's a "global" setting, so it can't be a CSS property.
Proposal:
However, I'm just making stuff up here. Is there any prior art here for setting 'global' things?
The text was updated successfully, but these errors were encountered: