Repository navigation
AsyncContext proposal integration - #13063
Open
nicolo-ribaudo wants to merge 20 commits into
Open
nicolo-ribaudo wants to merge 20 commits into
nicolo-ribaudo wants to merge 20 commits into
Conversation
This PR updates HTML to integrate with the TC39 AsyncContext proposal, which allows storing state associated with an async flow of execution in JavaScript, and preserving it across different kinds of async continuations in both JS and the web platform. This PR does not yet handle events, since the exact behavior of those with AsyncContext is still pending to be fully decided. But it covers microtasks, timers, deferred script execution, focus/blur and others. This patch does not include any changes to the `error` and `unhandledrejection` event handling, as well as to `HostEnqueueFinalizationRegistryCleanupJob`. This relies on the assumption that the changes in tc39/proposal-async-context#148 and tc39/proposal-async-context#150 will be accepted. Otherwise, error contexts will need to be handled in HTML. This patch relies on PR [TODO] to define the `[PropagatesAsyncContext]` extended attribute in WebIDL.
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
The mapping captured when the container navigates is threaded through navigate and attempt to populate the history entry's document, stored on the created Document, and consumed by completely finish loading a document to fire the load event on the container. Navigations initiated inside the frame reach navigate without the argument, so their load events do not inherit the embedder's context. The frame element is covered transitively, since navigate an iframe or frame is shared. Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
Co-Authored-By: Nicolò Ribaudo <nribaudo@igalia.com>
The details, dialog and popover elements all queue their toggle event through a toggle task tracker. The various algorithms to queue firing those events (which are always run synchronously with the mutation) capture the context and use it to actually fire the event. Closing a dialog captures once and uses the same mapping for both the toggle event and the close event. beforetoggle and cancel are fired synchronously and so are already transparent to AsyncContext.
This was referenced Oct 12, 2026
Member
Author
|
I updated the PR (and PR description) to also cover custom element reactions. That was the last big piece missing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ref #10432
This PR integrates the AsyncContext proposal into HTML APIs. This PR includes:
It follows the design decisions discussed at past WHATNOT meetings, and written down in https://github.com/tc39/proposal-async-context/blob/master/WEB-INTEGRATION.md / https://github.com/tc39/proposal-async-context/blob/master/web-integration/html__events.md
For custom element reactions it follows what's currently described in detail in tc39/proposal-async-context#158. That's a new document, but it's the behavior we get by applying the two bullet points we had in
WEB-INTEGRATION.mdabout custom elements.I am maintaining a
gh stackparallel to this PR with the same changes at https://github.com/nicolo-ribaudo/html/pulls?q=sort%3Acreated-desc%20is%3Apr%20label%3A%22async%20context%22: it was originally there to help myself with tracking the status of what I was doing, but I believe it can also be useful for reviewers to see more detailed context behind why some changes are the way they are (each of those PRs has a semi-detailed list of decisions and things to test in WPT).There currently are some open questions:
[PropagatesAsyncContextToEvents]extended attribute defined in AsyncContext propagation to events dom#1451 or not, as at least for HTML the benefits are not super clear. PRs in the stack that use it are at https://github.com/nicolo-ribaudo/html/issues?q=sort%3Acreated-desc%20label%3A%22uses%20PropagatesAsyncContextToEvents%22.<img>and media element algorithms with regards to the exact timing that something happens.EventSourceconstructor alive for as long as that connection is open / being reopened (Propagate AsyncContext for EventSource events nicolo-ribaudo/html#11)Corresponding PRs in other specs that need to land at the same time (they cyclically depend on each other) are whatwg/webidl#1568 and whatwg/dom#1451.
I also have a pending WebIDL PR to open to capture the context for rejection in WebIDL-managed promises, so that theUPDATE: we might make the change in the ECMAScript proposal instead.Expose Async Context Mappings on promise rejection eventscommit works for them as well as it does for JS-created ones.(See WHATWG Working Mode: Changes for more details.)
/browsing-the-web.html ( diff )
/canvas.html ( diff )
/custom-elements.html ( diff )
/dnd.html ( diff )
/document-lifecycle.html ( diff )
/dom.html ( diff )
/iframe-embed-object.html ( diff )
/imagebitmap-and-animations.html ( diff )
/images.html ( diff )
/index.html ( diff )
/infrastructure.html ( diff )
/input.html ( diff )
/interaction.html ( diff )
/interactive-elements.html ( diff )
/links.html ( diff )
/media.html ( diff )
/obsolete.html ( diff )
/popover.html ( diff )
/references.html ( diff )
/scripting.html ( diff )
/semantics.html ( diff )
/server-sent-events.html ( diff )
/timers-and-user-prompts.html ( diff )
/webappapis.html ( diff )
/workers.html ( diff )