Skip to content

Navigation API: fix an ordering issue #11512

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

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

Conversation

domenic
Copy link
Member

@domenic domenic commented Jul 31, 2025

Because navigatesuccess/navigateerror events can run JavaScript code, they can change the "ongoing API method tracker" pointer. Thus, it's better to resolve/reject the finished promise for the API method tracker before firing the event.

This does not change the observable order in normal cases: it remains the case that JavaScript event handlers for navigatesuccess/navigateerror run before promise reactions, because promise resolution is always delayed by a microtask. However, it fixes some tricky reentrant cases.


This was discovered by @natechapin in https://chromium-review.googlesource.com/c/chromium/src/+/6622087, while he was implementing the fix from #11409. I'd like his review, as well as ideally @farre's.

I'm still working with Nate on getting clarity on an exact test case that exercises this bug, and what the before/after behavior is. It might be the test case already in https://chromium-review.googlesource.com/c/chromium/src/+/6622087; I'm not sure.

  • At least two implementers are interested (and none opposed):
    • Chromium is interested
    • Probably we can treat this as an obvious bug fix, but let's wait until we have the specific WPT in hand.
  • Tests are written and can be reviewed and commented upon at:
    • TODO
  • Implementation bugs are filed:
    • Chromium: See https://chromium-review.googlesource.com/c/chromium/src/+/6622087
    • Gecko: TODO
    • WebKit: TODO
    • Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): N/A
    • Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): N/A
  • Corresponding HTML AAM & ARIA in HTML issues & PRs: N/A
  • MDN issue is filed: N/A, too niche of an edge case
  • 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 )

domenic added 2 commits July 31, 2025 12:46
Because navigatesuccess/navigateerror events can run JavaScript code, they can change the "ongoing API method tracker" pointer. Thus, it's better to resolve/reject the finished promise for the API method tracker before firing the event.

This does not change the observable order in normal cases: it remains the case that JavaScript event handlers for navigatesuccess/navigateerror run before promise reactions, because promise resolution is always delayed by a microtask. However, it fixes some tricky reentrant cases.
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

This ordering seems like something we should stick with everywhere, though I suppose it really only manifests here because the resolving/rejecting is conditional. But still, consistency is good.

@farre
Copy link
Contributor

farre commented Jul 31, 2025

This looks very reasonable. I wouldn't be surprised if we have the same bug as chromium here.

@natechapin
Copy link

The test in my CL (https://chromium-review.googlesource.com/c/chromium/src/+/6622087) fails the assertion at the start of the promote an upcoming API method tracker to ongoing steps. I haven't isolated a case where a promise resolves incorrectly or anything like that yet, but we definitely are violating spec assertions.

@natechapin
Copy link

I don't have official review permissions, but the spec diffs match what I expected based on my proposed code change.

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.

4 participants