Repository navigation
perf: O(1) tooltip tether registry and opt-in preventBodyPointerEvents for Dialog - #2282
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: b781979 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Contributor
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
Merged
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two performance changes for large pages.
Tooltip: tether trigger registry is O(1) per write (patch)
The tether registry copied its
Mapon 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.#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.triggersis only read from event handlers and untracked callbacks.tether.state.registry.triggersis 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):
Dialog / AlertDialog:
preventBodyPointerEventsonContent(minor)Setting
pointer-events: noneon<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.preventBodyPointerEventsdefaults totrue, which keeps today's behavior. Withfalseand aDialog.Overlayrendered, 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
preventBodyPointerEvents={false}.main.mainand this branch; they don't touch this change.