You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My expectation was that (once app.js is loaded and cached by the browser) this would be immediately executed as soon as the node the controller is registered on is started to be processed by the browser.
However, in actuality it kind of looks like all Stimulus controllers are only initialized once the whole page finished loading - i.e. it almost looks like everything is only processed on DOMContentLoaded. I assumed that stimulus controllers would be initialized as soon as possible via Mutation observers. Thus in this case the body class is added too late for my use case.
Or another example would be the click action for a menu button - the event listener only seems to be added once the whole DOM was loaded, meaning that on a large page the menu button (which is at the very top of the page typically) does nothing for quite some time.
Was my expectation wrong? Or is there something wrong with my setup. In my case I use webpack - together with hotwired/stimulus-webpack-helpers. The app.js looks like this for example:
However, in actuality it kind of looks like all Stimulus controllers are only initialized once the whole page finished loading - i.e. it almost looks like everything is only processed on DOMContentLoaded
Ideally though it would be great if Stimulus controllers and actions are initialised as soon as possible - otherwise it might take a long time until event listeners are registered for example, e.g. when the DOM is large (see menu button example above).
However, I realise this might be tricky to implement, especially if controllers depend on each other.
I have a question or may be a misconception about the life cycle of Stimulus controllers.
Let's say I have a simple controller that toggles a
<body>
class and stores that state inlocalStorage
:Now I also want to restore that body class state which is saved in
localStorage
. My initial though was to put that into theinitialize()
method:My expectation was that (once
app.js
is loaded and cached by the browser) this would be immediately executed as soon as the node the controller is registered on is started to be processed by the browser.However, in actuality it kind of looks like all Stimulus controllers are only initialized once the whole page finished loading - i.e. it almost looks like everything is only processed on
DOMContentLoaded
. I assumed that stimulus controllers would be initialized as soon as possible via Mutation observers. Thus in this case the body class is added too late for my use case.Or another example would be the click action for a menu button - the event listener only seems to be added once the whole DOM was loaded, meaning that on a large page the menu button (which is at the very top of the page typically) does nothing for quite some time.
Was my expectation wrong? Or is there something wrong with my setup. In my case I use webpack - together with
hotwired/stimulus-webpack-helpers
. Theapp.js
looks like this for example:The text was updated successfully, but these errors were encountered: