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
base: main
Are you sure you want to change the base?
Conversation
When starting a view transition right before state restoration, e.g. `addEventListener("popstate", () => startViewTransition(() => {...}))`, according to the current spec the scroll position would be restored before the `startViewTransition` callback is called, which means that it would be captured as part of the old state, even though it belongs to the new state. This change makes it so that we defer persisted state restoration until after the old state is captured. Together with w3c/csswg-drafts#9676
css-view-transitions-1/Overview.bs
Outdated
@@ -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: latest entry; url: #latest-entry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of poking into HTML's externals, try to get whatwg/html#9996 to export the appropriate parts.
(I'm a bit scared of exporting "latest entry" though, since it's a pretty low-level detail... document's node navigable's active session history entry would be a more public API. Maybe it's the same thing in this case?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have the html spec PR which will use this? Would help to review that together with this.
1. "`pending`". | ||
1. "`immediate`". | ||
|
||
Note: this is used to defer automatic restoration of persisted state, e.g. scroll position, |
There was a problem hiding this comment.
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?
@@ -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|. |
There was a problem hiding this comment.
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.
@@ -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`": |
There was a problem hiding this comment.
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?
|
@@ -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. |
There was a problem hiding this comment.
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?
This fixes an issue that the spec restores the persisted state (e.g. scroll position) too eagerly, e.g. when calling
document.startViewTransition
inside apopstate
handler, not giving the UA an opportunity to first capture the old state.This exports an algorithm that should be called from the HTML spec when ready to automatically restore persisted state, e.g. after
popstate
. If the algorithm returns true, proceed as normal, otherwise the state will be restored after capturing the old state.