stimulus_reflex: Custom Stimulus schema breaks Reflex

Describe the bug

Reflex ignores the schema set in Stimulus. It assumes Stimulus will always use the default schema.

Line 220 in javascript/stimulus_reflex.js

 if (actionValue) element.setAttribute('data-action', actionValue)

Hardcodes the ‘data-action’ attribute.

In our project we use a custom schema as follows:

const application = Application.start(document.documentElement, {
  controllerAttribute: 'data-controller',
  actionAttribute: 'data-do',
  targetAttribute: 'data-target'
});

Because we had a conflict with another plugin, cropperjs.

Feedback would be appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (14 by maintainers)

Most upvoted comments

After reviewing both Stimulus and Reflex it can probably be fixed by simply changing ‘data-action’ to:

application.schema.actionAttribute

I tried creating a pull request but I am not allowed to, kinda new to open source contributions.

Adding a reflexAttribute to the schema would also be nice so ‘data-reflex’ can be customized.

EDIT

Adding it to the Stimulus config schema does nothing to Stimulus so you could use that as a place to store the custom Reflex attribute:

const application = Application.start(document.documentElement, {
  controllerAttribute: 'data-controller',
  actionAttribute: 'data-do',
  targetAttribute: 'data-target',
  reflexAttribute: 'data-flex'
});

Then call it in the Reflex code as:

application.schema.reflexAttribute

There should be a default set in the Reflex code though otherwise it would break the code if it isn’t set in the Stimulus schema config (because the Stimulus schema config is optional).

I made a pull request, two simple changes in the code. That should fix the issue.

Thank you for the kind words @leastbad I am implementing a private chat feature. I was doing the things Reflex does by hand but then a colleague of mine told me about the Reflex gem.

To your question about pull requests, StimulusReflex forced me to finally figure out the contribution workflow. Happy to help off-line if you want to DM me, but the basic idea is that you fork the project to your own account, make a feature branch, change that feature branch, commit it, push it, and when you push it, GitHub will prompt you to open a PR from your feature branch back to hopsoft:master. And then we all win!

Welcome to the party, @nickyvanurk. I like you already.

What kinds of things are you hoping to work on with StimulusReflex? Is there anything else that we can do to help, after we get this schema issue sorted out?

Great report. We need to update Reflex to support custom Stimulus schema.