Skip to content

Conversation

MikeKingdom
Copy link
Collaborator

What does this PR do?

In grommet 2.42.0 we added a polyfill for React 18's useId() for cases where React 16 or 17 were used. The way this polyfill was done still causes an error in when TypeScript is used due to it doing an import { useId } from 'react'.

This change instead checks if useId is defined on the React module itself which seems to work better with TypeScript situations.

Fixes #7442

Where should the reviewer start?

utils/useId.js

What testing has been done on this PR?

Tested with a standalone TypeScript-based react project using React 16.

How should this be manually tested?

Do Jest tests follow these best practices?

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

What are the relevant issues?

#7442

Screenshots (if appropriate)

Do the grommet docs need to be updated?

Should this PR be mentioned in the release notes?

Is this change backwards compatible or is it a breaking change?

Signed-off-by: Mike Kingdom <michael.kingdom@hpe.com>
@MikeKingdom
Copy link
Collaborator Author

TypeScript/CRA/grommet 2.42.0 app with React 17 before the fix:
image
Same app with the fix from this PR:
image

TypeScript/CRA/grommet 2.42.0 app with React 16 before the fix:
image
Same app with the fix from this PR:
image

Copy link
Collaborator

@jcfilben jcfilben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!
Tested in a react 16 typescript project

@MikeKingdom MikeKingdom merged commit d745303 into master Nov 25, 2024
16 checks passed
@MikeKingdom MikeKingdom deleted the useid-polyfill-2 branch November 25, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'useId' is not exported from 'react' breaking error from grommet
3 participants