hotwired / stimulus

A modest JavaScript framework for the HTML you already have
https://stimulus.hotwired.dev/
MIT License
12.67k stars 421 forks source link

Wrong params passed to action when multiple actions from multiple controllers #766

Closed jrmgx closed 4 months ago

jrmgx commented 4 months ago

On a link I have two actions from two different controllers chained like this:

<a data-action="click->sidebar#actionOne click->plan#actionTwo">

I have also added associated params for each action like that:

<a data-action="click->sidebar#actionOne click->plan#actionTwo"
  data-plan-tab-param="interests"
  data-sidebar-scroll-param="true"
  ...>

When I click on this link, I have both actions called, but in each one I receive the plan-tab param.

I expected to receive the plan-tab param in the plan action and the sidebar-scroll param in the sidebar action.

Note: if I reverse the order of the actions, putting first plan#actionTwo then I receive the sidebar-scroll param in both instead of the plan-tab one.

Stimulus 3.2.2

ildarkayumov commented 4 months ago

https://jsfiddle.net/ildarkayumov/02u9xjed/ I tried to create an example based on your code and it worked well

Screenshot 2024-06-02 at 11 21 19

can you try it by yourself and provide non-working example please?

jrmgx commented 4 months ago

Thank you for your time, it is exactly the case I was describing in my issue, but as you said it work well in your reproducer.

So I'm a bit confuse. It is probably on my side, there is no other explanation.

This is the actual code in context if you want to take a quick look. Note: I'm not asking anything here, but it may talk to you, if you don't have time, no worries!

Action call: https://github.com/jrmgx/trailOdysseyOpen/blob/bd4c88826aa147221dfba22bff0f22aa74a3dcc1/templates/geo/elements_frame.html.twig#L44 Plan controller: https://github.com/jrmgx/trailOdysseyOpen/blob/bd4c88826aa147221dfba22bff0f22aa74a3dcc1/assets/controllers/plan_controller.js#L66 Sidebar controller: https://github.com/jrmgx/trailOdysseyOpen/blob/bd4c88826aa147221dfba22bff0f22aa74a3dcc1/assets/controllers/sidebar_controller.js#L67

If nothing seems obvious to you, let's close that issue as it certainly a bug inside my own code.

Sorry for the wasted energy, have a good day.

ildarkayumov commented 4 months ago

@jrmgx I see that you pass all params to all actions

data-plan-tab-param="interests"
data-plan-scroll-param="true"
data-sidebar-tab-param="interests"
data-sidebar-scroll-param="true"

what would happen if you pass only needed params like this ?

data-plan-tab-param="interests"
data-sidebar-scroll-param="true"

I tried to create a new example https://jsfiddle.net/ildarkayumov/28qnyL1u/ and it works well for me too

Screenshot 2024-06-04 at 13 13 37
jrmgx commented 4 months ago

Putting all parameters to all actions is my way of mitigating the issue, that's why. But let's close it for now, there is something wrong on my side for sure. Thank you for your time, if I ever find out, I'll put a message here.

Have a good day