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

[DataGrid] Scroll restoration #15623

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

lauri865
Copy link
Contributor

@lauri865 lauri865 commented Nov 26, 2024

Fixes #15190

Pain to implement in userland currently, avoids recalculating render contexts and trashing wrong initial content, that's impossible to avoid in userland.

Added a section under scrolling in docs to demonstrate.

@mui-bot
Copy link

mui-bot commented Nov 26, 2024

Deploy preview: https://deploy-preview-15623--material-ui-x.netlify.app/

Updated pages:

Generated by 🚫 dangerJS against abca445

Comment on lines 38 to 41
useEnhancedEffect(() => {
apiRef.current.publishEvent('virtualScrollerContentSizeChange');
}, [apiRef, props.style]);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a way to keep this logic in the feature hook? Imho, it feels a bit cleaner to have it there, considering all the other similar logic is also there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely agree with you there, and just finishing a commit on that note. Wasn't completely obvious to me initially how I could do it in a clean way, as it needs to run before paint to avoid triggering reflows – so at useLayoutEffect of the ScrollerContent component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with a callbackRef. Also made it more complete for different use cases. E.g. when columns are not immediately available, and if columns and rows become available at different times.

ColumnVirtualizationGrid.tsx in the docs turned out be a good test case.

Comment on lines 626 to 629
if (left > 0) {
scroller.scrollLeft = left;
ignoreNextScrollEvent.current = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why we only deal with left and not with top here? Would it be relevant to leave a small comment to explain it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some notes now.

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.

[data grid] Feature: First-party (performant) scroll restoration
3 participants