Is it intentional that parent controllers also listens to actions within child controller?

Hi :wave:,

Using example from https://stimulusjs.org/reference/actions#global-events, I have the following gallery controllers nested:

<div data-controller="gallery">
  <div data-controller="gallery"
       data-action="resize@window->gallery#layout">
    …
  </div>
</div>

I found out that the parent gallery controller also listens to the child action. Is this intentional? If this is intended, do you have advice on how to make the parent controller not listening to the child action?

I’m using Stimulus 1.1.1

Hey @firewalker06!

I realized I was completely mistaken in my initial response and that Stimulus does support nested scopes that allow controllers to be nested without the type of duplication you’re seeing. This was discussed here. So doubling up on window events (which I’m able to reproduce) seems like a bug. Good catch! Apologies for the earlier, misleading response!

No problem. Thanks for the reference and confirming this bug, @welearnednothing.

This does appear to be a bug with global actions. Reproduced here: https://codepen.io/javan/pen/JjYMYKO?editors=1010. Would you mind opening an issue on GitHub?

1 Like