-
Notifications
You must be signed in to change notification settings - Fork 59
CSS view transition auto name generation #1001
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
Hi @noamr, I know this is a small thing, but the explainer really needs examples. |
Discussed in a breakout. This seems fine. There is a web-compat risk "self" and "auto" were not previous proscribed, but now have new meaning. |
I'd like to raise a couple of concerns about this that TAG may not have considered. To reiterate, the feature is
A close equivalent is: .transitioning-list-items {
view-transition-name: match-element;
&:has([id]) {
view-transition-name: attr(id type(<custom-ident>));
}
} The problems
Hiding these foot-guns behind a friendly name like SPA vs MPA transitionsAlmost all view transition CSS features work the same for both cross-document and same-document view transitions. One exception is
This will be especially troublesome in sites that perform same-document navigations, except in cases where they know there's an update available, in which case they do a cross-document navigation to pick up the changes. This is a common pattern in larger SPAs. This will likely result in half-broken transitions that users will experience sometimes. This will be hard for developers to debug. This isn't the only case where this will be a problem, but it's one real-world example. The only way to avoid this is to give every transitioning element an id attribute. But, if you can do that, you could already give it a Adding IDs becomes riskyThis feature overloads the id attribute, and means adding an id to an element can break transitions, even if that id is not used anywhere else in the code base. Previous to this, it was safe to add a unique id to an element (except in cases where the CSS had something odd like This feature assumes that Here's there detail. I'm using React for brevity, but this issue also exists in plain DOM usage. This produces a basic list of items, with a button that randomises the order of the list via a transition. This is one of the main use-cases given for this feature. export const ListOfStuff = () => {
const [items, setItems] = useState([
{ imgSrc: '…', alt: '…' },
// …
]);
const onButtonClick = () => {
document.startViewTransition(() => {
flushSync(() => {
const newItems = items.slice();
randomSortArray(newItems);
setItems(newItems);
});
});
};
return (
<div>
<ul class="list-of-stuff">
{items.map(({ imgSrc, alt }) => (
<li key={imgSrc}>
<img src={imgSrc} alt={alt} />
</li>
))}
</ul>
<button onClick={onButtonClick}>Randomise!</button>
</div>
);
}; And let's make this all work with this new enticing feature: .list-of-stuff > li {
view-transition-name: auto;
} It works! Each item moves from its old position to its new position. But then, sometime later, another developer on the project wants to be able to link folks to the first item of the list, or use one of the many other features that link things to their target via ids. That's a small and easy change! export const ListOfStuff = () => {
// …as before…
return (
<div>
<ul class="list-of-stuff">
{items.map(({ imgSrc, alt }, i) => (
- <li key={imgSrc}>
+ <li key={imgSrc} id={i === 0 ? 'first-stuff-item' : undefined}>
<img src={imgSrc} alt={alt} />
</li>
))}
</ul>
<button onClick={onButtonClick}>Randomise!</button>
</div>
);
}; The developer is smart and careful, so they check that But, they just broke the transition. It isn't totally broken, parts of it still kinda work, but it doesn't look right. Specifically, three of the items no longer move, they just fade. The problem is that, with Developers will now have to be very careful when adding If the developer used So, Given this, why do we want this on the platform? I see why this passed initial review, because it works ok in little codepen demos with a single author and no forward maintenance. But for the wider web, it's a foot-gun. I raised these details with the CSSWG, but Safari went ahead and shipped, and will not unship. Further concerns in the thread were ignored. |
Thanks for raising that here Jake. I can see how this is potentially problematic. Is your point that this is a straight-up misfeature and it shouldn't exist at all because match-element is enough for SPA where as MPA can't rely on auto unless there is exceptional id-allocation discipline? Or, do you have an alternative approach in mind? Is that alternative as simple as an appropriately-scoped (We are given repeated reminders how the TAG and standards groups more generally have no direct ability to affect what ships in browsers, so I doubt we can do anything about Safari plans.) |
I like In SPAs built with a framework such as React/Vue/Svelte, element equality is abstracted away from you. It's just an optimisation. And (as far as I know) none of them allow an element to change parent node. Fun example: In NextJS and Remix, each route is a component, so if your You can maintain element equality when reordering siblings using the At somewhere like Shopify, I'd recommend assigning a That said, I think The problem with
I love that CSS As a codebase maintainer, I'd raise concerns about
Given that |
As well as "adding IDs becomes risky", removing them becomes risky too. Here's a fairly typical case: Moving IDs to another element:
Cleaning up IDs:
In both of these cases, the transition may not be broken in all cases. In many instances of the transition, element equality may be enough, so the bug is likely to hit production. This wouldn't be an issue with |
The TAG has previously been concerned about CSS using
The TAG hasn't discussed any consensus preferences yet, and obviously we can't force Safari to do anything in particular, but we could encourage the other browsers to hold off on defining |
Look at the minutes: w3c/csswg-drafts#8320 (comment) |
In those minutes, I see a "PROPOSED: Introduce keyword for element identity, some other syntax for using the element's ID, and auto keyword that switches between the two", followed by "RESOLVED: Add three keywords, one for ID attribute, one for element identity, and one that does fallback between the two." That is, the WG modified the resolution text to drop I wonder if we/the CSSWG should write a CSS design principle about taking extra care when proposing |
We looked at this in a breakout today, and we agree with Jake that We're still satisfied with the |
こんにちは TAG-さん!
I'm requesting a TAG review of view transition auto name generation.
Generating names for view-transition based on element identity, to reduce burden of inventing unique names.
Explainer¹: https://github.com/WICG/view-transitions/blob/main/auto-name-explainer.md
Specification: https://drafts.csswg.org/css-view-transitions-2/#auto-vt-name
WPT Tests: Still under review (https://chromium-review.googlesource.com/c/chromium/src/+/5878355)
User research: See poll
Security and Privacy self-review²: https://github.com/WICG/view-transitions/blob/main/auto-name-explainer.md#self-review-questionnaire-security-and-privacy
GitHub repo: https://github.com/w3c/csswg-drafts
Primary contacts: @noamr @khushalsagar, Google, editing the view-transitions spec
Organization/project driving the specification: Google
Multi-stakeholder support³:
view-transition-name
from element WebKit/standards-positions#408Status/issue trackers for implementations⁴: TBD
Further details:
I have reviewed the TAG's Web Platform Design Principles
Relevant time constraints or deadlines:
The group where the work on this specification is currently being done:
The group where standardization of this work is intended to be done (if different from the current group):
Major unresolved issues with or opposition to this specification:
This work is being funded by:
You should also know that... this has been discussed thoroughly in the CSSWG.
The text was updated successfully, but these errors were encountered: