Ask A Question

Notifications

You’re not receiving notifications from this thread.

Updated to Ruby 3.1.2, now targets in Stimulus Controllers not working

Erik Huang asked in Javascript

I am using Rails 6 and recently upgraded from Ruby 3.0.1 to 3.1.2. Since the upgrade for some reason, my reflexes are no longer working properly when invoked from stimulus controllers, as shown in profile-form#addTag():

app/javascript/controllers/application_controller.js

import { Controller } from '@hotwired/stimulus';
import StimulusReflex from 'stimulus_reflex';

export default class extends Controller {
  connect() {
    StimulusReflex.register(this);
  }

  getControllerByIdentifier(identifier) {
    return this.application.controllers.find((controller) => {
      return controller.context.identifier === identifier;
    });
  }

  beforeReflex(element, reflex) {
    console.log("Before")
  }

  afterReflex(element, reflex) {
    console.log("After")
  }
}

app/javascript/controllers/profile_form_controller.js

import ApplicationController from './application_controller';

export default class extends ApplicationController {
  static targets = ['form'];

  connect() {
    super.connect();
  }

  addTag(event) {
    this.stimulate("ProfileForm#add_tag", this.formTarget);
  }
}

ActionCable seems to be working properly, and when I console log in the stimulus callbacks, I can verify beforeReflex is returning but not afterReflex. This is only happening when I pass a stimulus data target in to this.stimulate() so:

this.stimulate(event.target) behaves as expected but this.stimulate(this.formTarget) does not.

Anyone happen across this issue before? I'd be happy to provide more context if needed.

Reply

Maybe not a good answer. I ran into a problem upgrading to 3.1.2 and just rolled back to 3.0.2. Not the same problem as yours. My thinking was I didn't need the latest and that eventually the problem would be fixed. And I was on Rails 7, so would assume fewer issues. My notes:

Downgraded to ruby-3.0.2 because of visit_Psych_Nodes_Alias': Cannot load database configuration: (Psych::BadAlias) error on launch (https://stackoverflow.com/questions/71191685/visit-psych-nodes-alias-unknown-alias-default-psychbadalias)

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.