Prompt
How do I find the root cause of a frontend error without reproducing it locally?
Latest observation
To find the root cause of a frontend error without reproducing it locally, you want to combine telemetry, context, correlation, and code inspection. A practical workflow:
1) Start with the exact error signal
Collect as much of this as possible:
- Error message
- Stack trace
- Browser / OS / device
- URL / route
- User action leading up to the error
- Timestamp
- User/session ID
- Release version / commit hash
- Request IDs / trace IDs
If you use tools like Sentry, Bugsnag, Datadog, New Relic, LogRocket, etc., they often provide most of this automatically.
2) Map the stack trace to source code
Use source maps if the error is minified/production-only.
- Ensure production source maps are available to your error monitoring tool
- Identify:
- The exact file/function/line
- The first app-owned frame in the stack
- Whether the failure happens in your code or a third-party library
If the stack is obfuscated, source maps are usually the fastest path to root cause.
3) Look at surrounding context in logs and traces
A frontend error is often caused by something upstream:
- API response shape changed
- Empty/null data not handled
- Race condition in async state updates
- Feature flag mismatch
- Auth/session expiration
- Slow network causing timing issues
- Third-party script failure
Check:
- Network requests around the error
- Response status codes
- Payload differences
- Console warnings
- Correlated backend logs using request/trace IDs
4) Group by pattern, not just single occurrences
If it only happens in production, classify incidents by:
- Browser version
- OS/device type
- Route/page
- User segment
- Release version
- Network conditions
- Whether it happens after a specific interaction
This often reveals the trigger:
- “Only on Safari iOS”
- “Only after login”
- “Only on a specific dashboard widget”
- “Only after deploy X”
5) Check recent changes
Look for code or config changes near when the error started:
- Recent frontend deploys
- API contract changes
- Feature flag rollouts
- Dependency upgrades
- CDN/cache changes
- Auth/session cookie changes
A diff between the last good release and the current one often points to the culprit.
6) Inspect telemetry for state and event timing
For bugs you can’t reproduce locally, the cause is often timing-related. Add or inspect:
- Breadcrumbs / event timeline
- State transitions
- User interaction logs
- Network request timing
- Component mount/unmount events
- React error boundaries / lifecycle logs
This helps detect:
- Double renders
- Stale closures
- Race conditions
- State updates after unmount
- Unexpected null state
7) Add targeted instrumentation if data is missing
If current observability isn’t enough, add lightweight logging around suspicious areas:
- Input validation failures
- API normalization code
- Feature-flag branches
- State transitions
- Error boundary fallbacks
- Critical async operations
Log:
- sanitized values
- branch taken
- identifiers, not sensitive data
- timestamps and correlation IDs
8) Reconstruct the failure path from evidence
Once you know:
- the failing line,
- the data that reached it,
- and the surrounding user/session events,
you can often infer the root cause without a local repro.
Example:
- Error:
Cannot read properties of undefined (reading 'name') - Stack points to render of
UserCard - Network log shows
user.profilemissing only for some accounts - API recently changed for deactivated users
Root cause: backend response shape mismatch for a subset of users.
9) Verify with a minimal hypothesis test
Even without reproducing the original bug, you can:
- inspect the relevant code path,
- write a unit/integration test for the suspected condition,
- simulate the bad payload or timing,
- confirm the fix in staging or via canary.
10) Prevent recurrence
Once identified:
- add defensive checks
- validate inputs
- tighten API contracts
- add monitoring for that error pattern
- create tests for the edge case
- use feature flags/canary releases for risky changes
A useful mental model
Ask these 5 questions:
-
Where did it fail?
(stack trace / source map) -
What data reached that point?
(logs / network / state) -
What changed recently?
(deploys / config / flags) -
Who is affected?
(browser / route / cohort) -
What upstream dependency could explain it?
(API / auth / third-party / cache)
If you want, I can also give you:
- a step-by-step incident workflow for frontend production errors, or
- a checklist tailored to React/Vue/Angular.