From b177f92ec17766e9c4fc9ac389b22699422069c4 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 14 Oct 2025 15:38:35 +0200 Subject: [PATCH] Prevent view transition animations on page refreshes View transitions don't play great with page refreshes as they can make those very noticeable --- app/controllers/application_controller.rb | 2 +- app/controllers/concerns/view_transitions.rb | 16 ++++++++++++++++ app/views/layouts/shared/_head.html.erb | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/controllers/concerns/view_transitions.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index aa35df0b3..1de45b5c9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,5 @@ class ApplicationController < ActionController::Base - include Authentication, Authorization, CurrentRequest, CurrentTimezone, SetPlatform, TurboFlash, WriterAffinity + include Authentication, Authorization, CurrentRequest, CurrentTimezone, SetPlatform, TurboFlash, ViewTransitions, WriterAffinity stale_when_importmap_changes allow_browser versions: :modern, block: -> { render "errors/not_acceptable", layout: "error" } diff --git a/app/controllers/concerns/view_transitions.rb b/app/controllers/concerns/view_transitions.rb new file mode 100644 index 000000000..94b9c0a55 --- /dev/null +++ b/app/controllers/concerns/view_transitions.rb @@ -0,0 +1,16 @@ +module ViewTransitions + extend ActiveSupport::Concern + + included do + before_action :disable_view_transitions, if: :page_refresh? + end + + private + def disable_view_transitions + @disable_view_transition = true + end + + def page_refresh? + request.referrer.present? && request.referrer == request.url + end +end diff --git a/app/views/layouts/shared/_head.html.erb b/app/views/layouts/shared/_head.html.erb index 25b06cae9..4c88b0190 100644 --- a/app/views/layouts/shared/_head.html.erb +++ b/app/views/layouts/shared/_head.html.erb @@ -2,7 +2,10 @@ <%= page_title_tag %> - + + <% unless @disable_view_transition %> + + <% end %>