-
Notifications
You must be signed in to change notification settings - Fork 19
Focus on What Hurts Most: AsyncContext for await as a First Step #124
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
Comments
For what it's worth, some of the aspects of the current web integration proposal would be very hard to polyfill. For example, if you do I believe the way Zone.js polyfills that is by patching everything so that the actual message sent contains a context ID, and by patching I believe there might also be cases where there really would be no way to polyfill the context accurately in userland, but I don't have any examples of that right now.
The main problem we're having with the web integration part of this proposal isn't that it needs to be done together with the Even if we add at some later point a deep propagation flag, the problems of figuring out how everything should behave, and the complexity of implementing it all at once don't go away. Even if we add deep propagation later on with such a flag, the entirety of the deep propagation would need to be added at once. Otherwise, rather than a flag, you'd need to have something like a version level, which would need to be increased with every single incremental update to how the web integration works. |
Uh oh!
There was an error while loading. Please reload this page.
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 — namelyasync/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 — justasync/await
and Promises.Focus the Proposal on What Cannot Be Polyfilled
A minimal version of
AsyncContext
— one that only targets native Promises andawait
— would provide immense value and interoperability across libraries. It would also: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 thatstartTransition()
loses context only acrossawait
. If this proposal focused solely on Promises andawait
, 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 ascaptureLevel
, 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 onawait
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!
The text was updated successfully, but these errors were encountered: