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

[EuiAccordion] Fix resize observer loop error when drag&dropping an accordion #6031

Merged

Conversation

chandlerprall
Copy link
Contributor

@chandlerprall chandlerprall commented Jul 6, 2022

Summary

Closes #5903

Found this by attempting to automatically pause/resume all EuiResizeObserver/useResizeObserver in response to drag&drop events. Was debugging why the error still happened with everything paused, at it turned out the re-renders in EuiAccordion were recreating the provided ref function causing React to call that function with null and then the same Element as it was before. This behaviour bypassed EuiObserver::updateChildNode's 'memoizing' logic and instantiated new observers during the drag operation.

After fixing the ref call loop the error went away even without pausing the observers 🎆

Reproduction & testing:
I updated the Drag and drop example page to have only the reproduction setup, you must also enable devtools' responsive layout, select ipad mini, and set the zoom level to 75%.

resizeobserveraccordion.mov

Checklist

  • reverted "revert me" commit
    - [ ] Checked in both light and dark modes
    - [ ] Checked in mobile
    - [ ] Checked in Chrome, Safari, Edge, and Firefox
    - [ ] Props have proper autodocs and playground toggles
    - [ ] Added documentation
    - [ ] Checked Code Sandbox works for any docs examples
    - [ ] Added or updated jest and cypress tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
    - [ ] Updated the Figma library counterpart
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6031/

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

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

Inline ref callback loop was a great find! Glad we don't need a resizeObserver intervention.

Tested with the docs deployment with the specific sizing + zoom.

@chandlerprall
Copy link
Contributor Author

CI error is from an AXE error in the reproduction case and will be resolved when the revert commit is reverted

@cee-chen
Copy link
Contributor

cee-chen commented Jul 6, 2022

Agreed, this is a super elegant fix/workaround to the problem! Huge kudos!

chandlerprall and others added 2 commits July 6, 2022 13:11
Co-authored-by: Constance <constancecchen@users.noreply.github.com>
This reverts commit fa3f198.
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6031/

Copy link
Contributor

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

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

I'm good with this! This is such an edge case I honestly don't think it needs a unit test or Cypress test specifically written for it, nor am I totally sure how we would write one 👍

@chandlerprall chandlerprall merged commit 1803afd into elastic:main Jul 6, 2022
@chandlerprall chandlerprall deleted the bug/5903-dragndrop-accordion branch July 6, 2022 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants