diff --git a/app/helpers/turbo/drive_helper.rb b/app/helpers/turbo/drive_helper.rb index 04638af7..7d9eeb07 100644 --- a/app/helpers/turbo/drive_helper.rb +++ b/app/helpers/turbo/drive_helper.rb @@ -82,6 +82,16 @@ def turbo_refresh_method_tag(method = :replace) def turbo_refresh_scroll_tag(scroll = :reset) raise ArgumentError, "Invalid scroll option '#{scroll}'" unless scroll.in?(%i[ reset preserve ]) tag.meta(name: "turbo-refresh-scroll", content: scroll) + end + + # Disable InstantClick (prefetch). + def turbo_disable_prefetch + provide :head, turbo_disable_prefetch_tag + end + + # See +turbo_disable_prefetch+. + def turbo_disable_prefetch_tag + tag.meta(name: "turbo-prefetch", content: "false") end end diff --git a/test/drive/drive_helper_test.rb b/test/drive/drive_helper_test.rb index e071ed31..9cf2d29c 100644 --- a/test/drive/drive_helper_test.rb +++ b/test/drive/drive_helper_test.rb @@ -16,6 +16,11 @@ class Turbo::DriveHelperTest < ActionDispatch::IntegrationTest assert_match(//, @response.body) assert_match(//, @response.body) end + + test "opting out of the default prefetch" do + get trays_path + assert_match(//, @response.body) + end end class Turbo::DriverHelperUnitTest < ActionView::TestCase diff --git a/test/dummy/app/views/trays/index.html.erb b/test/dummy/app/views/trays/index.html.erb index 9658cb7d..20ceb51e 100644 --- a/test/dummy/app/views/trays/index.html.erb +++ b/test/dummy/app/views/trays/index.html.erb @@ -1,5 +1,6 @@ <% turbo_exempts_page_from_cache %> <% turbo_page_requires_reload %> <%= turbo_refreshes_with method: :morph, scroll: :preserve %> +<%= turbo_disable_prefetch %>
Not in the cache!