Skip to content
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

Technical review: Document cross-document view transitions #32723

Closed
Closed
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
c7dcd4e
Document cross-document view transitions
chrisdavidmills Mar 18, 2024
218ab88
Add link rel=expect explanation
chrisdavidmills Mar 18, 2024
b82a640
Update existing content to make sense for SPA and MPA transitions
chrisdavidmills Mar 19, 2024
000fa78
Add doc for @view-transition at-rule
chrisdavidmills Mar 19, 2024
429ef2f
Merge branch 'main' into cross-document-view-transitions
chrisdavidmills Mar 20, 2024
d891779
Add rel=expect content
chrisdavidmills Mar 20, 2024
30accf7
Add pagereveal and pageswap event pages
chrisdavidmills Mar 21, 2024
30eb72d
Add docs for NavigationActivation
chrisdavidmills Mar 22, 2024
a03d960
Add docs for PageRevealEvent and PageSwapEvent
chrisdavidmills Mar 22, 2024
ce1710d
Merge branch 'main' into cross-document-view-transitions
chrisdavidmills Mar 22, 2024
8b88c2a
fix folder naming issue
chrisdavidmills Mar 23, 2024
7c50ef8
Merge branch 'cross-document-view-transitions' of github.com:chrisdav…
chrisdavidmills Mar 23, 2024
3a33825
Merge branch 'main' into cross-document-view-transitions
chrisdavidmills Mar 23, 2024
dd176af
Update files/en-us/web/api/viewtransition/index.md
chrisdavidmills Mar 24, 2024
175a58b
Improvements to demo links and explanations, make event objects part …
chrisdavidmills Mar 26, 2024
a55a815
add PageRevealEvent and PageSwapEvent to HTML DOM landing page
chrisdavidmills Mar 26, 2024
4224491
Merge branch 'main' into cross-document-view-transitions
chrisdavidmills Mar 28, 2024
8640c51
Merge branch 'main' into cross-document-view-transitions
chrisdavidmills Apr 12, 2024
8f3dfaa
Merge branch 'main' into cross-document-view-transitions
chrisdavidmills Apr 12, 2024
290489c
Fixes for bramus and noamr review comments
chrisdavidmills Apr 12, 2024
0973ce2
Update some details of rel=expect
chrisdavidmills Apr 24, 2024
79b7ca3
Merge branch 'main' into cross-document-view-transitions
chrisdavidmills Apr 24, 2024
3a50822
Add note back in that was recently added to main
chrisdavidmills Apr 24, 2024
2afc294
Merge branch 'main' into cross-document-view-transitions
chrisdavidmills May 24, 2024
4f19f17
Latest fixes to review comments
chrisdavidmills May 24, 2024
b9a7530
Update files/en-us/web/html/attributes/rel/index.md
chrisdavidmills May 24, 2024
9e1d074
Update files/en-us/web/api/navigationactivation/index.md
chrisdavidmills May 24, 2024
7fe0eaf
Update files/en-us/web/api/window/pageswap_event/index.md
chrisdavidmills May 24, 2024
0b142e5
Update files/en-us/web/api/window/pageswap_event/index.md
chrisdavidmills May 24, 2024
c894f7b
Update files/en-us/web/api/window/pageswap_event/index.md
chrisdavidmills May 24, 2024
a768586
Update files/en-us/web/api/pagerevealevent/index.md
chrisdavidmills May 24, 2024
d788f87
Update files/en-us/web/api/navigationactivation/index.md
chrisdavidmills May 24, 2024
03dccd3
Update files/en-us/web/api/pagerevealevent/index.md
chrisdavidmills May 24, 2024
6ad60a1
Update files/en-us/web/api/window/pageswap_event/index.md
chrisdavidmills May 24, 2024
45fa318
Update files/en-us/web/api/pagerevealevent/index.md
chrisdavidmills May 24, 2024
be95206
Update files/en-us/web/api/navigationactivation/index.md
chrisdavidmills May 24, 2024
bb868a0
Update files/en-us/web/api/pageswapevent/index.md
chrisdavidmills May 24, 2024
4191156
Update files/en-us/web/api/pageswapevent/index.md
chrisdavidmills May 24, 2024
6faaebb
Update files/en-us/web/api/pageswapevent/index.md
chrisdavidmills May 24, 2024
d6d62ed
Update files/en-us/web/api/pageswapevent/index.md
chrisdavidmills May 24, 2024
c4ef9cc
Update files/en-us/web/api/view_transitions_api/using/index.md
chrisdavidmills May 24, 2024
781ad75
Update files/en-us/web/api/view_transitions_api/using/index.md
chrisdavidmills May 24, 2024
220f138
Update files/en-us/web/api/view_transitions_api/using/index.md
chrisdavidmills May 24, 2024
fdd0cd2
Update files/en-us/web/api/view_transitions_api/using/index.md
chrisdavidmills May 24, 2024
d557f5c
Update files/en-us/web/api/view_transitions_api/using/index.md
chrisdavidmills May 24, 2024
ecdc3d3
Update files/en-us/web/api/view_transitions_api/using/index.md
chrisdavidmills May 24, 2024
c7fa835
Update files/en-us/web/api/view_transitions_api/using/index.md
chrisdavidmills May 24, 2024
c203f38
Update files/en-us/web/api/window/pagereveal_event/index.md
chrisdavidmills May 24, 2024
3022d22
Update files/en-us/web/api/view_transitions_api/using/index.md
chrisdavidmills May 24, 2024
f757a64
Update files/en-us/web/api/view_transitions_api/using/index.md
chrisdavidmills May 24, 2024
1d2e5d3
Update files/en-us/web/api/view_transitions_api/using/index.md
chrisdavidmills May 24, 2024
7f84898
Update files/en-us/web/api/window/pagereveal_event/index.md
chrisdavidmills May 24, 2024
c97f061
Update files/en-us/web/api/window/pagereveal_event/index.md
chrisdavidmills May 24, 2024
632d453
Merge branch 'main' into cross-document-view-transitions
chrisdavidmills Jun 12, 2024
64b2e7e
Fixes for bramus tech review comments
chrisdavidmills Jun 12, 2024
0aef236
Update files/en-us/web/api/pageswapevent/index.md
chrisdavidmills Jun 13, 2024
34fadad
Update files/en-us/web/api/pageswapevent/index.md
chrisdavidmills Jun 13, 2024
afcc431
Update files/en-us/web/api/view_transitions_api/using/index.md
chrisdavidmills Jun 13, 2024
4913b12
Update files/en-us/web/api/view_transitions_api/using/index.md
chrisdavidmills Jun 13, 2024
cc29537
Update files/en-us/web/api/window/pageswap_event/index.md
chrisdavidmills Jun 13, 2024
e3ead76
Update files/en-us/web/api/window/pageswap_event/index.md
chrisdavidmills Jun 13, 2024
6fff811
A few more fixes
chrisdavidmills Jun 13, 2024
aec4da8
Clarify bfcache notes and add explanation about bfcache conflict issue
chrisdavidmills Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions files/en-us/web/api/document/startviewtransition/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ browser-compat: api.Document.startViewTransition

{{APIRef("View Transitions API")}}{{SeeCompatTable}}

The **`startViewTransition()`** method of the {{domxref("Document")}} interface starts a new view transition and returns a {{domxref("ViewTransition")}} object to represent it.
The **`startViewTransition()`** method of the {{domxref("Document")}} interface starts a new same-document (SPA) [view transition](/en-US/docs/Web/API/View_Transitions_API) and returns a {{domxref("ViewTransition")}} object to represent it.

When `startViewTransition()` is invoked, a sequence of steps is followed as explained in [The view transition process](/en-US/docs/Web/API/View_Transitions_API#the_view_transition_process).
When `startViewTransition()` is invoked, a sequence of steps is followed as explained in [The view transition process](/en-US/docs/Web/API/View_Transitions_API/Using#the_view_transition_process).

## Syntax

Expand All @@ -24,7 +24,7 @@ startViewTransition(updateCallback)
### Parameters

- `updateCallback` {{optional_inline}}
- : An optional callback function typically invoked to update the DOM during the view transition process, which returns a {{jsxref("Promise")}}. The callback is invoked once the API has taken a screenshot of the current page. When the promise returned by the callback fulfills, the view transition begins in the next frame. If the promise returned by the callback rejects, the transition is abandoned.
- : An optional callback function typically invoked to update the DOM during the SPA view transition process, which returns a {{jsxref("Promise")}}. The callback is invoked once the API has taken a snapshot of the current page. When the promise returned by the callback fulfills, the view transition begins in the next frame. If the promise returned by the callback rejects, the transition is abandoned.

### Return value

Expand All @@ -34,7 +34,7 @@ A {{domxref("ViewTransition")}} object instance.

### Basic usage

In our [Basic View Transitions demo](https://mdn.github.io/dom-examples/view-transitions/), the `updateView()` function handles both browsers that do and don't support the View Transitions API. In supporting browsers, we invoke `startViewTransition()` to set off the view transition process without worrying about the return value.
In our [Basic SPA View Transitions demo](https://mdn.github.io/dom-examples/view-transitions/spa/), the `updateView()` function handles both browsers that do and don't support the View Transitions API. In supporting browsers, we invoke `startViewTransition()` to trigger the view transition process without worrying about the return value.
chrisdavidmills marked this conversation as resolved.
Show resolved Hide resolved

```js
function updateView(event) {
Expand Down
2 changes: 2 additions & 0 deletions files/en-us/web/api/html_dom_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ The History API interfaces let you access information about the browser's histor
- {{DOMxRef("HashChangeEvent")}}
- {{DOMxRef("History")}}
- {{DOMxRef("Location")}}
- {{DOMxRef("PageRevealEvent")}}
- {{DOMxRef("PageSwapEvent")}}
- {{DOMxRef("PageTransitionEvent")}}
- {{DOMxRef("PopStateEvent")}}

Expand Down
2 changes: 2 additions & 0 deletions files/en-us/web/api/navigation_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ There are a few perceived limitations with the Navigation API:
- : Event object for the {{domxref("Navigation/navigate_event", "navigate")}} event, which fires when [any type of navigation](https://github.com/WICG/navigation-api#appendix-types-of-navigations) is initiated. It provides access to information about that navigation, and most notably the {{domxref("NavigateEvent.intercept", "intercept()")}}, which allows you to control what happens when the navigation is initiated.
- {{domxref("Navigation")}} {{Experimental_Inline}}
- : Allows control over all navigation actions for the current `window` in one central place, including initiating navigations programmatically, examining navigation history entries, and managing navigations as they happen.
- {{domxref("NavigationActivation")}}
- : Represents a recent cross-document navigation. It contains the navigation type and current and destination document history entries.
- {{domxref("NavigationCurrentEntryChangeEvent")}} {{Experimental_Inline}}
- : Event object for the {{domxref("Navigation/currententrychange_event", "currententrychange")}} event, which fires when the {{domxref("Navigation.currentEntry")}} has changed. It provides access to the navigation type, and the previous history entry that was navigated from.
- {{domxref("NavigationDestination")}} {{Experimental_Inline}}
Expand Down
36 changes: 36 additions & 0 deletions files/en-us/web/api/navigationactivation/entry/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: "NavigationActivation: entry property"
short-title: entry
slug: Web/API/NavigationActivation/entry
page-type: web-api-instance-property
status:
- experimental
browser-compat: api.NavigationActivation.entry
---

{{APIRef("Navigation API")}}{{SeeCompatTable}}

The **`entry`** read-only property of the {{domxref("NavigationActivation")}} interface contains a {{domxref("NavigationHistoryEntry")}} object representing the history entry for the inbound ("to") document in the navigation. This is equivalent to the {{domxref("Navigation.currentEntry")}} property at the moment the inbound document was activated.

There are some cases in which either the from or entry NavigationHistoryEntry objects would not be viable targets for the traverseTo() method, as they might not be retained in history. For example, the Document can be activated using location.replace() or its initial entry could be replaced by history.replaceState(). However, those entries' url property and getState() method are still accessible.

## Value

A {{domxref("NavigationHistoryEntry")}} object.

## Examples

See the main {{domxref("NavigationActivation")}} page.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Navigation API](/en-US/docs/Web/API/Navigation_API)
- [View Transitions API](/en-US/docs/Web/API/View_Transitions_API)
37 changes: 37 additions & 0 deletions files/en-us/web/api/navigationactivation/from/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: "NavigationActivation: from property"
short-title: from
slug: Web/API/NavigationActivation/from
page-type: web-api-instance-property
status:
- experimental
browser-compat: api.NavigationActivation.from
---

{{APIRef("Navigation API")}}{{SeeCompatTable}}

The **`from`** read-only property of the {{domxref("NavigationActivation")}} interface contains a {{domxref("NavigationHistoryEntry")}} object representing the history entry for the outgoing ("from") document in the navigation.

## Value

A {{domxref("NavigationHistoryEntry")}} object, or `null` if the outgoing document is:

- Not same origin as the inbound document.
- The initial `about:blank` document.

## Examples

See the main {{domxref("NavigationActivation")}} page.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Navigation API](/en-US/docs/Web/API/Navigation_API)
- [View Transitions API](/en-US/docs/Web/API/View_Transitions_API)
85 changes: 85 additions & 0 deletions files/en-us/web/api/navigationactivation/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
title: NavigationActivation
slug: Web/API/NavigationActivation
page-type: web-api-interface
status:
- experimental
browser-compat: api.NavigationActivation
---

{{APIRef("Navigation API")}}{{SeeCompatTable}}

The **`NavigationActivation`** interface of the [Navigation API](/en-US/docs/Web/API/Navigation_API) represents a recent cross-document navigation. It contains the navigation type and outgoing and inbound document history entries.

This object is accessed via the {{domxref("PageSwapEvent.activation")}} and {{domxref("Navigation.activation")}} properties.
chrisdavidmills marked this conversation as resolved.
Show resolved Hide resolved

## Instance properties

- {{domxref("NavigationActivation.entry", "entry")}} {{ReadOnlyInline}} {{Experimental_Inline}}
- : Contains a {{domxref("NavigationHistoryEntry")}} object representing the history entry for the inbound ("to") document in the navigation. This is equivalent to the {{domxref("Navigation.currentEntry")}} property at the moment the inbound document was activated.
- {{domxref("NavigationActivation.from", "from")}} {{ReadOnlyInline}} {{Experimental_Inline}}
- : Contains a {{domxref("NavigationHistoryEntry")}} object representing the history entry for the outgoing ("from") document in the navigation.
- {{domxref("NavigationActivation.navigationType", "navigationType")}} {{ReadOnlyInline}} {{Experimental_Inline}}
- : Contains a string indicating the type of navigation.

## Examples

```js
window.addEventListener("pagereveal", async (e) => {
// If the "from" history entry does not exist, return
if (!navigation.activation.from) return;

// Only run this if an active view transition exists
if (e.viewTransition) {
const fromUrl = new URL(navigation.activation.from.url);
const currentUrl = new URL(navigation.activation.entry.url);

// Only transition to/from same basePath
// ~> SKIP!
if (!fromUrl.pathname.startsWith(basePath)) {
e.viewTransition.skipTransition();
}

chrisdavidmills marked this conversation as resolved.
Show resolved Hide resolved
// Went from profile page to homepage
// ~> Set VT names on the relevant list item
if (isProfilePage(fromUrl) && isHomePage(currentUrl)) {
const profile = extractProfileNameFromUrl(fromUrl);

setTemporaryViewTransitionNames(
[
[document.querySelector(`#${profile} span`), "name"],
[document.querySelector(`#${profile} img`), "avatar"],
],
e.viewTransition.ready,
);
chrisdavidmills marked this conversation as resolved.
Show resolved Hide resolved
}

// Went to profile page
// ~> Set VT names on the main title and image
if (isProfilePage(currentUrl)) {
setTemporaryViewTransitionNames(
[
[document.querySelector(`#detail main h1`), "name"],
[document.querySelector(`#detail main img`), "avatar"],
],
e.viewTransition.ready,
);
chrisdavidmills marked this conversation as resolved.
Show resolved Hide resolved
}
}
});
```

> **Note:** See [List of Chrome Dev Rel team members](https://view-transitions.netlify.app/profiles/mpa/) for the live demo this code is taken from.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Navigation API](/en-US/docs/Web/API/Navigation_API)
- [View Transitions API](/en-US/docs/Web/API/View_Transitions_API)
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: "NavigationActivation: navigationType property"
short-title: navigationType
slug: Web/API/NavigationActivation/navigationType
page-type: web-api-instance-property
status:
- experimental
browser-compat: api.NavigationActivation.navigationType
---

{{APIRef("Navigation API")}}{{SeeCompatTable}}

The **`navigationType`** read-only property of the {{domxref("NavigationActivation")}} interface contains a string indicating the type of navigation.

## Value

A string representing the type of navigation the {{domxref("NavigationActivation")}} relates to. Possible values are:

- `push`: A new location was navigated to, causing a new entry to be pushed onto the history list.
- `reload`: The {{domxref("NavigationActivation.entry")}} was reloaded.
- `replace`: The {{domxref("NavigationActivation.entry")}} was replaced with a new history entry. This new entry will reuse the same {{domxref("NavigationHistoryEntry.key", "key")}}, but be assigned a different {{domxref("NavigationHistoryEntry.id", "id")}}.
- `traverse`: The browser navigated from one existing history entry to another existing history entry.

## Examples

```js
window.addEventListener("pageswap", (event) => {
// For example, the page was hidden, or the navigation is cross-document.
if (!event.viewTransition) return;

// Skip the view transition for back/forward navigations.
if (event.activation.navigationType === "traverse") {
event.viewTransition.skipTransition();
}
});
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Navigation API](/en-US/docs/Web/API/Navigation_API)
- [View Transitions API](/en-US/docs/Web/API/View_Transitions_API)
98 changes: 98 additions & 0 deletions files/en-us/web/api/pagerevealevent/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
title: PageRevealEvent
slug: Web/API/PageRevealEvent
page-type: web-api-interface
status:
- experimental
browser-compat: api.PageRevealEvent
---

{{APIRef("HTML DOM")}}{{SeeCompatTable}}

The **`PageRevealEvent`** event object is made available inside handler functions for the {{domxref("Window.pagereveal_event", "pagereveal")}} event.

During a cross-document navigation, it allows you to manipulate a related [view transition](/en-US/docs/Web/API/View_Transitions_API) (providing access to the relevant {{domxref("ViewTransition")}} object) from the document being navigated _to_, if a view transition was triggered by the navigation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably say a word about it regardless of view-transitions. It's equivalent to the first requestAnimationFrame() after a cross-document navigation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand on this? I'm not sure I 100% understand it. Are you saying that the event itself is equivalent to the first requestAnimationFrame() after a cross-document navigation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly, it's roughly equivalent to something like this in the head:

function reveal() { ... }
/* This will fire in the first rendered frame after loading */
requestAnimationFrame(() => reveal());
/* This will fire if the page is restored from BFCache */
window.onpagehide = () => requestAnimationFrame(() => reveal());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think readers will find this confusing, and ask questions about how requestAnimationFrame() is involved in the view transition. Is a rAF() call use internally to run the animation — is that what you are saying? And how is that useful to the developer? Can they so something beneficial with that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A common use case for this outside of view-transitions is something like a startup animation. You wait for the first frame (either the first frame at load or after BFCache-restore) using the pagereveal event. I'd say it would also be the appropriate place to do something like reporting a page view.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I understand this now, and have added it to the page.


Outside view transitions, this event is also useful for cases such as triggering a startup animation, or reporting a page view. It's equivalent to the first {{domxref("Window.requestAnimationFrame()")}} run after a cross-document navigation, if you were to trigger `requestAnimationFrame()` in the {{htmlelement("head")}} of the document. For example, if you ran the following `reveal()` function in the `<head>`:

```js
function reveal() {
// Include startup animation here
}
/* This will fire in the first rendered frame after loading */
requestAnimationFrame(() => reveal());

/* This will fire if the page is restored from BFCache */
window.onpagehide = () => requestAnimationFrame(() => reveal());
```

## Constructor

- {{domxref("PageRevealEvent.PageRevealEvent", "PageRevealEvent()")}}
- : Creates a new {{domxref("PageRevealEvent")}} object instance.

## Instance properties

- {{domxref("PageRevealEvent.viewTransition", "viewTransition")}} {{ReadOnlyInline}} {{Experimental_Inline}}
- : Contains a {{domxref("ViewTransition")}} object representing the active view transition for the cross-document navigation.

## Examples

```js
window.addEventListener("pagereveal", async (e) => {
// If the "from" history entry does not exist, return
if (!navigation.activation.from) return;

// Only run this if an active view transition exists
if (e.viewTransition) {
const fromUrl = new URL(navigation.activation.from.url);
const currentUrl = new URL(navigation.activation.entry.url);

// Only transition to/from same basePath
// ~> SKIP!
if (!fromUrl.pathname.startsWith(basePath)) {
e.viewTransition.skipTransition();
}

chrisdavidmills marked this conversation as resolved.
Show resolved Hide resolved
// Went from profile page to homepage
// ~> Set VT names on the relevant list item
if (isProfilePage(fromUrl) && isHomePage(currentUrl)) {
const profile = extractProfileNameFromUrl(fromUrl);

setTemporaryViewTransitionNames(
[
[document.querySelector(`#${profile} span`), "name"],
[document.querySelector(`#${profile} img`), "avatar"],
],
e.viewTransition.ready,
);
chrisdavidmills marked this conversation as resolved.
Show resolved Hide resolved
}

// Went to profile page
// ~> Set VT names on the main title and image
if (isProfilePage(currentUrl)) {
setTemporaryViewTransitionNames(
[
[document.querySelector(`#detail main h1`), "name"],
[document.querySelector(`#detail main img`), "avatar"],
],
e.viewTransition.ready,
);
chrisdavidmills marked this conversation as resolved.
Show resolved Hide resolved
}
}
});
```

> **Note:** See [List of Chrome Dev Rel team members](https://view-transitions.netlify.app/profiles/mpa/) for the live demo this code is taken from.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [View Transitions API](/en-US/docs/Web/API/View_Transitions_API)
Loading