-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
List View: Recalculate window list when expanded state changes (fix logic for long nested lists) #53716
Conversation
Size Change: -53 B (0%) Total Size: 1.51 MB
ℹ️ View Unchanged
|
…e windowing logic
Update: getting closer. I think I've figured out a reliable way to do it by recalculating the windowing logic whenever the expanded state changes (in 04dc42e). I'll do some more testing tomorrow, but if this works, I think the next step will be to decide on a good prop name for it. |
Flaky tests detected in d5b02fb. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5898964798
|
I've gone with |
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.
LGTM! I think it works as expected, both with mouse and keyboard.
06f95152e72bd0a3075631ed3c89d43e.mp4
Thanks for reviewing @t-hamano! I think this change is fairly safe (as the main change is that recalculation happens more frequently, and only on expanded state change), so I'll merge this in now. Happy to follow up if anyone runs into any issues! |
What?
Fixes #41613, fixes #42031
Fix an issue with the windowing logic in the list view, where a short post containing a nested block with heaps of inner blocks (e.g. a Gallery with > 40 images) results in the windowing logic getting stuck and not updating when a user scrolls up and down the list.
Why?
When the list view is initially opened, if there are not many blocks at the root level, then no scrollbar will be present, so the fixed window list logic will not find the list view's scroll container in order to set up the windowing logic when a user scrolls up and down the list.
In normal circumstances (at the root level) this is fine — if you add or remove blocks, then
totalItems
withinuseFixedWindowList
will change, causing the windowing logic to be recalculated. However, if you have a container block with heaps of children (i.e. 40 or more), then expanding and collapsing the container block does not cause the recalculation to happen. In these cases (short root list, but a container block with heaps of children), then prior to this PR, the windowing logic can fail to update.How?
The fix is to ensure the fixed window list is recalculated whenever a block is expanded or collapsed. We can do this by passing the
expandedState
touseFixedWindowList
and then place theexpandedState
in the hook'suseLayoutEffect
dependency arrays. This causes the windowing to be recalculated whenever the expanded state is changed, anywhere in the tree.Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
Note in the before screengrab below, when expanding the collapsed block and then scrolling down the list, that the window list is not updated, resulting in an expanse of white further down the list. In the After screengrab, the list is updated as the user scrolls up and down the list.