Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/tooltip.js Optimization #35734

Merged
merged 1 commit into from
Feb 25, 2022
Merged

Conversation

dilyanpalauzov
Copy link
Contributor

Util.findShadowRoot() returns either null or an object.

It cannot return falsy, which allows this optimization.

@alecpl
Copy link
Contributor

alecpl commented Jan 31, 2022

Maybe something like this could work too?:

--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -245,12 +245,11 @@ class Tooltip extends BaseComponent {
     }
 
     const showEvent = EventHandler.trigger(this._element, this.constructor.Event.SHOW)
-    const shadowRoot = findShadowRoot(this._element)
-    const isInTheDom = shadowRoot === null ?
-      this._element.ownerDocument.documentElement.contains(this._element) :
-      shadowRoot.contains(this._element)
 
-    if (showEvent.defaultPrevented || !isInTheDom) {
+    if (showEvent.defaultPrevented
+      || findShadowRoot(this._element)
+      || !this._element.ownerDocument.documentElement.contains(this._element)
+    ) {
       return
     }
 

Util.findShadowRoot() returns either null or an object.

It cannot return falsy, which allows this optimization.
@mdo mdo force-pushed the tooltip_js_optimization_v5 branch from ff4dd75 to 7b160bb Compare February 25, 2022 16:56
@mdo mdo merged commit e4b62a9 into twbs:main Feb 25, 2022
@dilyanpalauzov dilyanpalauzov deleted the tooltip_js_optimization_v5 branch February 25, 2022 17:46
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.

4 participants