You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The bootstrapDelegationHandler function is invoked when the third argument of the EventHandler.on method, handler, is a selector string. It is widely used to detect components like carousel, collapse, dropdown, modal, offcanvas, and tab based on their data attributes. In these cases, the first argument of bootstrapDelegationHandler, element, is typically set to document.
As a result, Bootstrap executes multiple DOM selector queries against the entire DOM tree every time an event is triggered to check if the event is related to a specific component. For instance, with click events in the default bundle (loading all components), this can result in 11 DOM queries, causing noticeable delays depending on the DOM tree size and the user's device.
Motivation and context
Proposed Implementation
I suggest replacing the current DOM traversal logic with the more efficient Element.closest method, which simplifies the implementation and improves performance. Here's the proposed code:
The Element.closest method is widely supported in modern browsers, aligning with Bootstrap's browser compatibility requirements. https://caniuse.com/element-closest
If there are any potential side effects or edge cases I might have overlooked, I would greatly appreciate your feedback.
The text was updated successfully, but these errors were encountered:
Prerequisites
Proposal
Hello Bootstrap team,
I have a suggestion to simplify and potentially optimize the
bootstrapDelegationHandler
function inevent-handler.js
.Current Behavior
bootstrap/js/src/dom/event-handler.js
Lines 102 to 122 in 0cbfe13
The
bootstrapDelegationHandler
function is invoked when the third argument of theEventHandler.on
method,handler
, is a selector string. It is widely used to detect components likecarousel
,collapse
,dropdown
,modal
,offcanvas
, andtab
based on their data attributes. In these cases, the first argument ofbootstrapDelegationHandler
,element
, is typically set todocument
.For example:
bootstrap/js/src/dropdown.js
Line 444 in 0cbfe13
As a result, Bootstrap executes multiple DOM selector queries against the entire DOM tree every time an event is triggered to check if the event is related to a specific component. For instance, with click events in the default bundle (loading all components), this can result in 11 DOM queries, causing noticeable delays depending on the DOM tree size and the user's device.
Motivation and context
Proposed Implementation
I suggest replacing the current DOM traversal logic with the more efficient
Element.closest
method, which simplifies the implementation and improves performance. Here's the proposed code:The
Element.closest
method is widely supported in modern browsers, aligning with Bootstrap's browser compatibility requirements.https://caniuse.com/element-closest
If there are any potential side effects or edge cases I might have overlooked, I would greatly appreciate your feedback.
The text was updated successfully, but these errors were encountered: