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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(data frame): Fix scrolling in fillable cards #1550

Merged
merged 2 commits into from
Jul 18, 2024
Merged

Conversation

jcheng5
Copy link
Collaborator

@jcheng5 jcheng5 commented Jul 18, 2024

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:
image

Broken:
image

The change seems to have happened when Tanstack was updated. I set a breakpoint on these lines:

const scrollHeight = containerRef.current?.scrollHeight;
const clientHeight = containerRef.current?.clientHeight;
if (scrollHeight && clientHeight && scrollHeight <= clientHeight) {
scrollingClass = "";
}

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, because scrollHeight and clientHeight 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.

@jcheng5 jcheng5 requested a review from schloerke July 18, 2024 04:25
@schloerke
Copy link
Collaborator

This fix still gives expected behavior for #1498. 👍

@schloerke schloerke enabled auto-merge July 18, 2024 04:50
@schloerke schloerke added this pull request to the merge queue Jul 18, 2024
Merged via the queue into main with commit 2fac61c Jul 18, 2024
30 checks passed
@schloerke schloerke deleted the data-frame-scrolling branch July 18, 2024 05:08
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.

Horizontal scroll no longer works with @render.data_frame
2 participants