-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
[DataGridPro] Rework onRowsScrollEnd
to use IntersectionObserver
#8672
[DataGridPro] Rework onRowsScrollEnd
to use IntersectionObserver
#8672
Conversation
onRowsScrollEnd
to use IntersectionObserver
Deploy preview: https://deploy-preview-8672--material-ui-x.netlify.app/ Updated pages: |
packages/grid/x-data-grid-pro/src/hooks/features/infiniteLoader/useGridInfiniteLoader.ts
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid-pro/src/hooks/features/infiniteLoader/useGridInfiniteLoader.ts
Outdated
Show resolved
Hide resolved
…-rework-onRowsScrollEnd-to-use-IntersectionObserver
packages/grid/x-data-grid-premium/src/DataGridPremium/DataGridPremium.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid-pro/src/hooks/features/infiniteLoader/useGridInfiniteLoader.ts
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid-pro/src/hooks/features/infiniteLoader/useGridInfiniteLoader.ts
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid-pro/src/hooks/features/infiniteLoader/useGridInfiniteLoader.ts
Outdated
Show resolved
Hide resolved
* Stores the ref of the element at the bottom of the virtual scroller content that triggers the infinite loading. | ||
* @ignore - do not document. | ||
*/ | ||
unstable_infiniteLoadingTriggerRef: (node: HTMLElement | null) => void; |
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.
Keep in private API?
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.
I've replaced it with a getInfiniteLoadingTriggerElement
method in the private API and moved the interface to the MIT package for the sake of type safety (getInfiniteLoadingTriggerElement
is being called in the MIT package's useGridVirtualScroller
)
packages/x-data-grid-pro/src/hooks/features/infiniteLoader/useGridInfiniteLoader.ts
Outdated
Show resolved
Hide resolved
const InfiniteLoadingTriggerElement = styled('div')({ | ||
position: 'sticky', | ||
left: 0, | ||
width: 0, | ||
height: 0, | ||
}); | ||
|
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.
I don't love how the infinite loading logic is spilling in this file. Is there any other way we can separate the logic?
Instead of exposing unstable_infiniteLoadingTriggerRef
on the API, maybe we could expose (a) function(s) to add the trigger element?
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.
The function could take as input the props, so the props.rowsLoadingMode === 'client'
(below) would not need the (rootProps as any)
cast that's required here.
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.
Moved the trigger to the useGridInfiniteLoader
hook 👍🏻
packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx
Outdated
Show resolved
Hide resolved
if (triggerElement.current) { | ||
observer.current?.unobserve(triggerElement.current); | ||
} |
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.
Not sure if it applies but there is also observer.current?.disconnect()
, which can help avoid storing the observed element ref sometimes.
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.
Good point! I used disconnect
instead of unobserve.
I still need to keep track of the trigger element to observe it after recreating IntersectionObserver
(e.g. when marginBottom
changes): https://github.com/mui/mui-x/pull/8672/files#diff-626d69f7d7c9aebfab3fdc6388cd0f88a38b6d9e51c567e76f63a25d63895b10R81-R83
…ersectionObserver
…ui#8672) Co-authored-by: Andrew Cherniavskyi <[email protected]>
Fixes #4371
Fixes #9022
Preview: https://deploy-preview-8672--material-ui-x.netlify.app/x/react-data-grid/row-updates/#infinite-loading
TODO:
Server-side sorting should be used.
onRowsScrollEnd
triggered when applying filters #11402