Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

React component silently drops pageviews when `route` is set without `path`

Aperta
#197 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@sarmah-rup ci sta già lavorando.

Dal 21/7/2026.

  • #205 di @sarmah-rup — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
react, typescript

Direzione di ricerca

Start with packages/web/src/react/index.tsx, especially the effects that call inject and pageview, and review the package configuration page linked in the issue. Reproduce the React Router usage with route set and path omitted, then establish one supported behavior—documentation, a warning, or a pathname fallback—and verify that pageviews are no longer silently absent.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Report

Description

When using <Analytics route={route} /> from @vercel/analytics/react (v2.0.1) in a plain React + React Router app, no pageviews are ever sent — silently, with no warning or error.

Root Cause

In the React component (source):

// Setting route enables disableAutoTrack
useEffect(() => {
  inject({
    ...props.route !== void 0 && { disableAutoTrack: true },
    ...props,
  });
}, []);

// But pageview() only fires when BOTH route and path are truthy
useEffect(() => {
  if (props.route && props.path) {
    pageview({ route: props.route, path: props.path });
  }
}, [props.route, props.path]);

When route is provided:

  1. disableAutoTrack is set to true → the script won't track pageviews on its own
  2. The component is supposed to call pageview() manually on route changes
  3. But pageview() only fires when both route AND path are truthy
  4. If path is omitted → the condition is false → zero pageviews are sent, ever

There is no console.warn, no error, no fallback. The component renders null and does nothing.

How to Reproduce
import { Analytics } from '@vercel/analytics/react';
import { useLocation, matchPath } from 'react-router-dom';

function AnalyticsWithRoutes() {
  const { pathname } = useLocation();
  const route = ROUTES.find(p => matchPath(p, pathname)) ?? pathname;

  // ❌ This sends ZERO pageviews — no error, no warning
  return <Analytics route={route} />;

  // ✅ This works — but only discoverable by reading source code
  // return <Analytics route={route} path={pathname} />;
}
Expected Behavior

At minimum, one of:

  1. Documentation: The route and path props should be documented on the package configuration page, with a clear note that path is required when route is used.

  2. Runtime warning: When route is provided without path, log a warning:

    [Vercel Web Analytics] `route` prop requires `path` prop for pageviews to be tracked.
    
  3. Graceful fallback: When route is set but path is omitted, fall back to window.location.pathname instead of silently doing nothing.

Context
  • This primarily affects non-Next.js/Remix apps (React Router, TanStack Router, etc.) where developers must wire up route tracking manually.
  • The Next.js and Remix wrappers pass both route and path automatically, which is likely why this gap hasn't been caught — the manual usage path is undocumented.
  • The route and path props appear in TypeScript autocomplete but are absent from the official docs, so developers can discover and use route without ever knowing path is required.
  • We spent significant debugging time on this because the failure mode is completely silent — no network requests, no console output, nothing in DevTools.
Environment
  • @vercel/analytics: 2.0.1
  • Framework: React 19 + React Router 7 + Vite
  • Deployment: Vercel (production)
Lingua principale
TypeScript
Stelle
518
Fork
54
Merge medio
6h 21m
PR unite (30g)
3

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vercel/analytics

Tutte le issue di vercel/analytics

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.