Skip to content

Conversation

MikeKingdom
Copy link
Collaborator

@MikeKingdom MikeKingdom commented Jan 5, 2023

What does this PR do?

Change the implementation of useForwardedRef to not modify the associated ref during render. The preferred method of updating the forwarded ref according to React is its useImperativeHandle hook.

See #6551 for details on the issue.

The change to the DateInput-test is basically because the .focus() done via a setTimeout() can actually happen after the DOM has gone away (even though the timeout is only 1ms.)

Where should the reviewer start?

refs.js

What testing has been done on this PR?

jest, manual and storybook

How should this be manually tested?

Go to the DateInput "Format" story and click on the icon to open the Calendar. Then click on a date in the calendar and close it. It should use the ref that the Calendar forwarded from DateInput to set focus on the DateInput input field.

pass a ref into any component that uses useForwardedRef() and then display that ref from a useEffect.

Do Jest tests follow these best practices?

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

Any background context you want to provide?

What are the relevant issues?

Closes #6551

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

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!

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.

useForwardedRef incorrectly updates the ref during the render phase
3 participants