Skip to content

Navigation API: fix an ordering issue#11512

Merged
domenic merged 2 commits into
mainfrom
navigation-api-ordering
Aug 20, 2025
Merged

Navigation API: fix an ordering issue#11512
domenic merged 2 commits into
mainfrom
navigation-api-ordering

Conversation

@domenic

@domenic domenic commented Jul 31, 2025

Copy link
Copy Markdown
Member

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, which currently cause spec assertion failures.


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. Those tests will exercise this code path, and a spec assertion will get hit without this.

(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.

@annevk annevk left a comment

Copy link
Copy Markdown
Member

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

farre commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

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

@natechapin

Copy link
Copy Markdown

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
Copy Markdown

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

@domenic domenic merged commit 93634ae into main Aug 20, 2025
2 checks passed
@domenic domenic deleted the navigation-api-ordering branch August 20, 2025 05:58
@domenic domenic mentioned this pull request Aug 20, 2025
6 tasks
noamr added a commit to noamr/html that referenced this pull request Aug 20, 2025
noamr added a commit that referenced this pull request Aug 20, 2025
atscott added a commit to atscott/angular that referenced this pull request Aug 25, 2025
AndrewKushnir pushed a commit to angular/angular that referenced this pull request Aug 27, 2025
AndrewKushnir pushed a commit to angular/angular that referenced this pull request Aug 27, 2025
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