Skip to content

Optimizes MdTooltip by unmounting when hidden by default - #565

Open
Helge Johnsen (hj-inmeta) wants to merge 4 commits into
mainfrom
feature/127-performance-tooltip
Open

Helge Johnsen (hj-inmeta) wants to merge 4 commits into
mainfrom
feature/127-performance-tooltip

Conversation

@hj-inmeta

Copy link
Copy Markdown
Contributor

Describe your changes

The unmountOnHide prop now defaults to true for the MdTooltip component. This change significantly reduces initial DOM overhead and improves rendering performance by ensuring tooltips are only mounted to the DOM when they are visible.

Checklist before requesting a review

  • I have performed a self-review and test of my code
  • I have added label to the PR (major, minor or patch)
  • If applicable: Is story created/updated in stories-folder?
  • If applicable: Is README-file for CSS documentation created/updated?
  • If applicable: Are unit tests created/updated for the component?
  • If applicable: Tested in Storybook with keyboard, screen reader, zoom, and color contrast
  • If new component: Is tsx-file import added to packages/react/index.tsx?
  • If new component: Is CSS-file added to packages/css/index.css?

The `unmountOnHide` prop now defaults to `true` for the `MdTooltip` component. This change significantly reduces initial DOM overhead and improves rendering performance by ensuring tooltips are only mounted to the DOM when they are visible.
Helge Johnsen and others added 2 commits September 11, 2026 10:52
Updates the `MdTag` test for `tooltipOnly` mode to accurately reflect its rendering behavior.

The previous assertion incorrectly expected the label text to be present in the document, even when visually hidden. This correction verifies that when `tooltipOnly` is active, the label content is exclusively managed by the `MdTooltip` component and is not directly rendered in the DOM, aligning with the default `unmountOnHide` behavior of `MdTooltip`.

This ensures the test suite correctly validates the component's state following recent tooltip performance optimizations.

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

Address the tooltip-only accessibility issue and add interaction coverage for the new default behavior.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

MdTooltip now unmounts hidden content by default to reduce DOM overhead while preserving an opt-out.

Changes:

  • Defaults unmountOnHide to true.
  • Updates tooltip and tag tests.
  • Preserves explicit persistent mounting.
File summaries
File Description
packages/react/src/tooltip/tests/MdTooltip.test.tsx Tests tooltip mounting behavior.
packages/react/src/tooltip/MdTooltip.tsx Changes the default mounting behavior and documentation.
packages/react/src/tag/tests/MdTag.test.tsx Updates tooltip-only tag expectations.
Review details

Suppressed comments (1)

packages/react/src/tooltip/MdTooltip.tsx:32

  • With this default, MdTag's tooltipOnly branch (which wraps a bare SVG and supplies no aria-label) has no accessible name while idle: the tooltip text is now unmounted, so Ariakit cannot expose it through its aria-describedby relationship until the tooltip opens. Keep that consumer's content mounted or provide an explicit accessible label before applying the new default.
  unmountOnHide = true,
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +17 to +21
it('does not mount hidden tooltips for large collections', () => {
const { baseElement } = render(
<>
{Array.from({ length: 100 }, (_, index) => {
return (
/**
* When `true`, the tooltip will be unmounted when it is hidden. This can be useful for performance reasons, but it may cause issues with animations or transitions.
* @default false
* @default true

@podeig Denis Pokotylyuk (podeig) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hei Helge, Den ser fint ut for meg. Bare se på kommentarene fra Copilot :) Bra jobba, tusen takk for fiksen! 👍

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants