Skip to content

Commit

Permalink
Fix primefaces#5927: BodyCell memory leak when not editable
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Feb 19, 2024
1 parent 69b9adc commit cfb1ed3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 3 additions & 5 deletions components/lib/hooks/useEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ export const useEventListener = ({ target = 'document', type, listener, options,
unbind();
when && bind();
}
return () => {
// #5927 prevent memory leak by releasing
prevListener = null;
prevOptions = null;
};
}, [listener, options, when]);

useUnmountEffect(() => {
unbind();
// #5927 prevent memory leak by releasing
prevListener = null;
prevOptions = null;
});

return [bind, unbind];
Expand Down
8 changes: 3 additions & 5 deletions components/lib/hooks/useOverlayScrollListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ export const useOverlayScrollListener = ({ target, listener, options, when = tru
unbind();
when && bind();
}
return () => {
// #5927 prevent memory leak by releasing
prevListener = null;
prevOptions = null;
};
}, [listener, options]);

useUnmountEffect(() => {
unbind();
// #5927 prevent memory leak by releasing
prevListener = null;
prevOptions = null;
});

return [bind, unbind];
Expand Down
8 changes: 6 additions & 2 deletions components/lib/hooks/usePrevious.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import * as React from 'react';

export const usePrevious = (newValue) => {
const ref = React.useRef(undefined);
const ref = React.useRef(null);

React.useEffect(() => {
ref.current = newValue;
});

return () => {
ref.current = null;
};
}, [newValue]);

return ref.current;
};

0 comments on commit cfb1ed3

Please sign in to comment.