umami icon indicating copy to clipboard operation
umami copied to clipboard

Using `data-umami-event` causes a full page reload when clicking the same route repeatedly

Open AlaminPu1007 opened this issue 1 year ago • 3 comments

Describe the Bug

When using data-umami-event on a <Link> component in a Next.js application, clicking the same route multiple times causes a full page reload instead of maintaining client-side navigation. This behavior bypasses Next.js' routing mechanism, which should prevent hard reloads when navigating to the same route.

Steps to Reproduce

  1. Add data-umami-event to a <Link> component in a Next.js application
<Link href="/some-route" data-umami-event="button-click">Go to Route</Link>
  1. Navigate to the route by clicking the link.
  2. Click the same link again while on the same route.

Expected Behavior

Next.js should handle the navigation without triggering a hard reload, keeping the navigation smooth and client-side.

Actual Behavior

Clicking the link again causes a full page reload, even though it navigates to the same route, disrupting the expected smooth navigation flow in the application.

Environment

  1. Next.js Version - 14.2.3
  2. Umami Version - 2.11.3

Database

PostgreSQL

Which Umami version are you using? (if relevant)

2.11.3

Which browser are you using? (if relevant)

Chrome latest

AlaminPu1007 avatar Sep 05 '24 09:09 AlaminPu1007

Can you try putting the attribute on a wrapper element?

<div data-umami-event="button-click">
  <Link href="/">Go to route</Link>
</div>

mikecao avatar Sep 12 '24 22:09 mikecao

It's working after following your approach.

AlaminPu1007 avatar Sep 13 '24 14:09 AlaminPu1007

Hi @mikecao, I'm experiencing the same issue, and I must admit that I find the suggested workaround unsatisfactory as it often leads to significant code changes in SPAs. After quickly reviewing the JavaScript part of the code, I understand the underlying reason for the problem. However, I believe it could be resolved more elegantly by utilizing navigator.sendBeacon() instead of preventing the default behavior and then manually updating location.href for non-external links. Do you happen to know who might be responsible for this part of the code and whom I could address this suggestion to? Thanks.

fra-iesus avatar Oct 13 '24 23:10 fra-iesus

Hi @mikecao, i have the same issue on static old school html website with a ajax loading page on every pages. I try your workaround but the effect is links are no more tracked. Do you have any ideas ?

laurent-d avatar Nov 29 '24 08:11 laurent-d

@laurent-d If you use the wrapper around a link, it doesn't track?

mikecao avatar Dec 04 '24 16:12 mikecao

This issue is stale because it has been open for 60 days with no activity.

github-actions[bot] avatar Feb 03 '25 01:02 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Feb 10 '25 02:02 github-actions[bot]