-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Navigation API: deferred commit #10919
base: main
Are you sure you want to change the base?
Conversation
This adds `navigateEvent.prototype.intercept({commit: "after-transition"})`, as well as `NavigateEvent.prototype.commit()`. Instead of always "committing" the navigation immediately, we refer to this interception option. If it's the default ("immediate"), the existing behavior is invoked. The new "after-transition" behavior keeps the navigation un-committed, until `NavigateEvent.prototype.commit()` is called. This follows roughly the same semantics of `scroll`. See https://github.com/WICG/navigation-api/blob/main/README.md#deferred-commit
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.
Thanks so much for working on this!!!
This is missing the behavior of auto-committing when all finished promises fulfill. See https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/navigation_api/navigate_event.cc;l=338;drc=3b5e9130048e66ce39338d34f99751d0a2346e9c for the counterpart Chromium code.
@@ -95428,6 +95430,11 @@ enum <dfn enum>NavigationScrollBehavior</dfn> { | |||
"<dfn enum-value for="NavigationScrollBehavior" data-x="dom-NavigationScrollBehavior-manual">manual</dfn>" | |||
}; | |||
|
|||
enum <dfn enum>NavigationCommitBehavior</dfn> { | |||
"<dfn enum-value for="NavigationCommitBehavior" data-x="dom-NavigationCommitBehavior-after-transition">after-transition</dfn>", | |||
"<dfn enum-value for="NavigationCommitBehavior" data-x="dom-NavigationCommitBehavior-immediate">immediate</dfn>", |
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.
"<dfn enum-value for="NavigationCommitBehavior" data-x="dom-NavigationCommitBehavior-immediate">immediate</dfn>", | |
"<dfn enum-value for="NavigationCommitBehavior" data-x="dom-NavigationCommitBehavior-immediate">immediate</dfn>" |
browser UI, such as the URL address bar, and call the <code | ||
data-x="dom-NavigationInterceptOptions-handler">handler</code>.</p> |
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.
I think this should be " and update the browser UI, such as the location bar". Especially we should not talk about calling handler as handler is always called immediately.
|
||
<p>The <code data-x="dom-NavigationInterceptOptions-commit">commit</code> option can be set to | ||
"<code data-x="dom-NavigationCommitBehavior-after-transition">after-transition</code>" to | ||
turn defer these default outcome of the navigation until <code |
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.
turn defer these default outcome of the navigation until <code | |
defer these parts of the navigation until <code |
<code>DOMException</code> if called on a <code>NavigateEvent</code> that has already been | ||
committed due to the default "<code | ||
data-x="dom-NavigationCommitBehavior-immediate">immediate</code>" commit behavior, if called | ||
more than once, or if called synchronously, during event dispatch.</p> |
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.
I think it will also throw if it's called after all promises returned from the handlers are settled? I think that's important to emphasize, as the idea is to call it during the promise delay time.
<code data-x="dom-NavigateEvent-intercept">intercept()</code> was overridden by this new value, | ||
and the previous value will be ignored.</p></li> | ||
|
||
<li><p>Set <span>this</span>'s <span data-x="concept-NavigateEvent-commit">scroll |
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.
<li><p>Set <span>this</span>'s <span data-x="concept-NavigateEvent-commit">scroll | |
<li><p>Set <span>this</span>'s <span data-x="concept-NavigateEvent-commit">commit |
@@ -95700,6 +95734,25 @@ callback <dfn callback>NavigationInterceptHandler</dfn> = <span data-x="idl-Prom | |||
data-x="dom-NavigationInterceptOptions-scroll">scroll</code>"].</p></li> | |||
</ol> | |||
</li> |
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.
Maybe mention how scroll() must be called after commit(), if using after-transition commit behavior? Or maybe that's too detailed, not sure.
<var>navigationType</var>, whose <span data-x="concept-NavigationTransition-from">from entry</span> | ||
is <var>fromNHE</var>, and whose <span data-x="concept-NavigationTransition-finished">finished | ||
promise</span> is a new promise created in <var>navigation</var>'s <span | ||
data-x="concept-relevant-realm">relevant realm</span>.</p></li> |
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.
I think this should be left in the event dispatch algorithm, and not delayed until commit. The transition represents the not-yet-committed state.
I believe this matches the Chromium implementation, and is tested by https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/navigation-api/ordering-and-transition/navigate-commit-after-transition-intercept.html;l=48-50;drc=3b5e9130048e66ce39338d34f99751d0a2346e9c which shows the event.transition
object being set appropriately even before location.hash
is updated.
This adds
navigateEvent.prototype.intercept({commit: "after-transition"})
, as well asNavigateEvent.prototype.commit()
.Instead of always "committing" the navigation immediately, we refer to this interception option. If it's the default ("immediate"), the existing behavior is invoked.
The new "after-transition" behavior keeps the navigation un-committed, until
NavigateEvent.prototype.commit()
is called.This follows roughly the same semantics of
scroll
.See https://github.com/WICG/navigation-api/blob/main/README.md#deferred-commit
(See WHATWG Working Mode: Changes for more details.)
/nav-history-apis.html ( diff )