es-module-shims
es-module-shims copied to clipboard
Double imports
I'm using Ruby 3.2.2 and Rails 7.1 with TailwindCSS, ViewComponents, Hotwire Turbo and Stimulus. In order to get the app running on old Safari browsers, I included es-module-shims in the app layout as first import, before the Rails Importmap tag helper. This led to all my Stimulus JS controllers getting imported twice. This led to all eventHandlers being added twice, and all events firing twice, causing unexpected behaviour especially on toggle buttons.
Expected behaviour:
- Import JS files once
Faulty behaviour:
- JS files imported twice
Steps to reproduce:
- Create a new Rails app with -c tailwindcss
- add view-components gem (probably unrelated)
- create Stimulus controllers
- start server
Solution:
- remove es-module-shims
My provided solution is merely a workaround, since I need the functionality that es-module-shims offers. I'll have to look for an alternative now.