Skip to content

Comments

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

Merged
thompsongl merged 4 commits intoelastic:masterfrom
thompsongl:2736-buttongroup
Jan 27, 2020
Merged

EuiButtonToggle/useRenderToText: prevent state update on unmounted component#2797
thompsongl merged 4 commits intoelastic:masterfrom
thompsongl:2736-buttongroup

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