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

fix(combobox): memoize floating ui ref to prevent max call depth #16866

Conversation

tay1orjones
Copy link
Member

Closes #16857

This PR does to primary things:

  1. Memoize the value of getMenuProps to avoid an infinite loop
  2. Only apply floating ui refs when autoAlign={true}

The first fixes the problem outlined in the original issue, the second is an indirect improvement. If the refs had initially been guarded, this bug would've been isolated to users using autoAlign. Because the refs were not guarded, the bug was present for everyone regardless of if autoAlign was being used.

From what I can tell, there is not a reliable way to unit test this as the keyboard entry rate isn't configurable.

Changelog

Changed

  • Wrap getMenuProps in useMemo
  • Conditionally apply refs

Testing / Reviewing

  • Go to the default combobox story. Type super fast - like just totally spam the keyboard. The component should not error
  • Do the same on the allowCustomInput combobox story
  • Do the same on the with experimental autoalign combobox story
  • Ensure autoAlign works as expected on combobox by resizing the browser window, playing with scroll, and opening/closing the listbox

@tay1orjones tay1orjones requested a review from a team as a code owner June 25, 2024 18:54
Copy link

netlify bot commented Jun 25, 2024

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 875df8a
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/667bfb5e6d20660008b4ad87
😎 Deploy Preview https://deploy-preview-16866--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jun 25, 2024

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 875df8a
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/667bfb5e7ffd34000806131e
😎 Deploy Preview https://deploy-preview-16866--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@guidari guidari left a comment

Choose a reason for hiding this comment

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

LGTM!

@tay1orjones tay1orjones added this pull request to the merge queue Jun 26, 2024
Merged via the queue into carbon-design-system:main with commit 305c274 Jun 26, 2024
22 checks passed
@tay1orjones tay1orjones deleted the 16857-combobox-allowCustomInput-bug branch June 26, 2024 14:39
tay1orjones added a commit to tay1orjones/carbon that referenced this pull request Jun 26, 2024
@tay1orjones tay1orjones mentioned this pull request Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: ComboBox crashes when typing fast with allowCustomValue=true
3 participants