-
Notifications
You must be signed in to change notification settings - Fork 839
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(EuiSelectableList): fix read-after-write on component state #7768
fix(EuiSelectableList): fix read-after-write on component state #7768
Conversation
@@ -349,7 +348,9 @@ export class EuiSelectableList<T> extends Component< | |||
prevProps.onFocusBadge !== onFocusBadge || | |||
prevProps.searchable !== searchable | |||
) { | |||
this.forceVirtualizedListRowRerender(); | |||
this.setState({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to add an optional optionArray
argument to forceVirtualizedListRowRerender
, and it felt like using setState
directly was the cleanest solution. Let me know if you have other ideas!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this! 🙏
Imho, I'd think reusing forceVirtualizedListRowRerender
with passing the optionArray
might be better for a) comprehension (naming stating what's happening) and b) reusing available code.
But I'm not hard set on this, I'm fine with either.
|
||
// ensure that ListRow updates based on item props | ||
if (isVirtualized) { | ||
} else if (isVirtualized) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else if
because it's not needed to execute both setState
s when the first condition is true
@@ -349,7 +348,9 @@ export class EuiSelectableList<T> extends Component< | |||
prevProps.onFocusBadge !== onFocusBadge || | |||
prevProps.searchable !== searchable | |||
) { | |||
this.forceVirtualizedListRowRerender(); | |||
this.setState({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this! 🙏
Imho, I'd think reusing forceVirtualizedListRowRerender
with passing the optionArray
might be better for a) comprehension (naming stating what's happening) and b) reusing available code.
But I'm not hard set on this, I'm fine with either.
Preview staging links for this PR:
|
💚 Build Succeeded
History
cc @tkajtoch |
Summary
This PR fixes a recently introduced bug (in #7728) in the
EuiSelectableList
component caused by read-after-write on its state before the state update is applied. More specifically,forceVirtualizedListRowRerender
readsthis.state.optionArray
, and when called fromcomponentDidUpdate
, thesetState
a few lines above isn't yet applied.QA
EUI
gh pr checkout 7768
yarn && yarn --cwd packages/eui build-pack
Kibana
gh pr checkout 183431
@elastic/eui
version to the local build of EUI inpackage.json
yarn kbn bootstrap --no-validate
node scripts/jest --config x-pack/plugins/global_search_bar/jest.config.js --watch telmetry.test.tsx
passes all testsGeneral checklist
- [ ] A changelog entry exists and is marked appropriately.Skipping a changelog as this is a fix for a change only made for docs/storybook