Skip to content

perf: O(1) tooltip tether registry and opt-in preventBodyPointerEvents for Dialog - #2282

Merged
huntabyte merged 1 commit into
mainfrom
hunter/upstream-bits-ui-perf-patches
Nov 10, 2026
Merged

huntabyte merged 1 commit into
mainfrom
hunter/upstream-bits-ui-perf-patches

Conversation

@huntabyte

Copy link
Copy Markdown
Owner

Two performance changes for large pages.

Tooltip: tether trigger registry is O(1) per write (patch)

The tether registry copied its Map on every register, update, and unregister, so mounting n triggers on one tether cost O(n²). The map is now mutated in place. Only the active trigger's record is read reactively, through a version counter that is bumped when that record changes.

  • No behavior change. #coerceActiveTrigger() was a no-op after register/update, because the record's id is always in the map at that point, so it is removed.
  • Inside bits-ui, triggers is only read from event handlers and untracked callbacks. tether.state.registry.triggers is reachable from outside but undocumented, and reading it reactively would now go stale.

Mount and unmount of n triggers on one tether (dev-compiled Svelte, Chromium, median of 5):

n before mount / unmount after mount / unmount
500 34ms / 12ms ~25ms / 2ms
2,000 180ms / 188ms 90ms / 6ms
5,000 950ms / 1290ms 215ms / 18ms

Dialog / AlertDialog: preventBodyPointerEvents on Content (minor)

Setting pointer-events: none on <body> restyles every element on the page, because the property is inherited. On a synthetic flat DOM, one toggle costs 9ms in Chromium and 38ms in WebKit at 30k nodes, and 37ms / 164ms at 120k nodes. Each open and each close pays it.

preventBodyPointerEvents defaults to true, which keeps today's behavior. With false and a Dialog.Overlay rendered, the overlay blocks the page instead and the body is not touched. Without an overlay, the body is still blocked. A pointer-blocking layer opened inside the dialog, such as a dropdown menu, still blocks the body while it is open. The scroll lock handles this with a reactive "any active lock needs pointer blocking" check, which also covers an overlay that mounts after the content.

This is opt-in rather than the default because it changes behavior in edge cases. With false, elements stacked above the overlay that aren't part of the dialog (toasts, a higher-z header) receive pointer events, and an overlay that doesn't cover the viewport lets clicks through. Outside-click dismissal does not depend on the body style, so it is unaffected.

Tests

  • Tooltip: the tether's active payload stays current while 200 other triggers mount and unmount. Removing the version bump fails this test and an existing detach test.
  • Dialog: three tests cover preventBodyPointerEvents={false}.
    • With an overlay, the body is left alone and clicking the overlay still closes the dialog.
    • Without an overlay, the body is still blocked.
    • A menu inside the dialog blocks the body while open, and the body is restored after it closes.
    • The first and third fail on main.
  • Lint, format, svelte-check (bits-ui, tests, docs), and the bits-ui unit tests pass. Locally, a group of focus/keyboard browser tests time out on both main and this branch; they don't touch this change.

@changeset-bot

changeset-bot Bot commented Nov 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b781979

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

This PR includes changesets to release 1 package
Name Type
bits-ui Minor

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 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
bits-ui ✅ Ready (View Log) Visit Preview b781979

This branch was successfully deployed

1 active deployment
Preview — b7819794 Deployed Nov 5, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant