-
Notifications
You must be signed in to change notification settings - Fork 30
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
v1.0.0-beta.4 is incompatible with React <18 #147
Comments
Thanks for your report. This is weird as there is no I wanted to find a way to not require users to change their imports to use the legacy React DOM API. It looks like we could use |
Yes, I misspoke about the import. It is the dynamic import that webpack can't process at compile time even though the module isn't requested until runtime. I know react-component-rails is meant to be bundler-agnostic and, while I don't know for sure if behavior affects other bundlers, I do have a webpack-specific workaround. I can instruct webpack to load another module instead in place of // ... add to existing webpack config
{
// ...
resolve: {
alias: {
'react-dom/client$': path.resolve('path/to/module/that/raises/error'),
},
},
}; |
Version detection could be another option. Something like: private loadReactDOMClient() {
return new Promise<void>((resolve) => {
+ const [reactMajorVersion] = React.version && React.version.split('.') || '0';
+ if (parseInt(reactMajorVersion, 10) < 18) {
+ this.#ReactDOMClient = false
+ resolve()
+ } |
Expected Behavior
From the README:
I'd expect this library to work with React 17.
Actual Behavior
During webpack compilation, I see the following error:
Dependencies:
Analysis
It appears that the
import from "react-dom/client"
statement will not work in versions of React prior to 18.One solution I can think of is for
react-component-rails
to be refactored in a way such that the behavioral differences between React 18+ and React <18 can be isolated and injected via separate imports from the consumer, i.e., something like the following:import ReactComponentRails from "react-component-rails"
import ReactComponentRails from "react-component-rails/legacy"
The text was updated successfully, but these errors were encountered: