Skip to content
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

[Bug]: useId giving warning as it's not supported by react <18 #17084

Closed
2 tasks done
sean-anderson-ibm opened this issue Aug 1, 2024 · 2 comments · Fixed by #17088
Closed
2 tasks done

[Bug]: useId giving warning as it's not supported by react <18 #17084

sean-anderson-ibm opened this issue Aug 1, 2024 · 2 comments · Fixed by #17088
Assignees
Labels
role: dev 🤖 severity: 1 https://ibm.biz/carbon-severity type: bug 🐛

Comments

@sean-anderson-ibm
Copy link

Package

@carbon/react

Browser

No response

Package version

v1.63.0

React version

16.14.0

Description

A recent PR - #16988, which was part of the v1.63.0 release of @carbon/react has moved to using useId in more places. There is handling for the correct version here

// React 18 introduced a new hook called `useId` that takes care of hydration
but this seems to not be working since that PR.

When running a storybook-smoke-test (npm run storybook-smoke-test) we are seeing:

WARN export 'useId' (imported as 'useId') was not found in 'react' (possible exports: Children, Component, Fragment, Profiler, PureComponent, StrictMode, Suspense, __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, cloneElement, createContext, createElement, createFactory, createRef, forwardRef, isValidElement, lazy, memo, useCallback, useContext, useDebugValue, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState, version)

I believe the initial PR to fix this was #14153, and I can't see that file being changed since so it's not immediately obvious why it's no longer working.

Reproduction/example

[email protected], @carbon/[email protected]

Steps to reproduce

  • Create an environment with react 16.14.0, @carbon/[email protected] and a storybook set up.
  • Run npm run storybook-smoke-test and observe warning about useId

Suggested Severity

Severity 1 = Must be fixed ASAP. The response must be swift. Someone from the team must drop all current work and be immediately reassigned to address the issue.

Application/PAL

Cloud Pak For Integration (Platform UI)

Code of Conduct

@guidari
Copy link
Contributor

guidari commented Aug 1, 2024

We can guard the useId hook for React versions lower than 18 by using a smiliar approach that we applied here:

if (typeof React['useId'] === 'function') {
const id = nativeReactUseId(_prefix, prefix);
return id;
}

@tom-youd
Copy link

tom-youd commented Aug 8, 2024

Can this be reopened?
We are still seeing this warning with @carbon/react:1.63.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
role: dev 🤖 severity: 1 https://ibm.biz/carbon-severity type: bug 🐛
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants