From f3b0bde343334c2b6efa2a876c4f9670e20ce466 Mon Sep 17 00:00:00 2001 From: Supra4E8C Date: Wed, 1 Apr 2026 23:51:08 +0800 Subject: [PATCH] fix(usage): guard service health tooltip anchor --- src/components/usage/ServiceHealthCard.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/usage/ServiceHealthCard.tsx b/src/components/usage/ServiceHealthCard.tsx index c4e82c9..f7f94f3 100644 --- a/src/components/usage/ServiceHealthCard.tsx +++ b/src/components/usage/ServiceHealthCard.tsx @@ -83,7 +83,11 @@ export function ServiceHealthCard({ usage, loading }: ServiceHealthCardProps) { }, [activeTooltip]); const buildTooltipState = useCallback( - (idx: number, anchorEl: HTMLDivElement): ActiveTooltipState => { + (idx: number, anchorEl: HTMLDivElement | null): ActiveTooltipState | null => { + if (!anchorEl || !anchorEl.isConnected) { + return null; + } + const rect = anchorEl.getBoundingClientRect(); const centerX = rect.left + rect.width / 2; @@ -161,9 +165,8 @@ export function ServiceHealthCard({ usage, loading }: ServiceHealthCardProps) { (e: React.PointerEvent, idx: number) => { if (e.pointerType === 'touch') { e.preventDefault(); - setActiveTooltip((prev) => - prev?.idx === idx ? null : buildTooltipState(idx, e.currentTarget) - ); + const anchorEl = e.currentTarget; + setActiveTooltip((prev) => (prev?.idx === idx ? null : buildTooltipState(idx, anchorEl))); } }, [buildTooltipState]