Skip to content

React 16/17 compatibility broken in v9.1.0+ due to static analysis of React.useId() #1674

@gardsa

Description

@gardsa

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

  1. Create a project using React 16 or 17
  2. Install downshift@^9.1.0 (or 9.2.0)
  3. Import and use any downshift hook (useCombobox, useSelect, etc.)
  4. 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:

  1. Dynamic property access: React['useId']()
  2. Indirect invocation through a variable
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions