Skip to content

Using action option changes the order of actions #718

@janko

Description

@janko

In certain situations, using an action option such as :prevent can change the order in which actions registered in the same data-action are executed.

Here is a self-contained example demonstrating the problem:

<html>
  <head>
    <script type="module">
      import { Application, Controller } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"
      window.Stimulus = Application.start()
      Stimulus.debug = true
      Stimulus.register("one", class extends Controller {
        foo() {}
      })
      Stimulus.register("two", class extends Controller {
        bar() {}
      })
    </script>
  </head>
  <body>
    <div data-controller="two">
      <div data-controller="one">
        <a href="#" data-action="one#foo two#bar">Click me</a>
      </div>
    </div>
  </body>
</html>

Without the action option, the debug output shows the correct order:

one #foo
two #bar

However, if I use an action option:

<a href="#" data-action="one#foo:prevent two#bar">Click me</a>

The debug output shows the order in which actions are executed has changed:

two #bar
one #foo

This seems like a bug to me. I encountered it in a scenario where the order of actions was important, and it took me a while to realize it's because of the action option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions