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

[css-view-transitions-1] Defer restoring persisted state until after capturing old state #9676

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions css-view-transitions-1/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ spec:css-display-4; type: dfn; text:invisible;
urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
text: NavigateEvent
text: signal; for: NavigateEvent; url: #ref-for-dom-navigateevent-signal①
urlPrefix: https://html.spec.whatwg.org/multipage/; spec: html; type: dfn;
text: restore persisted state; url: #restore-persisted-state
text: active session history entry; url: #nav-active-history-entry
</pre>

<script async type="module" src="diagrams/resources/scaler.js"></script>
Expand Down Expand Up @@ -1094,6 +1097,18 @@ urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
Initially null.

Note: this is used for cross-document view transitions.

: <dfn>persisted state restoration</dfn>
:: One of the following, initially "`defer`":
Copy link
Member

Choose a reason for hiding this comment

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

Do we have scroll restoration in the spec for cross-document navigations?


1. "`defer`".
1. "`pending`".
1. "`immediate`".

Note: this is used to defer automatic restoration of persisted state, e.g. scroll position,
Copy link
Member

Choose a reason for hiding this comment

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

Can you add what immediate implies as well?

to be performed after the old state is captured. When in the "`defer`" mode, persisted state
is not yet requested, but should be deferred if requested. When in the "`pending`" mode,
persisted state restoration is requested and should be performed once the old state is captured.
</dl>

A {{ViewTransition}} must never have both an [=ViewTransition/update callback=] and a [=ViewTransition/process old state captured=].
Expand Down Expand Up @@ -1252,10 +1267,16 @@ urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
If failure is returned, then [=skip the view transition=] for |transition| with an "{{InvalidStateError}}" {{DOMException}} in |transition|'s [=relevant Realm=],
and return.

1. [=Resolve persisted state restoration=] for |transition|.
Copy link
Member

Choose a reason for hiding this comment

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

We should do this in the skip case as well.


1. If |transition|'s [=ViewTransition/process old state captured=] is not null, then call [=ViewTransition/process old state captured=] and return.

1. Set |document|'s [=document/rendering suppression for view transitions=] to true.

1. Set |transition|'s [=ViewTransition/persisted state restoration=] to "`immediate`".

Note: Now that the old state is captured, synchronous restoring persisted state should behave as normal.

1. [=Queue a global task=] on the [=DOM manipulation task source=],
given |transition|'s [=relevant global object=],
to execute the following steps:
Expand Down Expand Up @@ -1912,6 +1933,23 @@ urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
1. Set |document|'s [=document/active view transition=] to null.
</div>

## [=persisted state restoration=] ## {#persisted-state-restoration-algorithm}

<div algorithm>
To <dfn export>potentially defer persisted state restoration</dfn> for a {{Document}} |document|:

1. Let |transition| be |document|'s [=active view transition=].
1. If |transition| is null or its [=ViewTransition/persisted state restoration=] is "`immediate`", then return "`proceed`".
1. Set |transition|'s [=ViewTransition/persisted state restoration=] to "`pending`".
1. Return "`defer`".
</div>

<div algorithm>
To <dfn>resolve persisted state restoration</dfn> for a {{ViewTransition}} |transition|:
1. If |transition|'s [=ViewTransition/persisted state restoration=] is "`pending`", then
[=restore persisted state=] given |transition|'s [=associated document=]'s [=node navigable=]'s [=active session history entry=].
1. Set |transition|'s [=ViewTransition/persisted state restoration=] to "`immediate`".
</div>
<h2 id="priv" class="no-num">Privacy Considerations</h2>

This specification introduces no new privacy considerations.
Expand Down Expand Up @@ -1940,6 +1978,7 @@ Changes from <a href="https://www.w3.org/TR/2023/WD-css-view-transitions-1-20230
* Copy `color-scheme` from DOM element to ''::view-transition-group()''. See <a href="https://github.com/w3c/csswg-drafts/issues/9276">issue 9276</a>.
* Expose [=auto-skip view transition=] for a {{Document}}, to allow having outbound cross-document transitions preceed programmatic view transiitons. see <a href="https://github.com/w3c/csswg-drafts/issues/9512">issue 9512</a>.
* Add a note about why 'view-transition-name' should be animatable.
* Export an algorithm and add mechanism to defer restoring scroll/persisted state.
Copy link
Member

Choose a reason for hiding this comment

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

Is there a link to an html or csswg issue where this was discussed?


<h3 id="changes-since-2022-05-25">
Changes from <a href="https://www.w3.org/TR/2023/WD-css-view-transitions-1-20230525/">2022-05-25 Working Draft</a>
Expand Down