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

Multiple init() calls are initiated by MutationObserver callback #149

Closed
stopdesign opened this issue Dec 8, 2020 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@stopdesign
Copy link

stopdesign commented Dec 8, 2020

In preInit you set the MutationObserver callback. It calls init() multiple times because mutationsList could have many MutationRecords. Some (all) of them could have inputField inside. For example, in my case I have 3 records:
Screenshot 2020-12-08 at 18 22 21

https://tarekraafat.github.io/autoComplete.js/demo/ is affected. I see 9 init() calls.

Affected versions: >= 8.0.0.

OSX, Chrome 87.0.4280.67, Safari Version 13.0.4.

To Reproduce: visit the demo, open debug console, type any character and look at number of generic.json requests you have. I have 9 for each keypress event.

Expected behavior:

  1. Only one init() call.
  2. Possibility to call init() manually (preInit approach is incompatible with onload() initialisation).
@stopdesign stopdesign added the bug Something isn't working label Dec 8, 2020
@TarekRaafat
Copy link
Owner

Hello @stopdesign,

The input field observer is already set to fire the init() function only one time after fulfilling the required condition which is the availability of the input field element, and then the observer disconnects automatically so it doesn't fire ever again as long as the input field exists.

I've tried reproducing the reported behavior on the same mentioned browsers, versions, and operating system but unfortunately couldn't get the same results as yours.

My initial assumption is that you might be using a class for the input selector or the same id maybe.

Please try to share any more details that might help in debugging that weird behavior.

I'm thinking about availing an API for the observer to be able to turn it on/off. What do you think about that?

Have a nice day, cheers! :)

@cedbesafilm
Copy link

cedbesafilm commented Dec 9, 2020

@TarekRaafat i have the same problem (i opened the issue for the feature request #89)

Every event is triggered multiple time (include init), in my case 35

image

First Test
image
image

Second Test
image
image
and so on....

Sorry for the quality of code but i wrote it in hurry for the issue 😄

For the sake of completeness i use bootstrap and mdbootstrap but i don't think it's related

and i found this in th Event Listeners tab on Chrome

image

@TarekRaafat
Copy link
Owner

Hello @stopdesign and @cedbesafilm,

Thanks for your patience.

I have added a new API in v8.1 that controls the observer by turning it on/off it's off by default.

Hope this is convenient for you for the time being until I fix this issue, awaiting your feedback.

Have a nice day, cheers! :)

@cedbesafilm
Copy link

With default settings now the problem it's solved for me 😄

@TarekRaafat
Copy link
Owner

@cedbesafilm that's great! I'm glad to hear that your problem is solved.

Please let me know if you need any further support.

Have a nice day, cheers! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants