React component silently drops pageviews when `route` is set without `path`
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- react, typescript
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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)
- Ngôn ngữ chính
- TypeScript
- Star
- 519
- Fork
- 54
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của vercel/analytics
-
Allow preview versions of NextĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
-
Poor Discoverability of npm/pnpm Selector in Vercel Analytics SetupCó thể làm lại được @Emilsone đã nhận 127 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
-
Dependencies conflictCó thể đã có người làm @Mimori256 đã nhận 223 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Tất cả issue của vercel/analytics
Issue tương tự
-
Add: ESP 2 ROĐang mởapproved check:passed streams:add
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ipaas: Configure form shows "Deploy to apply." and "Overrides selected Link" when they don't applyĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
wso2/integration-control-plane#1118 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
File reporting form UI DesignĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
UTDNebula/utd-notebook#311 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày