When I use wicked_pdf that renders the page with turbo frames
render pdf: "dashboard/index",
formats: [:html],
disposition: :inline,
layout: 'pdf',
javascript_delay: 5000
it doesn’t render frames, but only the Loading...
title that I set as default text:
= turbo_frame_tag "page_status", src: page_status_dashboard_index_path do
= render 'dashboard/cards/loading'
So, how to tune Turbo for reacting on JS marker javascript_delay
?
Are you generating PDF files real-time when users to download from the browser, or do you want to generate PDF files to store on the server?
What server are you running?
Do you have a deadlock or other AJAX issues as described here?
In the rails logs the only one request for loading PDF version
Started GET "/dashboard.pdf" for 127.0.0.1 at 2022-06-09 13:58:22 +0300
and no any consequent Turbo request for fetching extra HTML parts, I’ve set full URL
= turbo_frame_tag "page_status", src: page_status_dashboard_index_url, loading: :eager do
= render 'dashboard/cards/loading'
Also set the application
layout for PDF version and checked that it contains application.js
with turbo frame library:
respond_to do |format|
format.pdf do
render pdf: "dashboard/index",
formats: [:html],
disposition: :inline,
layout: 'application', # 'pdf'
# show_as_html: true,
javascript_delay: 5000,
extra: '--no-stop-slow-scripts'
end
format.html
end
So, after the PDF request you do not see an additional requests in the rails logs (eg the turbo-frame request)? I’m guessing it might be blocking?
If just saving the current page as PDF, one item to consider might be using a JavaScript library to convert the current HTML to PDF. There are several good ones.
The main problem is that the main page fetches other Turbo Frames, and such a library as wiked_pdf can’t process it correctly. So, as I see for solving this issue of such types of HTML/PDF responsive pages, I need to apply conditional rendering like this:
- if pdf_request?
= render partial: 'dashboard/cards/page_status_template', locals: {data: data}
- else
= turbo_frame_tag "page_status", loading: :eager do
= render partial: 'dashboard/cards/page_status_template', locals: {data: data}