-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Suggestion for Narrowing Scope of AsyncContext to Its Core Use Case (for TC39 108th Meeting)
In light of @andreubotella’s upcoming presentation “How to simplify the web integration”, I’d like to respectfully propose narrowing the initial scope of the AsyncContext
proposal to the most critical and unpolyfillable parts of async context propagation — namely async/await
and Promises (and possibly async generators).
I raised a related issue earlier (#65) and, while it received some pushback at the time, I’d like to reintroduce the idea for further consideration. My intention is to help ensure this proposal delivers maximum impact with minimal complexity.
A Personal Stake: Dexie.js and Its Limitations
As the author of Dexie.js — a widely used IndexedDB wrapper featured in apps such as ChatGPT, WhatsApp Web, and Facebook Messenger — I deeply appreciate this proposal. Dexie uses its own internal async context to manage transactions and live queries. However, due to the absence of a standard, Dexie cannot interoperate with libraries like OpenTelemetry or Zone.js, which rely on their own workarounds.
This incompatibility directly stems from the lack of a consistent, standard way to track async context across await
boundaries. Dexie and many other libraries don’t need the full machinery of async context for every possible async API — just async/await
and Promises.
Focus the Proposal on What Cannot Be Polyfilled
A minimal version of AsyncContext
— one that only targets native Promises and await
— would provide immense value and interoperability across libraries. It would also:
- Accelerate browser vendor adoption
- Reduce cognitive overhead for developers
- Preserve room for future opt-in complexity (e.g.,
setTimeout
,EventTarget
, etc.)
Libraries like Zone.js have already demonstrated that most web APIs can be polyfilled effectively — except await
. That one gap is what this proposal is uniquely positioned to fill.
What Would React Do?
The React section in FRAMEWORKS.md
points out that startTransition()
loses context only across await
. If this proposal focused solely on Promises and await
, React’s issue could be addressed without introducing additional complexity. Limitations (e.g. lack of support for timers or event listeners) could be clearly documented for now.
What About Solid, Svelte, and Vue?
As reflected in FRAMEWORKS.md, these frameworks primarily care about preserving context across await
. Supporting that alone would already unblock many current use cases.
What About OpenTelemetry?
OpenTelemetry for web depends on Zone.js, which successfully polyfills all but one async behavior: await
. This single missing link means users must transpile all their async functions — a fragile and complex workaround.
By standardizing async context for await
, we can eliminate this barrier and provide out-of-the-box support for libraries like OpenTelemetry in the browser — a major win for both observability and DX.
Can Implicit Context Propagation Be Added Later?
Yes, the proposal’s current form already leaves the door open to future extensions. For example, AsyncVariableOptions
could be extended in the future with an additional option such as captureLevel
, enabling opt-in deep propagation when desired.
This path allows TC39 to ship a minimal core that solves the hardest problem now, while keeping future complexity opt-in and backwards-compatible.
Conclusion
A narrowly scoped AsyncContext
— focused on await
and Promises — would already unlock massive value for libraries, frameworks, and developers, while simplifying both implementation and mental models.
Thank you for the ongoing work on this proposal. I’m happy to elaborate further or assist in any way that’s helpful!