Skip to content

Conversation

jcfilben
Copy link
Collaborator

@jcfilben jcfilben commented Oct 7, 2024

What does this PR do?

Replaces useId in AccordionPanel because useId is only available in React 18 and we need to support react 16 and 17 as well.

This PR is targeted to merge into the react-compatibility branh so we can do a patch release from that branch

Where should the reviewer start?

What testing has been done on this PR?

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?

Screenshots (if appropriate)

Do the grommet docs need to be updated?

no

Should this PR be mentioned in the release notes?

yes

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

backwards compatible

@jcfilben jcfilben mentioned this pull request Oct 7, 2024
3 tasks
@@ -19,6 +19,16 @@ const customTheme = {
};

describe('Accordion', () => {
beforeEach(() => {
jest.spyOn(Date, 'now').mockImplementation(() => 12345678);
jest.spyOn(global.Math, 'random').mockReturnValue(0.123456789);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add comments about how you chose the values here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a comment in latest commit

// Ideally we should use `useId` from react but this is only available
// in React 18 and we want to keep compatibility with React 17 and 16.
function getUID() {
const timestamp = Date.now().toString(36);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we do:

Date.now() + Math.random() instead of just appending Math.random?

https://stackoverflow.com/questions/8012002/create-a-unique-number-with-javascript-time/40591207#40591207

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed in latest commit

@jcfilben jcfilben requested a review from britt6612 October 7, 2024 21:52
@jcfilben jcfilben merged commit 6164673 into react-compatibility Oct 7, 2024
10 checks passed
@jcfilben jcfilben deleted the replace-useId branch October 7, 2024 22:05
jcfilben added a commit that referenced this pull request Oct 9, 2024
* Change release branch (#7346)

* Accordion - Replace useId (#7345)

* Replace useId function

* address review comments

* changed comment to re-trigger circleci run

* Updated v2.40.2

* change release step in circleci to point back to master branch
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.

3 participants