With apologies for the half-baked solution presented, this is the interesting parts of a polymorphic comment engine that makes use of Stimulus, StimulusReflex and CableReady.
Note that app/javascript/controllers/index.js
has to set application.consumer = consumer
This was written in the pre-morphs era, so I've done my best to fill in the blanks on what I'd do today in the Reflex.
Not shown: any view templates. Basic idea: