10

Using rails (7.1.3.2) and turbo-rails (2.0.4). For some reason, when ever I hover over any link in my app, a GET request is happening to the linked page. I check my inspector and there is a mouseenter event coming from turbo.es2017-esm.js:3135.

When I disable it, the GET requests don't happen.

Here is an example of a link I have

<%= link_to "Edit", edit_post_path(@post), class: "hover:text-black flex-none", data: { turbo_frame: :resource_frame } %>

Anyone know why this is happening and how I can stop it?

1 Answer 1

23

It's a new instaclick behavior in Turbo v8:
https://github.com/hotwired/turbo/pull/1101

You can disable it by adding a meta tag to your page:

<meta name="turbo-prefetch" content="false">

or data attribute to/around your links:

<a href="/" data-turbo-prefetch="false">Home</a>

<div data-turbo-prefetch="false">
  <a href="/">Home</a>
  ...
</div>

https://turbo.hotwired.dev/handbook/drive#prefetching-links-on-hover

1
  • From the link above, "You can also disable the behaviour programatically by intercepting the turbo:before-prefetch event and calling event.preventDefault()". ` document.addEventListener("turbo:before-prefetch", (event) => { if (isSavingData() || hasSlowInternet()) { event.preventDefault() } }) function isSavingData() { return navigator.connection?.saveData } function hasSlowInternet() { return navigator.connection?.effectiveType === "slow-2g" || navigator.connection?.effectiveType === "2g" } `
    – B-Rad
    Commented 2 days ago

Not the answer you're looking for? Browse other questions tagged or ask your own question.