-
-
Notifications
You must be signed in to change notification settings - Fork 188
fix(rsc): inject AsyncLocalStorage
global via transform
#785
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
fix(rsc): inject AsyncLocalStorage
global via transform
#785
Conversation
// for build, we cannot use `import` as it confuses rollup commonjs plugin. | ||
return ( | ||
(this.environment.mode === 'build' && !isRolldownVite | ||
? `const __viteRscAyncHooks = require("node:async_hooks");` | ||
: `import * as __viteRscAyncHooks from "node:async_hooks";`) + | ||
`globalThis.AsyncLocalStorage = __viteRscAyncHooks.AsyncLocalStorage;` + | ||
code | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, it feels as hacky as before, but probably alright.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, maybe you'd like to be warned about a little typo : __viteRscAyncHooks (should probably be __viteRscAsyncHooks)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, good catch. PR welcome :)
Description
AsyncLocalStorage
properly on non runnable environment #784In old days, we have externalized react on
ssr
environment, so it's not possible to inject through transform, but now it's possible.