From cf374585c5d2edffe5793adea89922fcc9bfe0da Mon Sep 17 00:00:00 2001 From: Ricky Zhang Date: Fri, 20 Nov 2026 13:49:16 -0500 Subject: [PATCH] Tooltip: guard against missing text at runtime #8740 called `text.trim()` unconditionally during render, which throws when a caller passes an undefined `text` value at runtime (such as incomplete test mocks in github/github-ui). Check `typeof text === 'string'` before trimming so missing values remain inert instead of crashing render. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .changeset/tooltip-missing-text.md | 5 +++++ packages/react/src/TooltipV2/Tooltip.tsx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/tooltip-missing-text.md diff --git a/.changeset/tooltip-missing-text.md b/.changeset/tooltip-missing-text.md new file mode 100644 index 00000000000..218d937fd96 --- /dev/null +++ b/.changeset/tooltip-missing-text.md @@ -0,0 +1,5 @@ +--- +'@primer/react': patch +--- + +Tooltip: Guard against missing `text` values at runtime when checking whether a tooltip has content. diff --git a/packages/react/src/TooltipV2/Tooltip.tsx b/packages/react/src/TooltipV2/Tooltip.tsx index 223a9fb2b03..2b69ad0e132 100644 --- a/packages/react/src/TooltipV2/Tooltip.tsx +++ b/packages/react/src/TooltipV2/Tooltip.tsx @@ -147,7 +147,7 @@ export const Tooltip: ForwardRefExoticComponent< // Normalize keybindingHint to an array for uniform rendering const keybindingHints = Array.isArray(keybindingHint) ? keybindingHint : [keybindingHint] - const hasText = Boolean(text.trim()) + const hasText = typeof text === 'string' && text.trim().length > 0 const hasContent = hasText || keybindingHints.length > 0 const [calculatedDirection, setCalculatedDirection] = useState(direction)