-
Notifications
You must be signed in to change notification settings - Fork 57
Open
Description
A couple of folks said the API is confusing in parts. Maybe it can be improved. As a basis for the conversation, here are the current assumptions:
- For the feature to work, it needs to capture the state of the DOM before and after the change.
- Capturing the 'before' state is async, as it needs to wait for the next render to read back textures.
- To cater for frameworks that batch DOM updates, updating the DOM may be async.
- If the DOM change fails, the transition should not happen. An uncaught error during the DOM change indicates a failure.
- The transition is an enhancement around the DOM change. If the transition cannot happen, that shouldn't prevent the DOM change.
- If the transition is misconfigured (for example, two elements have the same
page-transition-tag), the transition shouldn't happen. This may be detected before the DOM change, but it shouldn't prevent the DOM change. - Right now, transitions apply to the whole document, and two transitions cannot happen concurrently. Starting one transition before the other has finished causes the earlier transition to 'skip'. However, the DOM update is not skipped, as skipping a transition doesn't necessarily mean the underlying change should be prevented (think of two updates that increment a counter).
- Whether the DOM change succeeded is useful to the developer in other contexts, such as the Navigation API, so the transition API shouldn't make it hard to determine this.
- More advanced transitions require JS, so the developer needs to know when the transition is about to start, and the transition elements are available.
- The developer may wish to queue their transition behind another, to prevent the earlier transition skipping.
- The developer may wish to skip their transition if the previous transition fails to complete successfully and fully.
The current API:
const transition = document.createTransition({
async updateDOM() {…}
});
transition.domUpdated.then(…);
transition.ready.then(…);
transition.finished.then(…);
transition.skipTransition();updateDOM- this is where the developer changes the DOM. The callback allows the feature to know when the DOM change is complete (via the returned promise) and rejections indicate failure. This callback is always called, as the DOM update is more important than the transition.domUpdated- this exposes the result ofupdateDOMfor use in other APIs, such as the navigation API. It may fulfill even if the transition is skipped, or cannot happen due to misconfiguration.ready- this fulfills when the transition is ready to go, so parts of the animation can be driven with JS. It rejects if the transition fails to become ready, due to skipping, misconfiguration, or a failure in the DOM change.finished- this fulfills when the transition animates to completion. It rejects if the transition fails to fully finish, due to skipping, misconfiguration, or a failure in the DOM change.skipTransition()- causes this transition to end abruptly, and rejectsreadyandfinishedif they haven't already resolved.
Metadata
Metadata
Assignees
Labels
No labels