prevent reports from unmounting when out of viewport (#6194)

This commit is contained in:
Matt Fiddaman
2025-11-18 09:57:36 +00:00
committed by GitHub
parent 30f4a7fa9d
commit 7e34ddd356
2 changed files with 16 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
import React, {
useEffect,
useRef,
useState,
type ComponentProps,
type ReactNode,
type CSSProperties,
@@ -43,12 +45,19 @@ export function ReportCard({
}: ReportCardProps) {
const ref = useRef(null);
const isInViewport = useIsInViewport(ref);
const [hasRendered, setHasRendered] = useState(false);
const navigate = useNavigate();
const { isNarrowWidth } = useResponsive();
const containerProps = {
flex: isNarrowWidth ? '1 1' : `0 0 calc(${size * 100}% / 3 - 20px)`,
};
useEffect(() => {
if (isInViewport && !hasRendered) {
setHasRendered(true);
}
}, [isInViewport, hasRendered]);
const layoutProps = {
isEditing,
menuItems,
@@ -91,7 +100,7 @@ export function ReportCard({
{/* we render the content only if it is in the viewport
this reduces the amount of concurrent server api calls and thus
has a better performance */}
{isInViewport ? children : null}
{isInViewport || hasRendered ? children : null}
</View>
);

View File

@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [matt-fidd]
---
Prevent reports from rerendering when re-entering the viewport