Erik Huang

Joined

50 Experience
0 Lessons Completed
0 Questions Solved

Activity

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.