-
-
Notifications
You must be signed in to change notification settings - Fork 630
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
Conditionally require react-dom/client in reactHydrate/reactRender if React version >= 18 #1448
Conversation
… React version >= 18
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.
@summera Thanks for your contribution!
Unfortunately, it's failing CI.
Looks like the require("react-dom/client")
even though /spec/dummy/yarn.lock
's version of r react-dom is v16.
I'm not sure what the solution is.
Maybe
const reactDomSrc = supportsReactCreateRoot ? "react-dom/client" : "react-dom";
require(reactDomSrc);
???
@Judahmeek unfortunately doing that results in the following errors:
If the approach taken by @tomdracz in #1449 works, I suggest we close this out in favor of that PR. |
Think mine might suffer from similar issues, although the warnings are perhaps ok to ignore. With the way React made it quite hard to support migrations due to API changes, I think the only clean ways to do it are:
|
@Judahmeek would you mind kicking off the workflows again? I may have gotten this passing with my latest commit, but I'd like to verify. |
I think this one has better chance of working than mine. Using require rather than dynamic import is more likely to work without issues. Looks like we are still getting some spec fails so need to investigate that |
@summera do you want to finish this one up? I'd love to get it merged! |
I'm at loss with this one. Found reference to template strings in require https://stackoverflow.com/questions/42797313/webpack-dynamic-module-loader-by-require/42804941#42804941 I can see in the error we're getting empty context error. This leads me to believe that either:
Need to dig into this and see what is the context returned by that dynamic require statement. Might bring us closer to figuring out what's wrong (maybe some webpack setting?). It's as if it's not looking up module inside the node_modules folder (which I THINK it should by default) |
@tomdracz Please keep us posted. This is an important fix! |
I tried to understand it yesterday too (and made my own attempt). The documentation is pretty unclear, but as far as I understood, Webpack requires a base directory for all dynamic imports/requires and indeed doesn't look in |
#1460 has been merged instead. |
Summary
This resolves #1441.
With React 18,
hydrateRoot
andcreateRoot
have been moved toreact-dom/client
. See reactwg/react-18#125 and facebook/react#23385 for more info.If you try to access these methods on
react-dom
, you'll see a warning that looks like this:React 18 support was added in #1409 but also resulted in this warning since
createRoot
andhydrateRoot
were being called onreact-dom
.In order to prevent the warning, I added a conditional require using a ternary statement in
reactHydrate.ts
andreactRender.ts
. I also had to disable theimport/no-unresolved
rule as it was throwing an error whenreact-dom/client
wasn't present (in React < 18). I think this should do it but I struggled making eslint and typescript happy so let me know if I'm missing anything.This change is