React component silently drops pageviews when `route` is set without `path`
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:
disableAutoTrackis set totrue→ the script won't track pageviews on its own- The component is supposed to call
pageview()manually on route changes - But
pageview()only fires when bothrouteANDpathare truthy - If
pathis omitted → the condition isfalse→ 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:
-
Documentation: The
routeandpathprops should be documented on the package configuration page, with a clear note thatpathis required whenrouteis used. -
Runtime warning: When
routeis provided withoutpath, log a warning:[Vercel Web Analytics] `route` prop requires `path` prop for pageviews to be tracked. -
Graceful fallback: When
routeis set butpathis omitted, fall back towindow.location.pathnameinstead 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
routeandpathautomatically, which is likely why this gap hasn't been caught — the manual usage path is undocumented. - The
routeandpathprops appear in TypeScript autocomplete but are absent from the official docs, so developers can discover and useroutewithout ever knowingpathis 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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di vercel/analytics
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
Poor Discoverability of npm/pnpm Selector in Vercel Analytics SetupForse di nuovo libera @Emilsone l’ha presa 97 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
-
Dependencies conflictForse già presa @Mimori256 l’ha presa 193 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Tutte le issue di vercel/analytics
Issue simili
-
Tenant
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
MTES-MCT/Dossier-Facile-Frontend#2061 ·
I maintainer di solito rispondono entro 1 giorno
-
area:frontend
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
interledger/publisher-tools#905 ·
I maintainer di solito rispondono entro 1 giorno
-
Add: Cbeebies PL SDApertaapproved check:passed streams:add
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
iptv-org/iptv#54525 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
DB-plane provider_chat_options.* is accepted by config set but never merged into the loaded configAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
area:web
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
praetorianer777/GoTome#178 ·
I maintainer di solito rispondono entro 1 giorno