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
Listen for the turbo:before-cache event if you need to prepare the document before Turbo Drive caches it. You can use this event to reset forms, collapse expanded UI elements, or tear down any third-party widgets so the page is ready to be displayed again.
I believe this means that turbo:before-cache is dispatched before page navigation on the current page. And indeed, using a very simple template the target page is loaded via XHR and the event is dispatched before navigating away from the first page.
<!-- page1.html --><body><aid="second-link" href="/page2.html">To second page</a></body>
If I wrap the body content in a Turbo frame, turbo:before-cache is dispatched as soon as as the new page is rendered, before any navigation is triggered. This breaks assumptions for cleanup, e.g., "tear down any third-party widgets".
For the markup without a frame the debug log will not contain an element, whereas with a frame the debug log will log a reference to the link immediately when its page is loaded.
The text was updated successfully, but these errors were encountered:
https://turbo.hotwired.dev/handbook/building#preparing-the-page-to-be-cached says
I believe this means that
turbo:before-cache
is dispatched before page navigation on the current page. And indeed, using a very simple template the target page is loaded via XHR and the event is dispatched before navigating away from the first page.This markup works as expected.
If I wrap the body content in a Turbo frame,
turbo:before-cache
is dispatched as soon as as the new page is rendered, before any navigation is triggered. This breaks assumptions for cleanup, e.g., "tear down any third-party widgets".This behavior can easily be observed by adding a listener to check for "second-link":
For the markup without a frame the debug log will not contain an element, whereas with a frame the debug log will log a reference to the link immediately when its page is loaded.
The text was updated successfully, but these errors were encountered: