You have to ensure the receiving controller is connected and setTimeout
is a perfectly valid way to do that. Another solution is to wait on an empty promise:
connect: ->
Promise.resolve().then =>
@outlet.dispatchEvent(new CustomEvent('updatePreview', detail: { preview: "<strong>Hiya</strong>" }))
That’s mostly true. Both controllers are initialized synchronously because they appear in the DOM at the same time. Here’s a very simplified of what Stimulus does:
[ ParentController, MultiWordChildController ].forEach(controllerConstructor => {
const controller = new controllerConstructor()
this.application.controllers.push(controller)
controller.initialize()
controller.connect()
})
Your ParentController instance can’t find the MultiWordChildController instance because the forEach lo…