-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Expected Behavior
From the README:
This package tries to support both the legacy React DOM interface (ReactDOM.render) and the new one introduced in React 18 (ReactDOM.createRoot).
The installed React version is tested at runtime by trying to import react-dom/client. If the import succeeds then the new API is used, otherwise we fallback to the legacy API.
I'd expect this library to work with React 17.
Actual Behavior
During webpack compilation, I see the following error:
ERROR in ./node_modules/react-components-rails/dist/index.js 1:1677-1703
Module not found: Error: Can't resolve 'react-dom/client' in '/Users/rosskaffenberger/dev/stitchfix/fe-infra-webpack-rails/gem/spec/sample/node_modules/react-components-rails/dist'
Dependencies:
- react-component-rails 1.0.0-beta.4
- react 17.0.2
- react-dom 17.0.2
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:
- apps using React 18:
import ReactComponentRails from "react-component-rails"
- apps using React <18:
import ReactComponentRails from "react-component-rails/legacy"