Use Global Regex for Stimulus Configuration #865
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a 🐛 bug fix.
Summary
When using the Stimulus Configuration, the generated code for loading Stimulus controllers makes a couple
replace
calls to translate a path to a Stimulus identifier.This means that if you have a controller whose filename is
do_a_thing_controller.js
, this gets translated into the Stimulus identifierdo-a_thing
, when one would expect it to have beendo-a-thing
. There case for controllers nested in directories is similar.With the way Stimulus currently works, it's incredibly annoying to debug this, because there are no warnings. Your controller just seemingly doesn't work.
Context
When building my personal site with Bridgetown and Hotwire, I added a controller that used multiple underscores, and then spent an embarrassing amount of time trying to figure out what I had done wrong. Was surprised to see that only one replacement had taken place.