stimulusreflex / stimulus_reflex

Build reactive applications with the Rails tooling you already know and love.
https://docs.stimulusreflex.com
MIT License
2.28k stars 172 forks source link

Promises just resolve with last Partial DOM update #171

Closed marcoroth closed 4 years ago

marcoroth commented 4 years ago

Bug Report

Describe the bug

While working on #163 I noticed that promises just resolve with the last Partial DOM update event if there are multiple data-reflex-root defined. The cable-ready:before-morph event gets fired for every data-reflex-root once and therefore the promise is just resolved with the last update event.

I don't know if this is a big real world issue but I noticed it because I wanted to rely on the update events provided by the promise individually .

Related: #142

To Reproduce

Setup the Partial DOM Updates as described in the docs example with multiple data-reflex-root and any Reflex on the server-side.

<div data-controller="example" data-reflex-root="[forward],[backward]">
  <input type="text" value="<%= @words %>" data-action="keyup->example#words">
  <div forward><%= @words %></div>
  <div backward><%= @words&.reverse %></div>
</div>
// example_controller.js

// ...

words() {
  this.stimulate('ExampleReflex#words').then(payload => {
    const { data, element, event } = payload;
    // => event just contains the last update event
  });
}

Expected behavior

Either the promise returns an array of events or there is another way to rely on all fired events in context with this stimulate call.

Versions

StimulusReflex

External tools

Browser

leastbad commented 4 years ago

It’s a leaky abstraction. Giving every call a uuid was the first step towards creating a coherent and unified structure for all of this... but there is work to be done.

🤔

marcoroth commented 4 years ago

Resolved via #163