Skip to content

Navigation API: Don't run navigation handlers until entry is committed.#12256

Open
farre wants to merge 1 commit intowhatwg:mainfrom
farre:issue/12222/1
Open

Navigation API: Don't run navigation handlers until entry is committed.#12256
farre wants to merge 1 commit intowhatwg:mainfrom
farre:issue/12222/1

Conversation

@farre
Copy link
Contributor

@farre farre commented Mar 12, 2026

Currently per spec, #update-the-navigation-api-entries-for-a-same-document-navigation will be called in different order to the #wait-for-all navigation handler list depending on if the navigation is intercepted or not. This is not ideal, but even more so, in case of a "traverse" navigation, the callback passed to the #wait-for-all and the might be called before the call to #update-the-navigation-api-entries-for-a-same-document-navigation has happened.

This means that we'll run the finish steps with the wrong session history entry.

Since all same document navigations, intercepted or otherwise, eventually call #update-the-navigation-api-entries-for-a-same-document-navigation we can ensure that we never run the navigation handlers with bad state.

This patch also reverts the patch that introduced always having a method tracker, since that was intended to solve this issue but failed doing so.

Fixes #12222, and #12165. Reverts #11814.

  • At least two implementers are interested (and none opposed):
    • N/A. All major engines handle this issue in a some fashion, otherwise "traverse" navigations would be utterly broken. It could possibly be editorial if you squint hard enough, but given that it's quite a substantial change I think it needs a bit more thorough vetting.
  • Tests are written and can be reviewed and commented upon at:
    • This should not change any test results
  • Implementation bugs are filed:
  • Corresponding HTML AAM & ARIA in HTML issues & PRs: N/A
  • MDN issue is filed: N/A
  • 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 )

Currently per spec, #update-the-navigation-api-entries-for-a-same-document-navigation
will be called in different order to the #wait-for-all navigation handler
list depending on if the navigation is intercepted or not. This is not
ideal, but even more so, in case of a "traverse" navigation, the
callback passed to the #wait-for-all and the might be called before
the call to #update-the-navigation-api-entries-for-a-same-document-navigation
has happened.

This means that we'll run the finish steps with the wrong session
history entry.

Since all same document navigations, intercepted or otherwise, eventually
call #update-the-navigation-api-entries-for-a-same-document-navigation
we can ensure that we never run the navigation handlers with bad state.

This patch also reverts the patch that introduced always having a
method tracker, since that was intended to solve this issue but
failed doing so.

Fixes whatwg#12222, and whatwg#12165. Reverts whatwg#11814.
Copy link
Collaborator

@noamr noamr left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for digging in to this!


<li><p>Let <var>navigateEvent</var> be <var>navigation</var>'s <span>ongoing <code
data-x="event-navigate">navigate</code> event</span>.</p></li>
<li><p>Let <var>apiMethodTracker</var> be <var>navigation</var>'s <span>ongoing API method tracker</span></p></li>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<li><p>Let <var>apiMethodTracker</var> be <var>navigation</var>'s <span>ongoing API method tracker</span></p></li>
<li><p>Let <var>apiMethodTracker</var> be <var>navigation</var>'s <span>ongoing API method tracker</span></p></li>

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

Development

Successfully merging this pull request may close these issues.

#commit-a-navigate-event needs to defer calling intercept handlers.

2 participants