Stimulus Discourse

StimulusJS and Turbolinks


#1

In the Rails world, when we using plain js or jQuery, there is the need to wait for the DOM to properly load using turbolinks:load before triggering running page load code, eg:

document.addEventListener('turbolinks:load', function(event) {
  if (typeof ga === 'function') {
    ga('set', 'location', event.data.url);
    return ga('send', 'pageview');
  }
});

What is the load order with StimulusJS. Can we assume that the DOM is fully loaded when running code in connect() or initialize() ?


#2

Yes, as of Stimulus 1.1 via https://github.com/stimulusjs/stimulus/pull/131