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

[data grid] cleanup observer in react ≤18 #16284

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,17 @@ export const useGridVirtualScroller = () => {

const previousSize = React.useRef<{ width: number; height: number }>(null);

const observerRef = React.useRef<ResizeObserver | null>(null);
const mainRefCallback = React.useCallback(
(node: HTMLDivElement | null) => {
mainRef.current = node;

// Cleanup for React 18 that calls the ref callback with null when unmounting
if (observerRef.current) {
observerRef.current.disconnect();
observerRef.current = null;
}

if (!node) {
return undefined;
}
Expand Down Expand Up @@ -175,12 +182,14 @@ export const useGridVirtualScroller = () => {
lastSize = newSize;
});

observerRef.current = observer;
observer.observe(node);

if (reactMajor >= 19) {
return () => {
mainRef.current = null;
observer.disconnect();
observerRef.current = null;
};
}
return undefined;
Expand Down
Loading