Comments (7)
With Turbo 8.0.0.beta.2 it was possible to check event.detail.isPreview
to handle no-cache and cache renderings, I wonder if now there is another way
from turbo.
@mdesantis thanks a lot for your input.
This property is not there anymore, but data-turbo-preview
attribute is still there.
from turbo.
@mdesantis - yep, seems to work for now.
But in this particular case (animated transitions) supporting caching adds substantial challenges of it's own, and ignoring it is practically impossible
from turbo.
Ohhh. Yep, that works - thanks!
from turbo.
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
from turbo.
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:
document.addEventListener("turbo:before-render", function (e) {
let ogRender = e.detail.render;
e.detail.render = (...args: any[]) => {
if (document.documentElement.hasAttribute("data-turbo-preview")) {
console.log("preview");
} else {
console.log("no preview");
}
return ogRender(...args);
};
});
from turbo.
You don't need to override event.detail.render()
at all; this should work at the start of a turbo:before-render
handler:
// Don't do anything if this is a cached preview being shown.
if (event.target.hasAttribute('data-turbo-preview') === true) {
return;
}
from turbo.
Related Issues (20)
- Turbo Stream refresh does not work when responding to a form submission HOT 1
- InstantClick is incompatible with `data-turbo-stream` and `data-turbo-confirm` HOT 1
- InstantClick always fetches page when hovering same link within the turbo-prefetch-cache-time window. HOT 5
- Morphing between different URLs HOT 1
- Morphed Turbo frame keeps loading the same content when `turbo_frame: :_top` is used to exit it HOT 2
- Support `data-turbo-frame="_parent"` in nested frames
- Morphing is updates an `a` tag, but not it's content, but only on the client who initiated the action HOT 10
- Navigating to page with non-successful response seems to reload javascript HOT 10
- Turbo doesn't send Turbo-Frame header when frame's src is updated HOT 13
- Morphing: impossible to "clear" a form due to ignoreActiveValue: true HOT 9
- Morphing overwrites the user's input on active element HOT 4
- Turbo 8 link advance with frame and temporary not render
- Progress bar does not disappear after fast network response HOT 2
- Turbo 8 data-turbo-action=advance and turbo stream replaces head section HOT 2
- InstaClick does not work when use frame to same page
- Turbo stream refresh takes precedence over user interaction HOT 3
- Turbo morph not preserving stimulus values HOT 1
- Turbo morph displays progress bar HOT 2
- [QUESTION] Plans for turbo handle routes? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from turbo.