-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event turbo:before-render is fired twice, unless caching is disabled. #1183
Comments
With Turbo 8.0.0.beta.2 it was possible to check |
@mdesantis thanks a lot for your input. |
I see, so this is the workaround nowadays: addEventListener("turbo:before-render", (event) => {
event.detail.render = (currentElement, newElement) => {
if (document.documentElement.hasAttribute("data-turbo-preview"))
console.log('cache')
else
console.log('no cache')
}
}) I wish Turbo exposed a stable API for this, so we don't have to cross the fingers every library update :D |
@mdesantis - yep, seems to work for now. |
Looks like the isPreview property got reverted here: bb735bf , although the docs still reference it here: https://turbo.hotwired.dev/reference/events#turbo%3Abefore-render The alternative seems pretty unwieldy - you need to override event.detail.render? So really you'd need something like this:
|
You don't need to override // Don't do anything if this is a cached preview being shown.
if (event.target.hasAttribute('data-turbo-preview') === true) {
return;
} |
Ohhh. Yep, that works - thanks! |
While I was trying to implement animated transitions, I've noticed that
turbo:before-render
is fired twice sometimes (quite often, but not at first).Furter investigation revealed that adding
<meta name="turbo-cache-control" content="no-cache">
fixes the issue.
However it disables a cache.
I humbly request to consider having separate events for cached content and to ensure rendering lifecycle events to be fired once.
The text was updated successfully, but these errors were encountered: