Skip to content

Tooltip: guard against missing text at runtime - #8814

Open
rickyzhangca wants to merge 1 commit into
mainfrom
agents/vscode-insiders-agent-fix-review
Open

rickyzhangca wants to merge 1 commit into
mainfrom
agents/vscode-insiders-agent-fix-review

Conversation

@rickyzhangca

Copy link
Copy Markdown
Contributor

Closes #

Follows up on #8740.

#8740 added an unconditional text.trim() check during render. While text is typed as string, callers passing undefined at runtime (for example, partial CheckRun test fixtures in github/github-ui ReposChecksStatusBadge.browser.test.tsx) now throw TypeError: Cannot read properties of undefined (reading 'trim') instead of rendering inertly.

Checking typeof text === 'string' && text.trim().length > 0 keeps the TypeScript contract unchanged while treating missing runtime values as empty text.

Changelog

New

Changed

  • Tooltip now guards text with typeof text === 'string' before trimming so missing runtime values stay inert instead of throwing during render.

Removed

Rollout strategy

  • No changes needed in github/github-ui
  • Needs changes in github/github-ui
  • Ships with feature flag(s)
  • Not sure
  • None

Testing & Reviewing

Local validation:

  • npm run build: passed
  • VITEST_FAIL_ON_CONSOLE=true npx vitest run --project '@primer/react' packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx: passed (44/44 tests)
  • npm run type-check: passed
  • npx eslint --max-warnings=0 --fix packages/react/src/TooltipV2/Tooltip.tsx: passed
  • npm run format:diff: passed
  • Full npm test and script/test-e2e suites were not run locally (covered by CI).

#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-bot

changeset-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cf37458

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

@rickyzhangca
rickyzhangca marked this pull request as ready for review November 20, 2026 18:53
@rickyzhangca
rickyzhangca requested a review from a team as a code owner November 20, 2026 18:53
@rickyzhangca
rickyzhangca requested review from tay1orjones and a balanced review from Copilot November 20, 2026 18:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests do not cover explicitly undefined text, leaving the crash fix without regression coverage for successful rendering, absent tooltip ARIA association, and no tooltip opening on focus.

1 open issue
What changed in this PR

This follow-up to #8740 prevents Primer React’s Tooltip from throwing when text is missing at runtime, while preserving its required-string TypeScript API.

Changes:

  • Checks that text is a string before trimming, keeping missing-text tooltips inert unless a keybinding hint provides content.
  • Adds a patch changeset for @primer/react.
File Description
packages/​react/​src/​TooltipV2/​Tooltip.tsx Guards the text-content check against missing runtime values.
.changeset/​tooltip-missing-text.md Records the runtime fix for a patch release.

Review effort: Balanced

// 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair ask, but optional!

@primer-integration

Copy link
Copy Markdown

Integration test results from github/github-ui PR:

Passed  Changes   Passed
Passed  CI   Passed
Passed  VRT   Passed
Passed  Projects   Passed

All checks passed!

This branch was successfully deployed

2 active deployments
storybook-preview-8814 — cf374585 Deployed Nov 20, 2026 by github-actions[bot]
github-pages — cf374585 Deployed Nov 20, 2026 by rickyzhangca via deploy-preview #34485
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants