I'll try to explain what I'm asking as simple as possible.
I'm writing a controller named parent. This is the starting HTML:
<div data-controller="parent">
<!-- ... -->
</div>
After the controller kicks in, the DOM will be modified this way (because how the JavaScript library I'm using):
<div class="wrapper">
<div data-controller="parent">
<!-- ... -->
</div>
</div>
Problem 1: the controller named parent re-run. This is not my intended behavior. I've managed to fix it using the plugin onInit hook, simply deleting the data-controller attribute:
connect() {
new MyPlugin(this.element, {
onInit: () => {
delete this.element.dataset.controller; // <-- this will avoid re-run of parent controller
}
});
}
Problem 2 the problem is much worst with "child" controllers. Stimulus will run twice: on load and on DOM modifications:
<div class="wrapper">
<div data-controller="parent">
<div data-controller="child"></div>
</div>
</div>
Any idea on how to solve this (like "disable watching DOM modifications" is much appreciated, thanks.
I'll try to explain what I'm asking as simple as possible.
I'm writing a controller named
parent. This is the starting HTML:After the controller kicks in, the DOM will be modified this way (because how the JavaScript library I'm using):
Problem 1: the controller named
parentre-run. This is not my intended behavior. I've managed to fix it using the pluginonInithook, simply deleting thedata-controllerattribute:Problem 2 the problem is much worst with "child" controllers. Stimulus will run twice: on load and on DOM modifications:
Any idea on how to solve this (like "disable watching DOM modifications" is much appreciated, thanks.