From 6d434ec467e8ce2b88086a31e376bd3d919c0c26 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 14 Oct 2025 11:02:15 +0200 Subject: [PATCH 1/3] Reuse existing cache invalidation logic that replaced this helper --- app/helpers/cards_helper.rb | 4 ---- app/views/cards/index.html.erb | 2 +- app/views/collections/show/_filtered_cards.html.erb | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/helpers/cards_helper.rb b/app/helpers/cards_helper.rb index 07a6b931f..2ab894086 100644 --- a/app/helpers/cards_helper.rb +++ b/app/helpers/cards_helper.rb @@ -33,8 +33,4 @@ module CardsHelper title << "assigned to #{card.assignees.map(&:name).to_sentence}" if card.assignees.any? title.join(" ") end - - def cacheable_preview_parts_for(card, *options) - [ card, card.collection, card.collection.entropy_configuration, card.collection.publication, card.column&.color, *options ] - end end diff --git a/app/views/cards/index.html.erb b/app/views/cards/index.html.erb index 99121d028..8b496c670 100644 --- a/app/views/cards/index.html.erb +++ b/app/views/cards/index.html.erb @@ -28,7 +28,7 @@ <%= turbo_frame_tag :cards_container do %>
<%= with_automatic_pagination :cards_paginated_container, @page do %> - <%= render partial: "cards/display/preview", collection: @page.records, as: :card, locals: { draggable: true }, cached: ->(card) { cacheable_preview_parts_for(card) } %> + <%= render partial: "cards/display/preview", collection: @page.records, as: :card, locals: { draggable: true }, cached: ->(card) { card.cache_invalidation_parts.for_preview } %> <% end %>
<% end %> diff --git a/app/views/collections/show/_filtered_cards.html.erb b/app/views/collections/show/_filtered_cards.html.erb index 63afd2920..9925e1e0a 100644 --- a/app/views/collections/show/_filtered_cards.html.erb +++ b/app/views/collections/show/_filtered_cards.html.erb @@ -1,5 +1,5 @@
<%= with_automatic_pagination :filtered_cards_paginated_container, page do %> - <%= render partial: "cards/display/preview", collection: page.records, as: :card, locals: { draggable: true }, cached: ->(card) { cacheable_preview_parts_for(card) } %> + <%= render partial: "cards/display/preview", collection: page.records, as: :card, locals: { draggable: true }, cached: ->(card) { card.cache_invalidation_parts.for_preview } %> <% end %>
From 956faaa67d2c05d6f993fdee4d2c4a8a086036ec Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 14 Oct 2025 11:10:49 +0200 Subject: [PATCH 2/3] More fine-grained approach to listen for broadcasted refresh signals Only listen for collections actually involved in the view --- app/helpers/collections_helper.rb | 5 +++++ app/views/cards/_broadcasts.html.erb | 3 +++ app/views/cards/index.html.erb | 2 +- app/views/events/index.html.erb | 2 +- app/views/filters/_broadcasts.html.erb | 7 ------- 5 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 app/helpers/collections_helper.rb create mode 100644 app/views/cards/_broadcasts.html.erb delete mode 100644 app/views/filters/_broadcasts.html.erb diff --git a/app/helpers/collections_helper.rb b/app/helpers/collections_helper.rb new file mode 100644 index 000000000..ac1debab4 --- /dev/null +++ b/app/helpers/collections_helper.rb @@ -0,0 +1,5 @@ +module CollectionsHelper + def referenced_collections_from(records) + Current.user.collections.where id: records.pluck(:collection_id).uniq + end +end diff --git a/app/views/cards/_broadcasts.html.erb b/app/views/cards/_broadcasts.html.erb new file mode 100644 index 000000000..d2404ae68 --- /dev/null +++ b/app/views/cards/_broadcasts.html.erb @@ -0,0 +1,3 @@ +<% referenced_collections_from(records).each do |collection| %> + <%= turbo_stream_from collection %> +<% end %> diff --git a/app/views/cards/index.html.erb b/app/views/cards/index.html.erb index 8b496c670..d700b363a 100644 --- a/app/views/cards/index.html.erb +++ b/app/views/cards/index.html.erb @@ -1,7 +1,7 @@ <% @page_title = @user_filtering.selected_collections_label %> <% turbo_exempts_page_from_cache %> -<%= render "filters/broadcasts", filter: @filter %> +<%= render "cards/broadcasts", records: @page.records %> <% content_for :head do %> <%= tag.meta property: "og:title", content: @page_title %> diff --git a/app/views/events/index.html.erb b/app/views/events/index.html.erb index d6a777d40..4868a5295 100644 --- a/app/views/events/index.html.erb +++ b/app/views/events/index.html.erb @@ -1,7 +1,7 @@ <% @page_title = "Home" %> <% @header_class = "header--events" %> -<%= render "filters/broadcasts", filter: @filter %> +<%= render "cards/broadcasts", records: @day_timeline.events %> <% content_for :header do %> <%= render "filters/menu" %> diff --git a/app/views/filters/_broadcasts.html.erb b/app/views/filters/_broadcasts.html.erb deleted file mode 100644 index a432280e6..000000000 --- a/app/views/filters/_broadcasts.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -<% if filter.collections.any? %> - <% filter.collections.each do |collection| %> - <%= turbo_stream_from collection %> - <% end %> -<% else %> - <%= turbo_stream_from :collections %> -<% end %> From b177f92ec17766e9c4fc9ac389b22699422069c4 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 14 Oct 2025 15:38:35 +0200 Subject: [PATCH 3/3] 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 %>