Using startViewTransition with Lit #4179
Replies: 5 comments 7 replies
-
Since this.lifecycleRenderTransition = document.startViewTransition(() => super.performUpdate()); |
Beta Was this translation helpful? Give feedback.
-
I haven't used the view transition API (aside from editing your playground just now) yet, but this seems (edit: about) right! We don't have any plans to add this yet. I would want to know a bit more - when is it good to enable, what's the cost, what kind of options do developers need and would the be pre-class or more dynamic and per instance, etc. Being able to do this yourself with an override to Edit: I think you need to wait for the transition to finish, or you could get additional calls to performUpdate before then: @customElement('my-component')
export class MyComponent extends LitElement {
private _viewTransition?: ViewTransition;
async scheduleUpdate() {
if (this._viewTransition !== undefined) {
await this._viewTransition.finished;
}
return super.scheduleUpdate();
}
performUpdate() {
if (!document.startViewTransition) {
return super.performUpdate();
}
await (this._viewTransition = document.startViewTransition(() => {
super.performUpdate();
}));
// clear the _viewTransition object so that we don't await a resolved Promise in a
// future scheduleUpdate() call:
this._viewTransition = undefined;
}
} This is enough code and subtle enough that I could see a mixin added to a labs package, maybe to |
Beta Was this translation helpful? Give feedback.
-
Perhaps, rather than exposing the |
Beta Was this translation helpful? Give feedback.
-
From startViewTransition() Method Steps:
Definitely some subtleties to this API! |
Beta Was this translation helpful? Give feedback.
-
After further discussion with @ChrisShank, and looking at this with fresh eyes today, I'm not convinced the View Transitions API should generally be integrated inside a Lit custom element. Consider:
Many of the View Transitions API experiments floating around recently conflate generalized UI animation with the page layout transitions that this API seems best suited to address. While metaframeworks and routers have some overlapping concerns, a custom element probably just needs to provide some indication that its DOM output is settled (ex. To produce a visually complete and coherent page level animation may require the This seems like it might be more of a concern for the Lit Router, which could potentially centralize control over the view transition. There might be a way to make this functionality composable by externalizing the scheduling to a single authority like that via collaborating APIs. (For very constrained use cases, a custom element representing the whole page could also coordinate this internally as above and akin to |
Beta Was this translation helpful? Give feedback.
-
I want to use the new View Transitions API with
LitElement
.To use this you wrap the update to the DOM inside
startViewTransition
, something like this?By default this will just cause DOM changes to fade-transition in Chrome, Edge and Opera.
await super.performUpdate()
orawait transition.ready
?(my guess is no as
updateComplete
is already exposed for that)startViewTransition
withLitElement
?Edit following feedback
@lit-labs/motion
PR: #4185Updated playground
Beta Was this translation helpful? Give feedback.
All reactions