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

Using generator causes duplicative references in app/javascript/controllers/index.js #739

Closed
jasonfb opened this issue Oct 31, 2023 · 6 comments · Fixed by hotwired/stimulus-rails#132

Comments

@jasonfb
Copy link

jasonfb commented Oct 31, 2023

Here I went to make a new stimulus controller with

bin/rails generate stimulus CancelSubscription

the generator did this, added it to the app/javascript/controllers/index.js but then also added duplicative references to two other stimulus controllers that were already in my app:
stimulus generator – index js 2023-10-31 10-56-32

(If you look carefully at the left margin, you see where my IDE has highlighted the newly added code import CheckoutController... and import OnboardingStartController ... below two lines of identical code.)

interestingly, it has not done the same for a 3rd controller listed in this file, don't know why.

is this a known issue?

I'm on Stimulus-rails 1.2.1

@adrienpoly
Copy link
Member

This is a stimulus-rails issue would you mind opening this issue on that repo.
can reproduce this with a blank app?
Thanks

@nachiket87
Copy link

Is this reproducable? @jasonfb

@jasonfb
Copy link
Author

jasonfb commented Nov 7, 2023

Let me work on that. It's happened for me pretty much every time I run the stimulus generator (as far as I can remember, it's always happened to me as long as I can remember)

FWIW, I build apps using JSBundling, maybe that has something to do with it.

I will create a reproduction app now to see if I can reproduce it

@nachiket87
Copy link

@jasonfb is it possible you have _controller.ts and _controller.js in the same /controllers/ folder?

I was able to reproduce in a test environment with hello_controller.js and hello_controller.ts

// This file is auto-generated by ./bin/rails stimulus:manifest:update
// Run that command whenever you add a new controller or create them with
// ./bin/rails generate stimulus controllerName

import { application } from "./application"

import CoffeeController from "./coffee_controller"
application.register("coffee", CoffeeController)

import HelloController from "./hello_controller"
application.register("hello", HelloController)

import HelloController from "./hello_controller"
application.register("hello", HelloController)

import TypeScriptController from "./type_script_controller"
application.register("type-script", TypeScriptController)

@nachiket87
Copy link

@jasonfb I've created a PR to fix this issue: hotwired/stimulus-rails#132

@adrienpoly
Copy link
Member

Closing this here as it is related to the stimulus-rails gem

PR candidate : hotwired/stimulus-rails#132

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

Successfully merging a pull request may close this issue.

3 participants