Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When searching a controller based off a reflex name, ignore hyphens #558

Merged

Conversation

g-gagnon
Copy link
Contributor

@g-gagnon g-gagnon commented Nov 3, 2021

Type of PR (feature, enhancement, bug fix, etc.)

Bug fix

Description

Stimulus controller identifiers are using kebab-case, while Reflex class name are CamelCase, which means if the controller and reflex combo are 2 or more words the controller lookup for client callbacks will fail. When it fails, it usually defaults to the first registered controller (https://github.com/stimulusreflex/stimulus_reflex/blob/master/javascript/controllers.js#L44).
It will then fail to call the callbacks if the first controller registered is a different one.

Why should this be added

It is not farfetched to have more than one controller in the page, and also to have a controller name being more than 1 word. This combo lead to unexpected behaviour like calling the wrong callbacks.

Checklist

  • My code follows the style guidelines of this project
  • Checks (StandardRB & Prettier-Standard) are passing
  • This is not a documentation update

@g-gagnon
Copy link
Contributor Author

g-gagnon commented Nov 3, 2021

Note that this code would still most likely fail if the controller/reflex is namespaced (eg.: user--settings controller, and User::SettingReflex reflex).
To support those, I assume the extractReflexName method would need to be updated, or the comparison to replace('--', '::') potentially.

@leastbad leastbad merged commit fba7631 into stimulusreflex:master Nov 12, 2021
@leastbad
Copy link
Contributor

Great catch on this, and sorry for the delay.

I had to tweak your fix slightly to support namespaced Stimulus controllers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants