Repository navigation
Resolve Dialog root containers in linear time - #3907
Open
MomchilGorchev wants to merge 2 commits into
Open
MomchilGorchev wants to merge 2 commits into
MomchilGorchev wants to merge 2 commits into
Conversation
|
@MomchilGorchev is attempting to deploy a commit to the Tailwind Labs Team on Vercel. A member of the Team first needs to authorize it. |
santiagoGuti
approved these changes
Oct 23, 2026
This branch has not been 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.
useRootContainerscollects the elements that count as "inside" aDialog. For eachhtml > *, body > *element, it checks whether that element contains any container resolved so far, including the root elements it has already pushed. That list grows by one per root element, so resolving the containers is quadratic in the number of<body>children.This runs on every outside click check while a
Dialogis open. On most pages<body>has a few dozen children, so it doesn't matter. We have production sessions where something outside the app, most likely a browser extension, leaves 7,000 to 18,000 elements in<body>. In those sessions every click inside an openDialogblocks the main thread for 1 to 5 seconds, all of it inside theuse-outside-clickdocument listener.Root elements are siblings, so one can never contain another. This PR compares each root element only with the default containers and portals, which is what the existing comment on that line describes. The resolved containers are the same, and the loop is linear.
Time per click inside an open
Dialog(longest animation frame, Chromium, 2.2.2 with this change applied as a patch):<body>childrenChanges:
useRootContainersin@headlessui/reactand@headlessui/vue.Dialogtest in each package that countsNode.prototype.containscalls for one click with 1,000 extra<body>children. It fails onmain(502,503 calls against a limit of 50,000) and passes with this change.