Hide page content until turbo:load event

To avoid cases when Turbo links are processed as normal HTTP requests
This commit is contained in:
cryptogopher 2024-01-04 23:06:47 +01:00
parent 92350ac3f2
commit c96b646087
2 changed files with 12 additions and 1 deletions

View File

@ -1,3 +1,8 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
Turbo.session.drive = false
function showPage(event) {
document.documentElement.style.visibility="visible";
}
document.addEventListener('turbo:load', showPage);

View File

@ -1,5 +1,11 @@
<!DOCTYPE html>
<html>
<!-- Hide content until Turbo is loaded completely. There exist (mostly
unnoticeable) delay after a page is shown and before Turbo has started to
service frame/stream requests. If user (or more probably: system test) clicks
link during this period, request will be sent outside of Turbo, resulting in
e.g. stream request sent as HTML instead of TURBO_STREAM.
Content is shown on 'turbo:load' event. -->
<html style="visibility: hidden;">
<head>
<title>fixin.me</title>
<meta name="viewport" content="width=device-width,initial-scale=1">