Skip to content

[tooltip] Avoid re-rendering inactive detached triggers on open and close - #5893

Closed
willhoney7 wants to merge 2 commits into
mui:masterfrom
willhoney7:fix/tooltip-detached-trigger-rerenders
Closed

willhoney7 wants to merge 2 commits into
mui:masterfrom
willhoney7:fix/tooltip-detached-trigger-rerenders

Conversation

@willhoney7

@willhoney7 willhoney7 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

With detached triggers (one Tooltip.Root with a handle, many Tooltip.Triggers), opening or closing the tooltip re-renders every trigger, not just the one that opened it.

Reproduction: https://stackblitz.com/github/willhoney7/base-ui-detached-trigger-rerenders?file=src%2FApp.tsx

Each trigger subscribes to store.useState('triggerProps', isMountedByThisTrigger), which returns inactiveTriggerProps for inactive triggers. The root's interaction hooks only mount while the tooltip is open (open || mounted). While they are mounted, usePopupInteractionProps syncs useDismiss's trigger handlers into inactiveTriggerProps. On unmount it resets them to EMPTY_OBJECT. So the object identity changes on every open and every close, and every inactive trigger re-renders.

But inactive triggers only apply the root trigger props when trackCursorAxis !== 'none'. Otherwise TooltipTrigger throws them away, so in the default case those re-renders do nothing.

Fix

Override the shared triggerProps(state, isActive) selector in TooltipStore:

  • An active trigger gets activeTriggerProps.
  • An inactive trigger gets inactiveTriggerProps only when cursor tracking is on, and undefined otherwise.

Because the selector returns a stable undefined in the default case, inactive triggers no longer re-render when the props object swaps. This replaces TooltipTrigger's shouldApplyRootTriggerProps check, so behavior doesn't change.

Impact

Measured in jsdom with 5 triggers under StrictMode, counting extra renders per inactive trigger:

Open Close
Before 4 4
After 0 0

We hit this in an app with about 2,000 tooltip triggers on a page sharing one handle. Each hover re-rendered all of them, twice per hover (once on open, once on close). We're currently patching around it locally.

Tests

Added "does not re-render inactive triggers when the tooltip opens and closes" to TooltipRoot.detached-triggers.test.tsx. It runs in Chromium only, alongside the existing multiple-detached-triggers tests. It fails without the fix (inactive render counts [12, 12] vs [4, 4]) and passes with it.

Related

Popover, PreviewCard, and Dialog share the same root cause: interaction hooks that mount only while open and swap inactiveTriggerProps. Because inactive triggers there do apply the props, the fix there is less local. I'll open a separate issue for that, plus a separate PR for an additional Popover-only cause (triggers subscribing to openChangeReason and openMethod).

…lose

Co-authored-by: Cursor <cursoragent@cursor.com>
@pkg-pr-new

pkg-pr-new Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

commit: 6d0fcf3

@code-infra-dashboard

code-infra-dashboard Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+79B(+0.02%) 🔺+17B(+0.01%)

Details of bundle changes

Performance

Total duration: 448.01 ms -8.22 ms(-1.8%) | Renders: 76 (+0) | Paint: 817.76 ms -15.48 ms(-1.9%)

Test Duration Renders
Mixed surface mount (app-like density) 46.33 ms 🔺+9.28 ms(+25.1%) 5 (+0)
Dialog mount (300 instances) 11.82 ms ▼-3.42 ms(-22.4%) 1 (+0)

13 tests within noise — details

Metric alarms

Test Metric Change
Mixed surface mount (app-like density) bench:paint 🔺 +13.25 ms

Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 6d0fcf3
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6ac4f6640e3727000862e25d
😎 Deploy Preview https://deploy-preview-5893--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@willhoney7

Copy link
Copy Markdown
Contributor Author

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+93B(+0.02%) 🔺+24B(+0.01%)
Details of bundle changes

Performance

Total duration: 627.03 ms 🔺+129.81 ms(+26.1%) | Renders: 76 (+0) | Paint: 1,134.88 ms 🔺+257.84 ms(+29.4%)

Test Duration Renders
Select mount (200 instances) 72.31 ms 🔺+20.84 ms(+40.5%) 3 (+0)
Slider mount (300 instances) 68.26 ms 🔺+16.28 ms(+31.3%) 2 (+0)
Checkbox mount (500 instances) 55.68 ms 🔺+15.27 ms(+37.8%) 1 (+0)
Scroll Area mount (300 instances) 55.42 ms 🔺+13.92 ms(+33.5%) 3 (+0)
Mixed surface mount (app-like density) 57.05 ms 🔺+12.68 ms(+28.6%) 5 (+0)
…and 7 more (+3 within noise) — details

Metric alarms

Test Metric Change
Select mount (200 instances) bench:paint 🔺 +31.73 ms
Slider mount (300 instances) bench:paint 🔺 +29.85 ms
Checkbox mount (500 instances) bench:paint 🔺 +28.36 ms
Scroll Area mount (300 instances) bench:paint 🔺 +24.85 ms
Mixed surface mount (app-like density) bench:paint 🔺 +21.69 ms
…and 11 more metric alarms — details

Check out the code infra dashboard for more information about this PR.

these numbers seem off? I don't know how Select or Slider or any of these could be worse from my changes...

@michaldudak

Copy link
Copy Markdown
Member

Thanks for your contribution! Don't worry about the perf test results as they are sometimes inaccurate.
I'd rename the new selector from appliedTriggerProps to just triggerProps (overriding the shared selector). Aside from that, this looks good.

…ggerProps

Co-authored-by: Cursor <cursoragent@cursor.com>
@willhoney7

Copy link
Copy Markdown
Contributor Author

Thanks for your contribution! Don't worry about the perf test results as they are sometimes inaccurate. I'd rename the new selector from appliedTriggerProps to just triggerProps (overriding the shared selector). Aside from that, this looks good.

done! should be good to go now

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 7, 2026
@willhoney7

Copy link
Copy Markdown
Contributor Author

I think this has been superseded! Going to close, will reopen if needed

@willhoney7 willhoney7 closed this Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: tooltip Changes related to the tooltip component. performance PR: out-of-date The pull request has merge conflicts and can't be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants