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

Đang mở
#197 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@sarmah-rup đang làm issue này rồi.

Từ ngày 21/7/2026.

  • #205 của @sarmah-rup — đang mở

Đá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
Lĩnh vực
analytics, frontend

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:

  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)
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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của vercel/analytics

Tất cả issue của vercel/analytics

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.