Ensure sibling controller readiness?

You’re welcome! I have to admit that I’m no expert on microtask queues but Sam touches it briefly here:

Stimulus responds to document changes in the next tick of the microtask queue .

In JavaScript, the easiest way to queue a microtask is to wait on an empty promise

What I think is happening, is that the loop which is responsible for registering the controllers is a part of the current tick of the microtask queue. According to this (incredibly well written) guide, any additional microtasks queued during microtasks are added to the end of the queue. This explains why the loop gets to finish registering the controllers before your empty promise (which is enqueued as a microtask) is resolved.

1 Like