-
Notifications
You must be signed in to change notification settings - Fork 330
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
Runtime APIs: MessageChannel #3273
Comments
Relabeling this as a feature request. The fact that we currently do not support |
First of all, thank you for a clear reproduction @phase! It helped me a lot understand what's going on. Secondly, I agree with @jasnell that supporting MessageChannel in workerd is indeed non-trivial because it doesn't fit the rest of the runtime well. Browsers and node can create new JS contexts at will via iframes or However, looking at this issue more deeply, i think the root cause of the failures in Astro and React is not that we don't support MessageChannel API, but rather that the bundlers somehow erroneously picks up I think we should get to the bottom of how these modules are resolved and resolve them correctly to address the Astro/React issue. |
After discussing a bit internally, I think we will likely implement |
My guess is that they use |
|
The workaround for when you need low latency tasks is to use MessageChannel API which is not throttled like this. |
Anyway, the point here is that due to some kind of build misconfiguration workerd is fed with js files intended specifically for browsers and not for servers which means that we might see additional issues due to this bundling issue and we should address that. I can have @dario-piotrowicz dig into this next week. |
Pretty sure this is why https://github.com/cloudflare/workers-sdk/blob/dc2ab3578956be656064cbfc7cc3e92bdae43092/packages/wrangler/src/deployment-bundle/bundle.ts#L66 |
I'm not so sure @Skye-31. I initially thought the same, but then I noticed two things: The And @phase mentioned in withastro/astro#12824 (comment) that the following alias resolves the issue: vite: {
resolve: {
// Use react-dom/server.edge instead of react-dom/server.browser for React 19.
// Without this, MessageChannel from node:worker_threads needs to be polyfilled.
alias: import.meta.env.PROD && {
"react-dom/server": "react-dom/server.edge",
},
},
}, Given the workaround, my thinking is that this has nothing to do with Wrangler, and instead the app is bundled incorrectly with Vite in Astro. Possibly because the resolution conditions in the Astro Vite config are misconfigured? At least that would explain why overriding the vite config in |
I debugged this and found bugs in the Astro adapter that is causing the original MessageChannel issue: withastro/astro#12824 (comment) |
The MessageChannel API is available on node but not CF Workers. This is causing an issue during the deployment of sites using React 19 + Astro + Workers, see facebook/react#31827 and withastro/astro#12824. The usage of this API may be a bug for this use case (meaning the solution there may be to stop using MessageChannel), but workerd may want to support it anyway.
I made a repository with steps to reproduce the crash mentioned in those issues here: https://github.com/phase/test-astro-react19-cf-workers
The text was updated successfully, but these errors were encountered: