fix: module tree expansion state when closing the module of the selected decl #3022
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.
Fixes: #2982
This fix delves into the nuance of component re-rendering lifecycle a bit. Basically, before, we would add the selected module to local storage AND update the component state on every single re-render of the component (at
const [expandedModules, setExpandedModules] = useState(...)
. The problem with that was that when we toggled the selected module to close it, the re-render would cause the selected module to still be added back to local storage, but the component state would be out of sync. Then when you went to expand that module again, because the states got unsynced, it would stay stuck in the visibly-closed state. Now, we only add the selected module to local storage in the effect, which doesn't get triggered on toggle a module's expansion state. As a result, the state doesn't de-sync.So now, you can do the following:
While the following still works correctly: