bug(data frame): Fix scrolling in fillable cards #1550
Merged
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 #1549.
Without this fix, the data frame in the tips dashboard example is sized to be as tall as the (non-virtualized) table. This causes the summary line ("Viewing rows x through y of z") to be covered, as well as the horizontal scroll bar on the data frame.
Working:

Broken:

The change seems to have happened when Tanstack was updated. I set a breakpoint on these lines:
py-shiny/js/data-frame/index.tsx
Lines 653 to 657 in 798d02c
For both working and non-working code, both scrollHeight and clientHeight are undefined the first time through; this causes
.scrolling
to be applied. The second time through, for the working, scrollHeight and clientHeight are different and I can see cells in the table (while the debugger is paused); but for the non-working, scrollHeight and clientHeight are the same and there are no cells in the table. This causes.scrolling
to be removed. And once removed, it won't be applied in the future, becausescrollHeight
andclientHeight
will always be the same value--because it's not scrolling.The fix is to use a layout effect (runs after DOM nodes are inserted/mutated but before the browser has had a chance to paint) to temporarily apply scrolling, measure, and then remove scrolling if appropriate. I'm a little worried that temporarily applying scrolling is too violent, but I don't know what else to do, and it appears to be flicker-free. In the common case where scrolling is correctly turned on, I think it will be very quick, as no CSS classes will actually be applied or removed.