-
-
Notifications
You must be signed in to change notification settings - Fork 79.2k
Open
Labels
confirmedjsp3Medium priority, and does not prevent the core functionalityMedium priority, and does not prevent the core functionalityv5
Description
Prerequisites
- I have searched for duplicate or closed issues
- I have validated any HTML to avoid common problems
- I have read the contributing guidelines
Describe the issue
Bootstrap's Instances registry, by design, doesn't support multiple instances per element. However, in the rare case we are trying to re-initiate the same component for second time, it wrongly overrides the already existing instance
I found this flaw on #37195, where two tooltips were created using the same element
and is caused on this method
Lines 15 to 31 in da0fe8c
set(element, key, instance) { | |
if (!elementMap.has(element)) { | |
elementMap.set(element, new Map()) | |
} | |
const instanceMap = elementMap.get(element) | |
// make it clear we only want one instance per element | |
// can be removed later when multiple key/instances are fine to be used | |
if (!instanceMap.has(key) && instanceMap.size !== 0) { | |
// eslint-disable-next-line no-console | |
console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`) | |
return | |
} | |
instanceMap.set(key, instance) | |
}, |
Steps to reproduce
- open debugger with given breakpoint on
Line 30 in da0fe8c
instanceMap.set(key, instance) - initialize an instance of any available js component, using constructor ex:
new Toast(myelement)
- Debugger with stop on the breakpoint
- repeat the first step again ->
new Toast(myelement)
- Debugger should not stop in the same point as the instance already exists
Reduced test cases
https://codepen.io/GeosSV/pen/gOzzWYV?editors=1011
What operating system(s) are you seeing the problem on?
Windows, macOS, Android, iOS, Linux
What browser(s) are you seeing the problem on?
Chrome, Safari, Firefox, Microsoft Edge, Opera
What version of Bootstrap are you using?
v5.2.2
oemelgarejo and WinterSilence
Metadata
Metadata
Assignees
Labels
confirmedjsp3Medium priority, and does not prevent the core functionalityMedium priority, and does not prevent the core functionalityv5
Type
Projects
Status
Inbox