-
Notifications
You must be signed in to change notification settings - Fork 639
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] view-transition-name determined by element #8320
Comments
As @chriscoyier pointed out recently, this solution doesn't really give authors a way to define transitions for the unique names that are generated. How would an author write |
I think that's a separate feature #8319, but yes, you would need that feature before this one. I should have mentioned it in the OP. |
I don't think we actually want this to be a generic feature, for a few reasons.
So I instead recommend having view-transitions define a custom way of saying "this thing has a name, but also is unique based on element identity in a way that's not exposed directly but does affect before/after matching". Maybe just |
I'm happy to sit on this one for a bit. #8319 is higher priority. |
Suggesting that a solution to this should take #8319 (comment) into account, and build upon #9141 as a way to dynamically generate unique idents. For example, given a playlist of songs, all of the songs can have a The idea in #9141 is to concat it from attributes, e.g. This is also flexible in a way that DOM order can be used instead of attributes, e.g. with the |
@tdresser shared an interesting observation today, frameworks like React have a concept of a unique key for list items : https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key. It seems like instead of a native API, where we can only assume element identify via the corresponding Node, it would be cool to leverage such concepts within the frameworks. Maybe add an API which makes hooking up a custom attribute to the CSS property value easier? |
As someone who is very often not using one of these frameworks, it doesn't feel like a great solution to me. |
@mirisuzanne are you otherwise happy with a feature that would only work same-document transitions? |
I wonder what people think about an idea like this:
Where the attributes are captured in the selector chain and then used to generate a name. |
Oh, my happiness. Interesting… :) I'm not actually opposed to a feature that makes it easier for third-party tools to assist in the cross-document functionality. I just hope we also keep working towards a solution that doesn't rely on frameworks? @noamr I think your proposal still has the cross document issue? Those IDs would be specific to a given document? |
You can have elements with the same IDs on the new document, eg if the IDs come from some database. |
Interesting. I like how this allows you to capture an attribute from a parent element and use that on a child. With Two thoughts:
|
Isn't the |
One issue with that syntax is it allows you to capture an attribute named n from only one element in the chain. As in, you can't do: I don't like the naming/syntax here, but you could do something like: :capture-for-attr(.one, 'one') :capture-for-attr(.two, 'two') {
view-transition-name: captured-attr('one', 'foo') captured-attr('two', 'foo');
}
This all feels very complicated though. |
I think that if we wanted to support multiple attributes with the same name in the future we could add something like: .one[@id1:id] .two[@id2:id] { view-transition-name: "something" @id1 @id2 } (JS destructuring assignments have the same problem and a similar sollution) If we go with verbose function-style I'd rather use the more conservative attr+CSS-variables. |
A while back I ran a poll (Twitter, Mastodon) asking authors what is missing from View Transitions. Out of the 33 replies, 6 requested this feature, making it the number 1 request (along with retargetable transitions and scoped transitions) |
I'm curious what the |
Which ID would you pick, given: section[id] > li[id] label * { view-transition-name: item-[@id] }` Without |
I'm making a simple demo that uses View Transitions to animate enlarging an item that's laid out with CSS Grid, and shifting the other items in the grid around. I was surprised to learn that 1) I have to use JavaScript to use View Transitions, and 2) that I have to give each item in the Grid a unique This caused me to have to write this code:
Which is not robust — what if there are more than 50 items on the Grid?? The experience will break. It seems View Transitions was designed with the expectation that websites are JavaScript first — that it's fine if every items needs to be uniquely named, a developer can just use JS to create all the HTML, and inline styles with JS-created names. |
This would be a much better solution: |
See discussion above - the problem with this solution is that it doesn't work for cross-document, or if the framework recreates the element. Generating the name from attributes is perhaps more verbose but works for all those use-cases. |
This is only the case for Same-Document View Transitions. For Cross-Document View Transitions JavaScript is not mandatory. (And, in the future, there could always be worked on defining some non-JS based triggers for Same-Document View Transitions)
While that could solve some Same-Document View Transitions, this solution won’t work for:
This is also discussed earlier in this thread. Also see the discussions in #9639 and #9141 which are concerned with solving this naming problem. |
Agenda+’ing this one as I think it’s ready for discussion at the meeting. Proposal:
Why not only
Why
Why not
|
Minor thought on Imagine this, which uses the .card {
--card-id: element-uuid();
view-transition-name: ident(var(--card-id));
img {
view-transition-name: ident(var(--card-id) "-img");
}
} This works as long as the card elements remain the same elements, but it works even if the img within is a different element. That doesn't seem possible with |
Using
Not sure what's the problem... You label the item you're removing as "--special-item" and the rest as "--normal-item" and everything should line up just fine?
This is fine. Not everyone is building an "SPA". View Transitions can be used to do nice animations for simpler changes within a web page, such as in @jensimmons's demo. Fancy counting functions and string concatenation for building out custom IDs is nice but... if you don't need them, why do we need to require them? We shouldn't require authors to use complicated mechanisms to do simple things. In general, the CSSWG shouldn't be designing features for large complicated websites only, but also make things easy to use for smaller, simpler websites (and parts of websites) also. Authors can step up to more complicated solutions as they need them, we shouldn't force them into it prematurely. |
I +1 the idea of autogenerating names without requiring the author to assign an id to every element. But I prefer an approach which uses node identity to generate names over DOM ordering. The DOM ordering approach is more subtle in that small unrelated changes to the DOM can affect how elements are being matched up. A node identity based approach is possible with both syntax options: @fantasai node identity based generated names should work for the use-case @jensimmons brought up. Would you still want us to use DOM ordering for this..? |
Practically, I don't see how this is different from: .card {
view-transition-name: element-uuid();
img {
view-transition-name: element-uuid();
}
} In which case, |
^ |
I personally don't see much point in removing and recreating the |
It seems nicer since it's able to support more use-cases. And the syntax doesn't seem any complicated than the |
The reason I'm reluctant to it is because Perhaps it's more syntax bikeshedding at this point, but I would rather have some syntax that abstracts away things and feels more like CSS. It doesn't need to necessarily be |
I don't have a proposal on top of my head aside from |
When mutating something like an image, the old image sticks around until enough of the new image has loaded. This is often undesirable (especially given that width and height changes apply immediately), and a quick fix is to recreate the element, so you get the initial element loading experience. More generally, when developing with frameworks, it's somewhat trickier to preserve element identity than it is to force new element creation.
I don't agree. I think if you asked developers what they think the two do, you'll get something more accurate with
Now let's do When 🤷
I don't think you're abstracting much away. The auto generated name will probably appear as the group name. As for 'feels', I really think we should focus on more objective things, but |
This isn't just about feels.
In my proposal, the computed value would just stay
Fwiw, Just to be clear though, I'm not advocating for a particular syntax. I'm open to a different one that addresses more use-cases but I think honoring how CSS was designed is important IMO. I wonder if @fantasai or @tabatkins have ideas here. |
A lot of use cases fall in the middle between that demo and a full-blown SPA, there's no clear dichotomy. By allowing Since
perhaps we should spec & implement ident+attr first, and defer this conversation until after we've received feedback from developers that they're too verbose for some use cases? |
@noamr I appreciate the reframing. I do worry that the use-cases being tackled here are ones that pop up for little demos, but aren't such a big issue in 'real' development. In real apps/sites, it's pretty easy to assign items a unique ID. The biggest help here has been transition classes. Aside from that, it feels like a lot of effort is being spent here that could be better spent on something like nested transition groups, which would unblock a bunch of transitions. |
All of the proposed solutions are not exclusive. The simplicity of The element identity matching seems to be already present to some extent in I'm fine with trying ident/attr solution first, but isn't this just moving the naming problem from CSS to DOM? It doesn't at all address the "demo" cases, and the fact that a lot of DOM may already have unique ids on elements in "real world" cases seems coincidental at best |
The CSS Working Group just discussed The full IRC log of that discussion<emilio> vmpstr: unique names for transitions is cumbersome because authors need to come up with a bunch of unique names<emilio> ... various proposals <emilio> ... one is to have v-t-n: auto / from-element which matches with element identity <emilio> ... so as long as it doesn't change it works nicely <emilio> ... but it doesn't work with cross-document transitions <emilio> ... and also for frameworks that might replace the dom nodes <emilio> ... another proposal is `element-uuid()` but it's effectively the same as above, just more explicit <emilio> ... another one is `attr()`, which would work for cross-document v-t and frameworks <emilio> ... my proposal would be to do both <khush> q? <emilio> ... leaving attr for more advanced use cases <emilio> q+ <astearns> ack fantasai <emilio> fantasai: I think doing both (`auto` / `from-element` and `attr()`) makes sense <emilio> ... there was another idea in the thread which needs more thought <emilio> ... right now we restrict v-t-n to be unique <emilio> ... if it's not it gets ignored or something, it's an error condition <emilio> ... in a bunch of cases, let's say you're reordering a list or so you don't necessarily want to number them all <emilio> ... if we could have multiple names and we could number them somehow automatically that might help <emilio> ... but that might be doable in addition to these things <astearns> ack emilio <fantasai> s/reordering/shifting items after inserting into/ <flackr> emilio: my main concern is how likely is it for someone to use from element and not realize it doesn't work for cross document? <flackr> emilio: from where i stand it seems obv it doesn't work, but requires some internals knowledge <astearns> q+ <flackr> emilio: just a mild concern, not blocking. <emilio> ack fantasai <Zakim> fantasai, you wanted to answer emilio's question <astearns> ack fantasai <emilio> fantasai: vt has been focused on the fact that you have "pages", and you're changing pages from one page in a web app to another one <emilio> ... but lots of transitions authors can do are single-page <emilio> ... and sometimes view-transitions is the best tool <emilio> ... for those cases this element identity stuff it's not an issue <ydaniv> +1 <flackr> emilio: for those use cases this is fine, it just feels like it might be confused <flackr> emilio: or worse the browser could accidentally have a same pointer <flackr> emilio: i guess that's just a bug <emilio> flackr: my comment is somewhat related <astearns> ack flackr <emilio> ... while I agree that attr() should be supported <emilio> ... if the common case is an identity <emilio> ... maybe we can roll it into `auto` in-some cases <emilio> ... so if element has an `id` attribute then `auto` would take that <fantasai> interesting <emilio> ... or an ancestor one or something <emilio> vmpstr: we still need to define for the `auto` cases <emilio> ... we still need some identifier that an author can see <emilio> ... I think the element's uuid is a good choice there <fantasai> -1 to uuid <emilio> ... but we haven't thought too much about it <emilio> q+ <fantasai> if the author wants to reference it they should give it a name <khush> q+ <fantasai> using the id attribute <emilio> astearns: I think the automatic number is interesting but has a different set of failure modes that it probably could be a separate issue <vmpstr> it's about the param in ::view-transition-group(param) etc, not sure what to put there, or leave it as "auto"? <emilio> ... I wanted to push back a bit, it seems a bit of a smell that people don't want to put unique names in css so we make them put it on the markup? <astearns> ack astearns <astearns> ack fantasai <Zakim> fantasai, you wanted to respond to astearns <emilio> fantasai: a lot of times you have these unique ids already <emilio> ... so you might as well just reuse them <astearns> ack emilio <fantasai> I like flackr's idea of having `auto` take the ID if it has one, and fall back to element identity matching otherwise <flackr> emilio: just want to confirm, allowing attr would make this id mutable in some interesting ways. I guess we have a well defined point where we collect them so it doesn't add much complexity, right? <astearns> q+ <flackr> khush: I imagine it's similar to attribute changes requiring recomputing style <flackr> emilio: my point is, if the mutation happens after we start the transition, then presumably it shouldn't count? This detail probably needs to be mentioned <flackr> khush: this is called out already for view-transition-name as it's an issue already for name changes <flackr> emilio: sounds good <flackr> emilio: the auto thing seems like it could use a bit more work since as vmpstr mentioned the name is exposed in the css. My slight preference is to resolve attr and figure out auto later <flackr> emilio: happy to also resolve on auto and resolve the details later <astearns> ack khush <emilio> khush: +1 to fantasai, attr() is useful where you already have unique names for your items without having to use JS <emilio> ... the other thing is, I think we'll have an easier time resolving on attr() <flackr> +1 as well, css is often in a separate file and not unique per element <emilio> ... for auto / from-element vs element-uuid <emilio> ... there was an example where element-uuid could be used to name an ancestor or child of an element rather than auto <emilio> ... auto would only allow to set the id on that element itself <flackr> q+ <emilio> ... one other point was that anything that ties with element identity it doesn't work for MPA <emilio> ... we might want to just ignore the name altogether for MPA transitions <emilio> ... so it's harder to miss <emilio> ... but I think we should probably resolve on attr() and work on the other details on transitions <emilio> astearns: I wanted to ask whether it'd make sense to make from-element only work on SPA and reserve auto for something that can work eventually on MPA <emilio> ... so resolve on from-element for now, and opening an issue on an additional auto which does something along the lines that flackr was suggesting <emilio> vmpstr: I don't mind the idea but I'd like a different name that from-element <emilio> ... I'd prefer a different id <astearns> ack astearns <astearns> ack flackr <emilio> ... because from-element seems you're reading something from the element rather than using the element itself <emilio> TabAtkins: can we take it back to the issue? random() has similar use cases and we should make sure they're in sync <emilio> flackr: for auto / from-element it was mentioned that this is exposed <emilio> ... is that necessary? <emilio> ... are there other ways we could do it? <emilio> vmpstr: we can hide it by using auto <emilio> ... we don't currently have the same parameter in the view transition pseudos I don't think it's a problem <emilio> ... the reason we added v-t-c is similar <emilio> ... so I think we can hide it <emilio> flackr: I think you can expose the initial style without a name <emilio> khush: web animations might be weird because you get a list of pseudos and can't differentiate it <emilio> ... any place the name would have appeared then it'd be replaced with auto <emilio> flackr: that's one possibility <emilio> ... maybe there are others <emilio> ... worth exploring <emilio> khush: we use ua css to put styles, we need to figure out how the UA css would work <emilio> flackr: right, but that can be an implementation detail <astearns> ack fantasai <emilio> fantasai: I like flackr's suggestion of auto pulling the id if it has an ID and otherwise uses other way of identity <emilio> q+ <emilio> fantasai: I agree we want to expose randomly generated IDs into author CSS <emilio> ... they can given it a name if they need to target something <fantasai> s/want/don't want/ <emilio> khush: attr() didn't ship for reasons <emilio> fantasai: let's draft some more concrete proposal <emilio> ... and come back <emilio> vmpstr: vague resolution is fine and we can come back with details |
@astearns I see you added the “Needs Edits” label to this thread but I don’t see any resolution in the discussion. Am I overlooking something? |
The conclusion was to have a more detailed proposal for And more exploration is needed for the |
Noticed this wasn’t on the agenda for the F2F, but if there’s time maybe we can discuss? I think it’s clear what we want auto naming for both simple and complex cases.
The result for authors is that there’s less code and less naming things going on – see this example that uses a polyfill to get the syntax working. Some names are auto-generated, whereas some rely on The thing that’s unclear is how |
Actually, I think we need a clearer proposal before bringing this back? There were a bunch of open questions about how The |
Probably #9141 (comment) summarizes it.| |
Thinking of this example https://codepen.io/jaffathecake/pen/VwBprqL
In this case the developer has to manually give each list item a unique
view-transition-name
. This could be avoided via something like:Where
element-uuid()
returns a value unique and constant for that DOM node.The proposal for CSS
random()
has aper-element
value that could be generalised aselement-uuid()
. #2826 (comment) (cc @tabatkins)The downside to this is it would only work for same-document transitions, since
element-uuid()
s will always be different across documents. It also depends on element usage being consistent, which some frameworks don't always get right.Edit: This would depend on #8319, otherwise styling the resulting pseudos is impossible.
The text was updated successfully, but these errors were encountered: