flowbite icon indicating copy to clipboard operation
flowbite copied to clipboard

popover.js - memory leak

Open jjagielka opened this issue 3 years ago • 0 comments

Describe the bug popover.js - eventListeners added mutiple times

 show() {
   ...
  modifiers: [
                ...options.modifiers,
                { name: 'eventListeners', enabled: true },  // concatenation at each call
            ]

options.modifiers is an array, so the above code keep on adding new object at each call of show().

The same mistake is in hide() function.

You should change it to something like that:

function enableListeners(modifiers: Modifier<any, any>[], value: boolean) {
   const modifier = modifiers.find((x) => x.name === 'eventListeners');
   if (!modifier) return [...modifiers, { name: 'eventListeners', enabled: open }];
   modifier.enabled = value;
   return modifiers;
}

show() {
   ...
   modifiers: enableListeners(options.modifiers)
   ...

jjagielka avatar Aug 16 '22 12:08 jjagielka