New lifecycle callback for Turbolinks


I’m currently using Turbolinks along with Stimulus, and I think it would be useful to have a new lifecycle method that gets called once and is not called again for Turbolinks visits. This is helpful for “higher-order controller” that manage state for the entire browsing session. This is simply an optimization, because without Turbolinks, everything will be reloaded again on every page load anyways.


Does the initialize callback not handle this? Is it being called on Turbolinks visits?

Am I reading this wrong?


From what I’m seeing on my console logging, it goes through the entire lifecycle for every turbolinks visit:

initialize => connect => disconnect

Also, interestingly, when you navigate back and turbolinks loads from cache and then replaces the cache with the freshly fetched page, you’ll see:

initialize => connect => disconnect => initialize => connect => disconnect