I’m inserting within the post, yes. That’s why I suspect execution order.
Some bit of code determines the execution order… that’s the leverage point for me to get my component before TOC. eg, if it’s alpha by component name (ie, as displayed in the Component list in Admin area) then I can try namin my component accordingly, etc
That said, you can set initializer order for advanced use cases. I can put DiscoTOC in a named initializer so you can run your code before DiscoTOC, but I need to know what you’re trying to do first to give you a clear answer.
Your modifications here are based on an HTTP/AJAX request, correct?
Yes AJAX, but using a synchronous call. (I’ve always loved the oxymoron of synchronous AJAX :^)
I’m feeling like my next step is create a proper component—atm, it’s just some j/s pasted into my Theme’s Header. Then I can try fiddling with a judiciously chosen ID. “_foo” or “0-foo” might be all I need.
Replies by others above suggest the name of the component does not affect the execution order. I’ve just renamed them to be aa-mycomponent and x-last-DiscoTOC and it doesn’t work. [DiscoTOC doesn’t include headings added to the DOM dynamically—yes, within the post body]
@Johani any further ideas from your May train of thought?
Well, I think you could prove that out either way by trying a very basic example.
Create two simple components, overriding or connecting the same thing, perhaps a simple template with a slight difference, call one by a name starting later in the alphabet, note which one ends up overriding the theme.
It’s very clearly ordered by name in the code here in the model:
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.