Don't retain state across distinct-but-similar expanders #4290
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
馃摎 Context
It turns out that #4258 is caused by what seems to be a really fun bug --
distinct expanders sometimes look so similar that react's diffing algorithm
decides that the two elements are the same (but with different props), and so
the state of the
useState
hook is retained across two distinct expanders 馃くThe fix for this is to simply add a
useEffect
dependency on the hook currentlywatching for default expanded state changes so that the expander's state is also
reset when its
label
changes.What kind of change does this PR introduce?
馃 Description of Changes
Fix expander state being incorrectly retained for distinct expanders by
adding a
useEffect
dependencyAdded an e2e test for this behavior
馃И Testing Done
馃寪 References