Wrap Vercel Analytics in an error boundary#3805
Closed
posthog[bot] wants to merge 1 commit into
Closed
Conversation
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
|
This PR has been automatically marked as stale because it has had no recent activity. It will be closed if no further activity occurs. |
|
This PR was closed because it has been inactive for 1 day since being marked as stale. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The third-party
@vercel/analyticsscript threw an unhandledTypeError: Cannot read properties of undefined (reading 'toLowerCase')on the editor page. TheAnalytics-*.jschunk's only in-app source issrc/components/Analytics.tsx, a thin wrapper around@vercel/analytics/reactthat renders globally viaHeader.tsx/Header2.tsx.This wraps
<VercelAnalytics />in a small, self-contained silent error boundary (mirroring the existing class-basedErrorBoundarypattern inApp.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
documentevent handlers, so the pagehide/visibility-flush variant (the one with theHTMLDocument.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.Created with PostHog Code from an inbox report.