| name | systematic-debugging |
| description | Four-phase debugging methodology with root cause analysis. Use when investigating bugs, fixing test failures, diagnosing unexpected behavior, or troubleshooting production issues. Emphasizes NO FIXES WITHOUT ROOT CAUSE FIRST. |
Systematic Debugging
Core Principle
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST.
Never apply symptom-focused patches that mask underlying problems. Understand WHY something fails before writing a single line of fix code.
The Four-Phase Framework
Phase 1: Reproduce & Gather Evidence
Before touching any code:
- Read the full error — every word matters, including the stack trace
- Reproduce consistently — define exact steps. If you can't reproduce, you can't verify a fix
- Check recent changes —
git log --oneline -10, what changed before this broke?
- Gather diagnostics — console output, network tab, React DevTools, state snapshots
- Define expected vs actual — write it down explicitly
git log --oneline -20
git bisect start
git bisect bad HEAD
git bisect good <last-known-good-commit>
Phase 2: Trace to Root Cause
Follow the data, not your assumptions:
1. Where does the error appear? (symptom location)
2. What value is wrong at that point?
3. Where does that value come from? (trace upstream)
4. Is the value wrong at the source, or corrupted in transit?
5. What assumption was violated?
Key insight: The bug is rarely where the error appears. Trace upstream until you find where correct data becomes incorrect.
Phase 3: Hypothesize & Test
Scientific method, not shotgun debugging:
- One clear hypothesis — "The error occurs because X causes Y"
- Predict the outcome — "If my hypothesis is correct, then Z should happen when I..."
- Change ONE variable — isolate the test
- Observe result — did it match prediction?
- Iterate or proceed — revise hypothesis if wrong, implement if right
Phase 4: Fix & Verify
- Write a failing test that captures the exact bug
- Implement the fix — address root cause, not symptoms
- Verify the test passes
- Run full test suite — no regressions
- Verify in browser — test the actual user flow
Common Frontend Bug Categories
Rendering Bugs
Symptom: Component shows wrong data or doesn't update
Common causes:
- Stale closure (useCallback/useEffect missing dependency)
- Key prop wrong (React reuses component instance)
- State mutation instead of immutable update
- useEffect dependency array incorrect
Diagnosis:
- React DevTools: check props and state values
- Add console.log at render time: is data correct?
- Check useEffect deps with ESLint exhaustive-deps rule
Async/Race Condition Bugs
Symptom: Sometimes works, sometimes doesn't. Flaky tests.
Common causes:
- Response arrives after component unmounts
- Multiple rapid requests, last response isn't the latest
- State update after navigation
Diagnosis:
- Add timestamps to requests and responses
- Check for AbortController / cleanup functions
- Use React Query (handles cancellation automatically)
Layout/Styling Bugs
Symptom: Element in wrong position, wrong size, or invisible
Common causes:
- CSS specificity conflict
- Missing overflow handling
- Flexbox/Grid misconfiguration
- z-index stacking context
- Missing responsive breakpoint
Diagnosis:
- Browser DevTools: Inspect computed styles
- Check for conflicting Tailwind classes (use tailwind-merge)
- Test at all breakpoints
Hydration Mismatches (SSR)
Symptom: "Text content did not match" or "Hydration failed"
Common causes:
- Server renders different content than client
- Using browser APIs during render (window, localStorage)
- Dates/times formatted differently on server vs client
- Random values or Math.random() in render
Diagnosis:
- Check if component accesses window/document during render
- Wrap browser-only code in useEffect or dynamic import
- Use suppressHydrationWarning only for timestamps
Red Flags — Stop Immediately
- 3+ failed fix attempts → Re-evaluate the hypothesis. You're likely fixing symptoms.
- "This should work" → If you can't explain WHY it works, you don't understand the bug.
- "Quick fix for now" → There is no "for now." Fix the root cause or document the technical debt.
- "Works on my machine" → Environment difference IS the bug. Find it.
Debugging Tools
console.trace('call stack');
console.table(arrayOfObjects);
JSON.stringify(obj, null, 2);
debugger;
Debugging Checklist
Before claiming a bug is fixed:
Integration with Other Skills
- testing-strategy: Write reproducing test before fixing
- react-patterns: Common React-specific bug patterns
- state-management: State-related debugging techniques