-
Notifications
You must be signed in to change notification settings - Fork 842
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
[DataGrid] Ensure referential integrity of focused cell #6007
Conversation
AWESOME debugging and breakdown on this - it was super easy to follow your logic and the issue! I agree your fix works, just wanted to throw this alternative option out there to see what you think - it's a few less characters so may be easier to read/grok. In eui/src/components/datagrid/utils/scrolling.tsx Lines 47 to 54 in c1f5de4
- }, [focusedCell, scrollCellIntoView]);
+ }, [focusedCell?.[0], focusedCell?.[1], scrollCellIntoView]); Would that accomplish the same fix? Or am I oversimplifying? 🤔 |
Preview documentation changes for this PR: https://eui.elastic.co/pr_6007/ |
Unfortunately I don't think that will work. It would invalidate the dependencies being exhaustive ( My thinking was by making it part of |
Gotcha, no worries! After thinking on a bit more as well I totally agree that your approach is the most robust solution. Seriously awesome!! :) I have a few small comments and a suggestions for a unit test, I'll make those here shortly. I think we should add a changelog for this fix as well - you can auto-generate the changelog file by running |
This comment was marked as resolved.
This comment was marked as resolved.
Preview documentation changes for this PR: https://eui.elastic.co/pr_6007/ |
… data-grid-focused-cell
Co-authored-by: Constance <constancecchen@users.noreply.github.com>
… data-grid-focused-cell
Preview documentation changes for this PR: https://eui.elastic.co/pr_6007/ |
@constancecchen Thanks for the review, and test addition. I think this is ready now. As a side note I did hit a bit of an issue with the changelog generation. I got this error running
I ended up just manually adding |
Preview documentation changes for this PR: https://eui.elastic.co/pr_6007/ |
Whoa, thanks for finding that! Almost certainly an issue of the majority of us being on older Macs/OSes, which we should run into at some point when our machines get upgraded, haha 🙈 Thanks for the comment expansion as well, this looks really great! |
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.
🎉 Thank you for this fantastic contribution to EUI and EuiDataGrid! Feel free to merge this PR in once CI passes!
Preview documentation changes for this PR: https://eui.elastic.co/pr_6007/ |
Summary
As part of elastic/kibana#79288 I discovered an issue with the
focusedCell
/setFocusedCell
logic.It's possible (especially with an
overscanRowCount
greater than 1) to end up in a loop where the user can't scroll a focused cell out of view, instead it will constantly scroll back in to view, and thus block scrolling up or down properly.The reason for this is the calls to
setFocusedCell
pass through a new array instance each time, and this means the hooks that usefocusedCell
as a dependency (which would rely on referential integrity of the array, or alternatively using the primitive values of the array instead) receive a new reference each time.This causes the following loop (for a focused cell):
.focus
onFocus
, which will always pass a new array instance tosetFocusedCell
.useScroll useEffect
as a dependency changescrollCellIntoView
This is more exaggerated in the case of a higher overscan count as cells can be simultaneously focused, mounted, and out of view for longer. Although it is still visible with the default of 1 too.
This gif tries to show the behaviour (notice the snapping back to the focused cell):
This is the behaviour with the fix applied:
There are a few ways this could be approached, I didn't want to change the tuple nature of
focusedCell
and switch to passing two primitives around instead as this logic was spread in quite a few places. This change seemed the least intrusive, it ensures the publicsetFocusedCell
only propagates to the private_setFocusedCell
state update if the values have actually changed (and should therefore notify locations such asscrolling.ts
).Please let me know if this breaks anything or my assumptions are wrong (as I'm not an EUI developer), as far as I can see this doesn't alter anything else.
Checklist