stimulus-components icon indicating copy to clipboard operation
stimulus-components copied to clipboard

rails stimulus:manifest:update removes components from manifest

Open ophilbert opened this issue 3 years ago • 2 comments

Hello,

Having an issue with the way we import stimulus components. Every component installation is made using yarn install stimulus-component-xyz and manually editing index.js to add the new component.

My problem lies with the command found on hotwired/stimulus-rails

rails stimulus:manifest:update

I use it to add my own controllers and ensure old ones are removed from the index.js The problem is that it also removes the stimulus component i added manually.

What's expected

Stimulus components import method should not be deleted when using rails stimulus:manifest:update. I doubt it's doable though since we have no control over this. At least documentation should warn us from using that command and provide an alternative since hotwired is the default way in rails 7 this will probably happen to more people.

What's happening

Running rails stimulus:manifest:update removes all manually added stimulus components

Repro

  1. clone the repository

  2. notice app/javascript/controllers/index.js contains:

import ScrollTo from 'stimulus-scroll-to
application.register('scroll-to', ScrollTo)
  1. Run rails stimulus:manifest:update
  2. Notice that app/javascript/controllers/index.js no longer holds references to scrollTo component

Should I just stop using rails stimulus:manifest:update and only create my controllers using rails generate stimulus controllerName ?

Thank you

ophilbert avatar Apr 25 '22 07:04 ophilbert

@ophilbert I am having the same issue, would you mind share what's your final approach? 😊

hungmi avatar Jul 27 '22 05:07 hungmi

I ended up stopping using rails stimulus:manifest:update

and manually editing the index file. Not the best solution but I don’t add new controllers every day so it’s fine this way.

Le mer. 27 juil. 2022 à 07:21, Hungmi @.***> a écrit :

@ophilbert https://github.com/ophilbert I am having the same issue, would you mind share what's your final approach? 😊

— Reply to this email directly, view it on GitHub https://github.com/stimulus-components/stimulus-components/issues/47#issuecomment-1196277853, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN3ITIEYEFDB7OTXTF3WI3VWDBOTANCNFSM5UHSYO4Q . You are receiving this because you were mentioned.Message ID: @.***>

-- Olivier Philbert

ophilbert avatar Jul 27 '22 17:07 ophilbert

Yeah I think stimulus:manifest:update is more for local controllers 👍

guillaumebriday avatar Jun 16 '23 04:06 guillaumebriday

A solution might be to register Stimulus Components via an alternate components.js file.

  1. Create the file app/javascript/components.js
// app/javascript/components.js
import { application } from "./controllers/application"
 
import Autosave from 'stimulus-rails-autosave'
application.register('autosave', Autosave)
  1. Import components.js by adding this line to app/javascript/application.js:
// app/javascript/application.js
...
import "./components"
...

This way, app/javascript/controllers/index.js can be used for local controllers only, and app/javascript/components.js for manually installed Stimulus Components.

fvue avatar Feb 06 '24 12:02 fvue