Skip to content

AsyncContext proposal integration - #13063

Open
nicolo-ribaudo wants to merge 20 commits into
whatwg:mainfrom
nicolo-ribaudo:async-context/html-pr
Open

nicolo-ribaudo wants to merge 20 commits into
whatwg:mainfrom
nicolo-ribaudo:async-context/html-pr

Conversation

@nicolo-ribaudo

@nicolo-ribaudo nicolo-ribaudo commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Ref #10432

This PR integrates the AsyncContext proposal into HTML APIs. This PR includes:

  • basic refs to the proposal
  • propagation through APIs that take a callback to signal completion
  • propagation through top-level script execution
  • propagation through APIs that fire events (this is what most of the PR is for). A lot of those APIs actually needed no change, because either they are sync or the event is meant to run in the empty context.
  • propagation to custom element reactions

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.md about custom elements.

I am maintaining a gh stack parallel 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:

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 the Expose Async Context Mappings on promise rejection events commit works for them as well as it does for JS-created ones. UPDATE: we might make the change in the ECMAScript proposal instead.


  • 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:
  • MDN issue is filed: …
  • The top of this comment includes a clear commit message to use.

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

andreubotella and others added 19 commits October 12, 2026 14:54
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.
@nicolo-ribaudo

nicolo-ribaudo commented Oct 20, 2026 •

Copy link
Copy Markdown
Member Author

I updated the PR (and PR description) to also cover custom element reactions. That was the last big piece missing.

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