-
Notifications
You must be signed in to change notification settings - Fork 940
Description
Description
After upgrading from downshift v9.0.13 to v9.2.0, applications using React 16 or 17 fail to build with Webpack. The error occurs during static analysis:
export 'useId' (imported as 'React') was not found in 'react'
Root Cause
In src/hooks/utils.js, the useElementIds function uses a ternary expression with a runtime check:
const useElementIds =
'useId' in React // Avoid conditional useId call
? function useElementIds({...}) {
const reactId = `downshift-${React.useId()}`
// ...
}
: function useElementIds({...}) {
// fallback using generateId()
}https://github.com/downshift-js/downshift/blob/v9.2.0/src/hooks/utils.js#L17-L28
While this correctly avoids calling useId at runtime on older React versions, Webpack's static analysis still parses the React.useId() reference and attempts to resolve it from the React module. Since React 16/17 don't export useId, this causes a build failure.
This worked in v9.0.13 but broke in v9.1.0, likely due to the TypeScript migration in PR #1665 which changed the React import style and build configuration.
Steps to Reproduce
- Create a project using React 16 or 17
- Install
downshift@^9.1.0(or 9.2.0) - Import and use any downshift hook (
useCombobox,useSelect, etc.) - Build with Webpack
Expected Behavior
downshift should build successfully with React 16/17, as indicated by the peer dependency "react": ">=16.12.0".
Suggested Fix
The React.useId() call needs to be isolated so static analyzers don't see it when building for older React versions. Options include:
- Dynamic property access:
React['useId']() - Indirect invocation through a variable
- Separate entry points for React 18+ vs older versions
Environment
- downshift version: 9.1.0 / 9.2.0
- React version: 16.x / 17.x
- Bundler: Webpack
Related Links
- Working version: v9.0.13
- Breaking change PR: #1665
- Comparison: v9.0.13...v9.2.0