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

Use Global Regex for Stimulus Configuration #865

Merged
merged 4 commits into from
Mar 16, 2024

Conversation

MSILycanthropy
Copy link
Contributor

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 identifier do-a_thing, when one would expect it to have been do-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.

@jaredcwhite
Copy link
Member

Thanks @MSILycanthropy! FYI I took the liberty of committing a fix for the regex backslash so it carries over to the JS code from the Ruby heredoc. I know, confusing! (Otherwise the JS file would just have /// istead of /\//.)

@jaredcwhite jaredcwhite merged commit a260a4b into bridgetownrb:main Mar 16, 2024
4 checks passed
@MSILycanthropy MSILycanthropy deleted the stimulus_global_regex branch March 16, 2024 19:36
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