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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't retain state across distinct-but-similar expanders #4290

Merged
merged 2 commits into from Jan 21, 2022

Conversation

vdonato
Copy link
Collaborator

@vdonato vdonato commented Jan 18, 2022

馃摎 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 currently
watching 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?

    • Bugfix

馃 Description of Changes

  • Fix expander state being incorrectly retained for distinct expanders by
    adding a useEffect dependency

  • Added an e2e test for this behavior

    • This is a visible (user-facing) change

馃И Testing Done

  • Added/Updated e2e tests

馃寪 References

Copy link
Collaborator

@mayagbarnes mayagbarnes left a comment

Choose a reason for hiding this comment

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

馃憤馃徏

@vdonato vdonato merged commit 6d74c8f into streamlit:develop Jan 21, 2022
@vdonato vdonato deleted the expander-state branch January 21, 2022 00:36
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.

Expander state is incorrectly shared by distinct expanders
4 participants