Turn uses the Pausable Rendering feature to control rendering timing.
turbo:before-render
and turbo:render
are dispatched twice when a preview is rendered. You can detect the initial preview render by checking the data-turbo-preview
attribute on the HTML element. So if you set a hasPreview
variable with the result of this check, you’ll be able to determine when a render is a preview, or a post-preview one.
Checkout turn/controller.js at b588a8497de8bdc1e99842252870590b82371ae9 · domchristie/turn · GitHub for an example of this