What controls the order of execution for Theme components' j/s?

The Name doesn’t affect execution order. @merefield the line you linked affects how they’re displayed in the admin UI, but isn’t used for the actual execution.

This is the relevant line for execution order:

So they are executed in ascending order of ‘id’ in the database.

The only guarantee that’s portable across Discourse instances is that theme code is always executed before theme component code.

As @Johani mentioned above, if you have need to run code after some other component has loaded, the best bet is probably to use an Ember initializer, which supports ordering. Unfortunately that won’t be possible straight away in this case, since it doesn’t look like DiscoTOC is using Ember initializers. Updating DiscoTOC to use multi-file javascript (and therefore ember initializers) would certainly be pr-welcome

3 Likes