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

Navigation API: deferred commit #10919

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Navigation API: deferred commit #10919

wants to merge 2 commits into from

Conversation

noamr
Copy link
Contributor

@noamr noamr commented Jan 16, 2025

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

  • At least two implementers are interested (and none opposed):
  • Tests are written and can be reviewed and commented upon at:
  • Implementation bugs are filed:
    • Chromium:
    • Gecko: …
    • WebKit: …
    • Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): …
    • Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): …
  • Corresponding HTML AAM & ARIA in HTML issues & PRs: N/A, no HTML elements involved in this
  • MDN issue is filed: Will be done as part of Chromium beta launch
  • The top of this comment includes a clear commit message to use.

(See WHATWG Working Mode: Changes for more details.)


/nav-history-apis.html ( diff )

noamr added 2 commits January 16, 2025 12:16
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
@noamr noamr requested a review from domenic January 16, 2025 12:31
Copy link
Member

@domenic domenic left a 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>",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"<dfn enum-value for="NavigationCommitBehavior" data-x="dom-NavigationCommitBehavior-immediate">immediate</dfn>",
"<dfn enum-value for="NavigationCommitBehavior" data-x="dom-NavigationCommitBehavior-immediate">immediate</dfn>"

Comment on lines +95570 to +95571
browser UI, such as the URL address bar, and call the <code
data-x="dom-NavigationInterceptOptions-handler">handler</code>.</p>
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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>
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<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>
Copy link
Member

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>
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants