Skip to content

Commit 6106271

Browse files
authored
[css-view-tranitions-2] Update two-phase view transition explainer (#14145)
1 parent 98f7294 commit 6106271

1 file changed

Lines changed: 46 additions & 17 deletions

File tree

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

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ navigation.addEventListener("navigate", event => {
7373
historyChange: "immediate",
7474
async handler(controller) {
7575
const transition = document.startViewTransition(() => show_preview());
76-
76+
7777
// The restore callback will be called if the navigation is aborted, or if this document is restored from BFCache.
7878
controller.addRestoreCallback(() => hide_preview());
7979
return transition.finished;
@@ -95,23 +95,52 @@ navigation.addEventListener("navigate", event => {
9595
The above knobs can be very effective, but might also require expertise to get right.
9696
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.
9797

98-
As an alternative, proposing a declarative CSS-based solution, based on view-transition at rules and `@navigation` conditionals:
98+
As an alternative, proposing a declarative CSS-based solution, based on view-transition at rules, `@navigation` conditionals, and UA-provided view-transision types:
9999

100100
```css
101-
@navigation(preview) {
101+
@navigation(phase: preview) {
102102
#skeleton {
103103
display: block;
104104
}
105105
}
106106

107107
@view-transition {
108-
navigation: preview;
109-
types: some-preview-types;
108+
preview: always;
109+
}
110+
111+
:active-view-transition-types(-ua-to-preview) {
112+
.real-content .thumbnail {
113+
view-transition-name: thumb-to-hero;
114+
}
115+
}
116+
117+
@navigation (phase: preview) {
118+
.real-content .thumbnail {
119+
view-transition-name: none;
120+
}
121+
122+
:root:active-view-transition-types(-ua-to-preview) {
123+
.skeleton .hero-placeholder {
124+
view-transition-name: thumb-to-hero;
125+
}
126+
}
127+
128+
:root:active-view-transition-types(-ua-from-preview) {
129+
& {
130+
view-transition-name: none;
131+
}
132+
.skeleton {
133+
view-transition-name: root;
134+
}
135+
}
110136
}
137+
111138
```
112139

113-
The "preview" animation with its attached types would start when the navigation is initiated (but not intercepted), and would defer the commit until
114-
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).
140+
The `@navigation (phase: preview)` conditional allows authors to define styles that apply only during the preview phase of a cross-document view-transition,
141+
while the two special "types" `-ua-to-preview` and `-ua-from-preview` can be used to define styles, specifically `view-transition-name`s, when going from
142+
the old real content to the preview state, or out from the skeleton to the new page.
143+
115144

116145
## Pros and cons of the different solutions
117146

@@ -125,7 +154,7 @@ However, the current plan is to enable that first for power users, and take lear
125154

126155
It may expose some information about timing of a navigation, including whether a prerendered page is ready.
127156
It is limited to same-origin navigations.
128-
157+
129158
2. Do features in your specification expose the minimum amount of information
130159
necessary to implement the intended functionality?
131160

@@ -136,7 +165,7 @@ Yes
136165
either?
137166

138167
No
139-
168+
140169
4. How do the features in your specification deal with sensitive information?
141170

142171
N/A
@@ -150,12 +179,12 @@ No
150179
that persists across browsing sessions?
151180

152181
No
153-
182+
154183
7. Do the features in your specification expose information about the
155184
underlying platform to origins?
156185

157186
No.
158-
187+
159188
8. Does this specification allow an origin to send data to the underlying platform?
160189

161190
No
@@ -167,7 +196,7 @@ No
167196
10. Do features in this specification enable new script execution/loading
168197
mechanisms?
169198
No
170-
199+
171200
11. Do features in this specification allow an origin to access other devices?
172201

173202
No
@@ -188,28 +217,28 @@ None
188217
third-party contexts?
189218

190219
It is only available for same-origin navigations.
191-
220+
192221
15. How do the features in this specification work in the context of a browser’s
193222
Private Browsing or Incognito mode?
194223

195224
N/A
196-
225+
197226
16. Does this specification have both "Security Considerations" and "Privacy
198227
Considerations" sections?
199228

200229
Yes
201-
230+
202231
17. Do features in your specification enable origins to downgrade default
203232
security protections?
204233

205234
No
206-
235+
207236
18. What happens when a document that uses your feature is kept alive in BFCache
208237
(instead of getting destroyed) after navigation, and potentially gets reused
209238
on future navigations back to the document?
210239

211240
This is handled specifically with the `addRestoreCallback` method.
212-
241+
213242
19. What happens when a document that uses your feature gets disconnected?
214243

215244
The navigation gets aborted anyway.

0 commit comments

Comments
 (0)