Skip to content

Commit 3ea4d89

Browse files
authored
Update two-phase transition explainer with CSS solution
Propose a declarative CSS-based solution for view transitions using @navigation conditionals to improve UX.
1 parent 1b5952d commit 3ea4d89

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

css-view-transitions-2/two-phase-transition-explainer.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,29 @@ navigation.addEventListener("navigate", event => {
8383
- Only same-origin navigations without cross-origin redirects are deferrable.
8484

8585

86-
## Solution 2: Allowing animations to defer commit for a short period
86+
## Solution 2: Declarative "preview" view transitions & navigation preview state
8787

8888
The above knobs can be very effective, but might also require expertise to get right.
89+
Specifically, the `addRestoreCallback` mechanism can be easily overlooked by developers and cause bad UX when BFCache is enable and the state is not cleaned up properly.
8990

90-
The likely use case to let an animation continue till the end, so we can perhaps enable this declaratively:
91+
As an alternative, proposing a declarative CSS-based solution, based on view-transition at rules and `@navigation` conditionals:
9192

9293
```css
93-
::view-transition-group {
94-
animation-navigation-behavior: smooth;
94+
@navigation(preview) {
95+
#skeleton {
96+
display: block;
97+
}
98+
}
99+
100+
@view-transition {
101+
navigation: preview;
102+
types: some-preview-types;
95103
}
96104
```
97105

106+
The "preview" animation with its attached types would start when the navigation is initiated (but not intercepted), and would defer the commit until
107+
it is finished. The "new" state of the animation would be controlled by style only, using the `@navigation(preview)` conditional (which can be mixed and matches with other conditionals).
108+
98109
## Pros and cons of the different solutions
99110

100111
While deferring page swap provides full flexibility, it also needs care to avoid some footguns that can cause unwanted navigation delays.

0 commit comments

Comments
 (0)