-
-
Notifications
You must be signed in to change notification settings - Fork 41
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(cloudflare): use React edge renderer for compatibility with React 19 #436
base: main
Are you sure you want to change the base?
Conversation
React 19 requires MessageChannel from node:worker_threads, which isn't available in Cloudflare's workerd runtime. Switch to React's edge-optimized server renderer to avoid MessageChannel dependency.
🦋 Changeset detectedLatest commit: 86d1ac5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 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 |
Can I interest @alexanderniebuhr or @bholmesdev in a review? |
This breaks for React 18? I think we could probably simply remove the alias altogether, it has this exports: "./server": {
"deno": "./server.browser.js",
"worker": "./server.browser.js",
"browser": "./server.browser.js",
"default": "./server.node.js"
}, And the cloudflare vite config will respect worker or browser conditions already. So it should load the right entrypoint. |
Removing the alias doesn't work, unfortunately. Here's what will happen. React 18:
React 19:
The correct files are loaded even without the alias (as you suggested), but something else breaks. I guess that's why the alias was added in the first place. Also, you're right that my change actually breaks React 18. 😕
We need a better fix. |
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.
Blocking, since this doesn't work for all versions, to avoid accidental merge.
React 19 requires
MessageChannel
from node:worker_threads, which isn't available in Cloudflare's workerd runtime. Switch to React's edge-optimized server renderer to avoid the MessageChannel dependency.More background
Trying to use
useActionState
from React 19 as described here currently results inUncaught ReferenceError: MessageChannel is not defined
when workerd is involved.Rather than polyfilling
MessageChannel
and its dependencies, e.g. via unenv, I found that switching the renderer is much easier.The edge renderer probably makes more sense at the edge anyway (😄), though I don't know if the browser variant was initially chosen for a specific reason.