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

Nested SimpleBars Cause Multiple Initializations #295

Closed
CreativeTechGuy opened this issue Apr 9, 2019 · 3 comments
Closed

Nested SimpleBars Cause Multiple Initializations #295

CreativeTechGuy opened this issue Apr 9, 2019 · 3 comments

Comments

@CreativeTechGuy
Copy link

Current Behavior

When nested SimpleBars are initialized from JavaScript, the MutationObserver will trigger a re-initialization of the children.

Expected behavior

The MutationObserver shouldn't re-initialize a simplebar with default options when it has already been created.

Reproducible example

Demo. The settings for autoHide are set to false for all .scroll-areas, but the child scroll area is initialized a second time due to the MutationObserver detecting the change of the first one. This causes the settings to get overwritten for the child and the autoHide is re-enabled.

Suggested solution(s)

MutationObserver should not re-initialize elements with a data-simplebar attribute set to init.

Your environment

Software Version(s)
SimpleBar 3.1.5
Browser Chrome 73
Operating System Windows 10
@CreativeTechGuy
Copy link
Author

A temporary solution for anyone affected is to add the following line to the top of their script.

SimpleBar.removeObserver()

This will completely disable the MutationObserver and only allow manual initialization, thereby avoiding the problem.

@Grsmto
Copy link
Owner

Grsmto commented Apr 12, 2019

Should be fixed in [email protected]!

@Grsmto Grsmto closed this as completed Apr 12, 2019
@Grsmto Grsmto reopened this Apr 22, 2019
@Grsmto
Copy link
Owner

Grsmto commented Apr 23, 2019

FYI I reverted the fix for this as it wasn't actually working properly.
I think the right way of fixing this issue is to either:

  • disable the global mutation observer, just like you did
  • pass options via data attribute and let the mutation observer do the job. So not instantiate manually

@Grsmto Grsmto closed this as completed Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants