Skip to content

Wrap Vercel Analytics in an error boundary#3805

Closed
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/analytics-error-boundary
Closed

Wrap Vercel Analytics in an error boundary#3805
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/analytics-error-boundary

Conversation

@posthog

@posthog posthog Bot commented Jul 3, 2026

Copy link
Copy Markdown

Summary

The third-party @vercel/analytics script threw an unhandled TypeError: Cannot read properties of undefined (reading 'toLowerCase') on the editor page. The Analytics-*.js chunk's only in-app source is src/components/Analytics.tsx, a thin wrapper around @vercel/analytics/react that renders globally via Header.tsx/Header2.tsx.

This wraps <VercelAnalytics /> in a small, self-contained silent error boundary (mirroring the existing class-based ErrorBoundary pattern in App.tsx) so a flaky analytics script can never surface as an app-wide unhandled exception. On error it renders nothing and logs a warning.

Why

A tracker-blocking browser (Brave) appears to leave one of the analytics script's internal values undefined, causing it to throw. Analytics is non-critical and should fail silently rather than pollute error tracking or risk the page.

Scope note

  • The boundary reliably suppresses the render/lifecycle-phase variant of the throw. React error boundaries do not catch errors thrown inside native document event handlers, so the pagehide/visibility-flush variant (the one with the HTMLDocument. frame prefix) is not caught by this boundary. Impact of that remaining variant is negligible (analytics-only noise), and containing the render-phase path removes the primary surface.
  • The report also suggested enabling Vercel-analytics source-map uploads so frames resolve if this ever recurs at real volume. That requires deploy-pipeline/CI changes and a source-map upload token (secrets) that can't be provisioned from here, so it's intentionally left as a follow-up rather than half-wired.

Created with PostHog Code from an inbox report.

The third-party @vercel/analytics script can throw at runtime (e.g. when a
tracker-blocking browser leaves one of its internal values undefined), which
surfaced as an unhandled TypeError on the editor page. Since Analytics renders
globally via Header/Header2, contain it in a silent error boundary so a flaky
analytics script can't bubble up as an app error or spam error tracking.

Generated-By: PostHog Code
Task-Id: 8713aeef-6c88-4f08-86ce-d1a258b1f134
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has had no recent activity. It will be closed if no further activity occurs.

@github-actions github-actions Bot added the stale label Jul 6, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

This PR was closed because it has been inactive for 1 day since being marked as stale.

@github-actions github-actions Bot closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants