mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard: Fix lazy loading for repeated panels (#43083)
This commit is contained in:
parent
61227998a7
commit
c926d4d7f2
@ -15,6 +15,7 @@ export function LazyLoader({ children, width, height, onLoad, onChange }: Props)
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [isInView, setIsInView] = useState(false);
|
||||
const wrapperRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffectOnce(() => {
|
||||
LazyLoader.addCallback(id, (entry) => {
|
||||
if (!loaded && entry.isIntersecting) {
|
||||
@ -26,12 +27,15 @@ export function LazyLoader({ children, width, height, onLoad, onChange }: Props)
|
||||
onChange?.(entry.isIntersecting);
|
||||
});
|
||||
|
||||
if (wrapperRef.current) {
|
||||
LazyLoader.observer.observe(wrapperRef.current);
|
||||
const wrapperEl = wrapperRef.current;
|
||||
|
||||
if (wrapperEl) {
|
||||
LazyLoader.observer.observe(wrapperEl);
|
||||
}
|
||||
|
||||
return () => {
|
||||
delete LazyLoader.callbacks[id];
|
||||
wrapperEl && LazyLoader.observer.unobserve(wrapperEl);
|
||||
if (Object.keys(LazyLoader.callbacks).length === 0) {
|
||||
LazyLoader.observer.disconnect();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user