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

EuiButtonToggle/useRenderToText: prevent state update on unmounted component #2797

Merged
merged 4 commits into from
Jan 27, 2020

Conversation

thompsongl
Copy link
Contributor

@thompsongl thompsongl commented Jan 27, 2020

Summary

Fixes #2736.

  • Store the DocumentFragment reference in a mutable useRef object so it's (synchronously) modifiable and available for the lifecycle duration.
  • The ref callback from useInnerText is a useState setter, so we need to prevent invocations after unmount (hostNode == null).
  • Remove requestAnimationFrame tick as there are no more state side-effects during the unmount process.

Simple testing method with local EUI docs:

  • "Toggle buttons" section
  • Change from "Demo" to "Props" tab
  • You'll see a (soon to be fixed) EuiCodeBlockImpl warning, but no state update warning

Checklist

- [ ] Check against all themes for compatibility in both light and dark modes
- [ ] Checked in mobile

  • Checked in IE11 and Firefox

- [ ] Props have proper autodocs
- [ ] Added documentation examples
- [ ] Added or updated jest tests

  • Checked for breaking changes and labeled appropriately

- [ ] Checked for accessibility including keyboard-only and screenreader modes

  • A changelog entry exists and is marked appropriately

requestAnimationFrame(() => {
unmountComponentAtNode(hostNode);
});
onUnmount();

Choose a reason for hiding this comment

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

👍 it's nice that the RAF trick is no longer required

Copy link

@andrew-goldstein andrew-goldstein left a comment

Choose a reason for hiding this comment

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

Thanks @thompsongl for the quick turnaround on this for 7.6! 🙏
LGTM

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.

EuiButtonGroup (and EuiButtonToggle) doesn't unmount properly
2 participants