Open gearoidoceallaigh opened 4 years ago
Looks as though the double rendering is triggered as a result of page caching.
The "fix" in this case:
<meta name="turbolinks-cache-control" content="no-cache">
to the head
visitRendered
will only be triggered onceThis makes sense as two (potentially) different DOMs are presented to the app. This is a bit confusing but I accept it's a sacrifice to put the "turbo" in "turbolinks" 🙂
It would be great if visitableDidRender
had some way of discerning whether it was receiving a cached version of the page or not. In my case, I am looking for a meta
which determines the user's session status and when caching is enabled, my app will initially receive a DOM which reflects the user being signed out.
I'll try setting this using document.addEventListener("turbolinks:before-cache", function() {
^ Unfortunately this didn't work.
It looks as though
visitRendered
is being triggered twice after an initial load when a page is loaded using theTurbolinks.visit
method.I've been able to reproduce using a clean Rails 6 project and the a clean Turbolinks Demo app.
To reproduce:
visitRendered
in the injected script (user-script
)Turbolinks.visit('/')
visitRendered
is triggered once (correctly)Turbolinks.visit('/')
againvisitRendered
is triggered twiceThis results in two
visitableDidRender
calls in the iOS app which is negatively impacting my application as I do some additional view controller configuration post render.Would appreciate it if someone could try the above and report if they are able to reproduce.