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

fix duplicate controllers in manifest on update #132

Merged
merged 2 commits into from
Nov 10, 2023

Conversation

nachiket87
Copy link
Contributor

@nachiket87 nachiket87 commented Nov 7, 2023

Fixes hotwired/stimulus#739

when typescript and js controllers are named the same. For example, hello_controller.js and hello_controller.ts and placed in the controllers folder, index.js is updated with duplicate content to register the controllers.

// 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 HelloController from "./hello_controller"
application.register("hello", HelloController)

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

@nachiket87
Copy link
Contributor Author

what do you think @adrienpoly ?

@jasonfb
Copy link

jasonfb commented Nov 8, 2023

I understand now. the controllers are written in typescript, of course, and the extra .js file are an artifact of the tsc watch process. I see what the issue is.

Copy link
Member

@adrienpoly adrienpoly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @jasonfb for confirming the reproduction of this issue. I am not familiar with tsc process generating extra .js file but if you confirm this is you issue then it looks like this will fix it.

@nachiket87 could you add a test to cover this ?

@nachiket87
Copy link
Contributor Author

Thanks for the review @adrienpoly. I've added the test here: c55a28b

The issue can be verified by removing the .uniq here: https://github.com/nachiket87/stimulus-rails/blob/c55a28b7bbdcf45a0443bf97d258a31920b1f8ab/lib/stimulus/manifest.rb#L9

@nachiket87
Copy link
Contributor Author

this PR - #77 introduced the issue.

@dhh can this be merged please.

@dhh dhh merged commit 3e168f0 into hotwired:main Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Using generator causes duplicative references in app/javascript/controllers/index.js
4 participants