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

Reflex replaced with a new instance for some reason #463

Closed jordano159 closed 3 years ago

jordano159 commented 3 years ago

Bug Report

Describe the bug

When creating a simple nothing morph, i've encountered "StimulusReflex detected that the StimulusReflex Controller responsible for this Reflex has been replaced with a new instance. Callbacks and events for "nothing" or later life-cycle stages cannot be executed." I couldn't figure out what was the problem, and right now I can't use the reflexSuccess method.

my console output: image

manage_users.html.erb: <td id="level<%= user.id %>"><%= select_tag("levels", options_for_select(User.levels.keys, user.level), "data-controller": "users", "data-action": "change->users#update_user_level", "data-user-id": user.id ) %></td>

users_controller.js

import ApplicationController from './application_controller.js'

export default class extends ApplicationController {
    update_user_level(event) {
    const user_id = event.target.dataset.userId
    const level = event.target.value
    this.stimulate('User#update_user_level', user_id, level)
  }
}

user_reflex.rb:

class UserReflex < ApplicationReflex
  def update_user_level(user_id, level)
    User.find(user_id).update(level: level)
    morph :nothing
  end
end

Versions

StimulusReflex

External tools

Browser

leastbad commented 3 years ago

Hey, usually the fastest way to get support is to drop by the Discord with a link to a git repo that reproduces the issue so we can test it on our local machines. The fastest way to get up and running with a MVCE is to clone https://github.com/leastbad/stimulus_reflex_harness and just add enough code to break it.

Usually, I'd recommend re-reading https://docs.stimulusreflex.com/rtfm/reflexes#understanding-stimulusreflex-controllers but I admit that it doesn't immediately look like it should be failing in that way. Still, this is exactly why we need to see the larger context; you just never know what might be misconfigured. And honestly, about 40% of bugs can't be reproduced in the harness template, which helps developers zoom in on the real problem in their codebase just by narrowing the possibilities.

If you can link to an MVCE, we'll get this sorted out for you pronto.

leastbad commented 3 years ago

Hi @jordano159! Can you confirm whether or not this issue was resolved by updating to the master branch?

leastbad commented 3 years ago

Happy to re-open if you can give more information!

Laykou commented 3 years ago

After upgrading from 3.4.0 (which was created following the documentation on https://docs.stimulusreflex.com/hello-world/setup) to 3.5.0.pre1 I started to get the same error.

Before I dive into creating a simplified repository for this I wanted to understand what is the concept behind warned attribute?

I was not able to find it anywhere else in the code:

image

Is there also updated documentation for 3.5.0.pre1?

leastbad commented 3 years ago

Hi @Laykou I would be happy to answer your questions on Discord, as your questions are valid but unrelated to #463.

DanteZ5 commented 2 years ago

following, same trouble :-/

leastbad commented 2 years ago

Hi @DanteZ5, sorry that you're having trouble. Can you please confirm what versions of StimulusReflex and CableReady that you're running, as well as your Rails version and JS tooling stack?

Is it one Reflex that isn't working, or all of them?

Do you have a git repo we could check out? Are you on Discord? If not, you should be!

DanteZ5 commented 2 years ago

we're connected on Discord (I'm Mox). Thanks for your help, I'm still working on called reflex from stimulus controller trying to move action from connect to something like nameTargetConnected. Keep you updated

hamzaGit19 commented 1 year ago

Hi @DanteZ5 and @jordano159 , were you guys able to find a solution for this issue?

leastbad commented 1 year ago

@hamzaGit19 please jump on Discord and we'll be happy to help you sort out whatever issue you're having.