feat: remove async_hooks polyfill, use native workerd implementation#10243
feat: remove async_hooks polyfill, use native workerd implementation#10243petebacondarwin merged 3 commits intomainfrom
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
🦋 Changeset detectedLatest commit: 2b91389 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
|
Failed to automatically backport this PR's changes to Wrangler v3. Please manually create a PR targeting the Depending on your changes, running Notes:
|
- Move async_hooks from hybridModules to nativeModules in unenv-preset - Remove async_hooks polyfill implementation file - Add comprehensive tests for AsyncLocalStorage and AsyncResource - Verify native workerd async_hooks APIs work correctly Fixes #10239 Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
- Remove implementation details from changeset - Keep description brief and targeted at tool users - Address PR feedback from @petebacondarwin Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
6f4e350 to
0a8d741
Compare
| "_tls_wrap", | ||
| "assert", | ||
| "assert/strict", | ||
| "async_hooks", |
There was a problem hiding this comment.
Does workerd implement the full async_hooks package? The documentation states:
Workers does not implement the full async_hooks ↗ API upon which Node.js' implementation of AsyncLocalStorage is built.
There was a problem hiding this comment.
It implements all the methods that we were polyfilling.
|
Congratulations @devin-ai-integration[bot], the maintainer of this repository has issued you a holobyte! Here it is: https://holopin.io/holobyte/cme1jtzwt335607l7xnv2psof This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. |
Fixes #10239
This PR removes the
async_hookspolyfill from the unenv-preset package and switches to using the native workerd implementation. The change is based on the fact that workerd now provides native support for async_hooks APIs, making the polyfill unnecessary.Changes Made
async_hooksfromhybridModulestonativeModulesinpackages/unenv-preset/src/preset.tspackages/unenv-preset/src/runtime/node/async_hooks.tsasync_hooksin the native modules listKey Findings
The native workerd implementation provides:
AsyncLocalStorage(the most commonly used API)AsyncResourcecreateHook,executionAsyncId, etc. for backward compatibilityasyncId()andtriggerAsyncId()are not implementedTesting
Added two comprehensive test functions:
testAsyncHooks()- Tests AsyncLocalStorage, AsyncResource constructor, and stub APIstestAsyncHooksRequire()- Tests CommonJS require pattern compatibilityAll e2e tests pass (180 tests) confirming that the native implementation works correctly.
Review Focus Areas
asyncId()/triggerAsyncId()methods won't cause issuesLink to Devin run: https://app.devin.ai/sessions/d91bc6320b194eaa8db8a6715a8e9db5
Requested by: @petebacondarwin