- <%= link_to talk_path(talk, back_to: back_to, back_to_title: back_to_title), data: {action: "mouseover->preserve-scroll#updateLinkBackToWithScrollPosition"} do %>
+ <%= link_to talk_path(talk, back_to: normalize_back_to(back_to), back_to_title: back_to_title), data: {action: "mouseover->preserve-scroll#updateLinkBackToWithScrollPosition"} do %>
<%= content_tag :h2, class: "text-sm font-sans font-medium" do %>
<%= sanitize(talk.title_with_snippet, tags: ["mark"]) %>
<% end %>
diff --git a/test/helpers/talks_helper_test.rb b/test/helpers/talks_helper_test.rb
new file mode 100644
index 000000000..9ae2aa12a
--- /dev/null
+++ b/test/helpers/talks_helper_test.rb
@@ -0,0 +1,21 @@
+require "test_helper"
+
+class TalksHelperTest < ActionView::TestCase
+ test "normalize_back_to removes infinite_count and format params" do
+ assert_equal "talks_url?s=rails", normalize_back_to("talks_url?s=rails")
+ assert_equal "talks_url?s=rails", normalize_back_to("talks_url?s=rails&infinite_count=1")
+ assert_equal "talks_url?s=rails", normalize_back_to("talks_url?s=rails&format=turbo_stream")
+ assert_equal "talks_url?page=2", normalize_back_to("talks_url?format=turbo_stream&page=2")
+ assert_equal "talks_url?s=rails", normalize_back_to("talks_url?s=rails&infinite_count=1&format=turbo_stream")
+ assert_equal "talks_url?s=rails", normalize_back_to("talks_url?s=rails&infinite_count=111&format=turbo_stream")
+ end
+
+ test "normalize_back_to handles empty params" do
+ assert_equal "talks_url", normalize_back_to("talks_url")
+ end
+
+ test "normalize_back_to preserves other params" do
+ result = normalize_back_to("talks_url?topic=ruby&speaker=john&infinite_count=1")
+ assert_equal ["speaker=john", "topic=ruby"].sort, URI.parse(result).query.split("&").sort
+ end
+end