Skip to content

Next.js: TelemetryProvider shutdown on unmount drops render crashes shown as 'This page couldn't load' #932

Open

Description

@unjica

Environment

  • @telemetry-tracker/next 1.3.3
  • @telemetry-tracker/core 1.5.3
  • Next.js 16.4.5 (Turbopack prod: next build && next start), React 19.3.1
  • Setup follows the current /docs/nextjs guide (TelemetryProvider in the root layout)

Symptom

Client render crashes that show Next.js 16.2+'s "This page couldn't load / Reload to try again, or go back." screen are not reported to Telemetry Tracker when using the documented provider setup.

  • A crash during the first page load sends nothing (SDK never finishes init).
  • Even app/global-error.tsx that calls trackError is lost when the provider was the only init path.

Cause

TelemetryProvider's useLayoutEffect cleanup calls shutdown() (core clears config). When a render crash replaces the page tree with the default/custom global error UI, the provider unmounts first. Next then reports the error (reportGlobalError → window.onerror), but getConfigOrNull() is already null, so the error is dropped.

Hydration / first-paint crashes are worse: the provider's layout effect never committed, so init never ran at all.

Next internals note: errors caught by the built-in default global error are treated as uncaught (reportGlobalError → window error event). Errors caught by an app's own error.tsx / global-error.tsx go to onCaughtError → console.error only (never window.onerror), so they still need an explicit trackError in that boundary.

Workaround (verified)

Initialising the SDK in instrumentation-client.ts (Next 15.3+), without relying on TelemetryProvider for init, caught all 5 test crash paths in local verification. Use useTrackPage (or equivalent) for $screen as needed.

Repro and results

Local verification on 2026-11-09 (Europe/Ljubljana) against a mock ingest and headless Chrome.

Crash routes exercised:

Route What throws
/click Client render throws after a button click
/effect Client render throws ~500 ms after mount
/render Client render throws during hydration
/handler Error thrown in onClick (not render)
/promise Async onClick rejects

Results by setup:

Variant Setup /click /effect /render /handler /promise
A Documented /docs/nextjs: TelemetryProvider in root layout NOT reported NOT reported NOT reported (no init) reported reported
B init() at module scope in a client module, no provider reported reported reported – –
C Provider + TelemetryErrorBoundary around children reported (fallback) reported NOT reported – –
D init() in instrumentation-client.ts, no provider reported reported reported reported reported
E D + global-error.tsx with trackError; segment error.tsx without reported NOT reported (segment swallows) reported – –
F A + global-error.tsx with trackError NOT reported – NOT reported – –

Proposed fix

  1. SDK: Do not shut the SDK down on TelemetryProvider unmount (target @telemetry-tracker/next 1.3.4), with a regression test that a render crash after provider unmount still reaches ingest.
  2. Docs: Recommend instrumentation-client.ts init on /docs/nextjs, /error-tracking/nextjs, and /monitoring/nextjs (in addition to or instead of provider-only init).

Blocker note

The planned SEO page /error-tracking/nextjs/this-page-couldnt-load is blocked until this is fixed (or until docs + page exclusively teach the working instrumentation-client.ts path and the provider bug is clearly called out).

Acceptance

  • With the documented Next.js setup, /click, /effect, and /render crashes that show "This page couldn't load" are ingested.
  • Regression test covers provider unmount vs. late window.onerror / reportGlobalError.
  • Docs stop implying provider-only init is enough for render crashes on Next 16.2+.

Activity

  1. added
    bug
    sdk
    on Nov 9, 2026
  2. unjica commented on Nov 13, 2026

    @unjica
    CollaboratorAuthor

    SEO Optimization (2026-11-13): taking only the /error-tracking/nextjs docs part in #960. Re-verified today on Next.js 16.4.6 + @telemetry-tracker/next 1.3.3 (prod build, headless Chrome, mock ingest): provider-only init drops global-error and hydration crashes (even with trackError in global-error.tsx); init() in instrumentation-client.ts + useTrackPage reports all paths and $screen events. SDK fix and /docs/nextjs + /monitoring/nextjs updates remain on this issue.

  3. unjica commented on Nov 16, 2026

    @unjica
    CollaboratorAuthor

    Cross-link only: the SEO page /error-tracking/nextjs/this-page-couldnt-load is now tracked as #969. It stays blocked on this issue. SEO & Content Research is re-scoping the 2026-11-09 brief (overlap with the v1.22.36 /error-tracking/nextjs update), so #969 must not be built from the current brief.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsdk

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions