Qa debugging performance

From NaveedTechLab/skills-library · View interactive version

Qa debugging performance is an AI agent skill from the GitHub repository NaveedTechLab/skills-library. Debug APIs, fix vulnerabilities, and optimize frontend performance. Use when the user needs to: (1) debug Express.js API routes or middleware errors, (2) identify and fix SQL injection vulnerabilities, (3) optimize React component re-renders, (4) create or improve custom React hooks like useDebounce

How to use this skill

Skill file

QA Debugging & Performance

Diagnose first, fix second. Never patch a symptom without identifying the root cause.

Workflow

1. Identify the problem class (bug | vulnerability | performance | code quality)
2. Locate the root cause (read code, trace call stack, inspect data flow)
3. Confirm the hypothesis (reproduce or reason through the failure path)
4. Apply the minimal fix
5. Verify the fix did not introduce regressions

Constraint: Do not propose a fix until root cause is stated explicitly.


1. Express.js Debugging

See references/express-debugging.md for:

Quick triage:

| Symptom | Likely root cause |

|---|---|

| 404 on valid route | Route defined after catch-all, or wrong HTTP verb |

| 500 with no message | Unhandled promise rejection in async handler |

| Request hangs | Missing next() or res.send() in middleware |

| CORS error | cors() middleware positioned after route definitions |

| SQL returns unexpected data | Unsanitized user input interpolated into query string |


2. SQL Injection Prevention

Root cause check: Is user-supplied data concatenated directly into a SQL string?

// VULNERABLE - always flag this pattern
const q = `SELECT * FROM users WHERE id = ${req.params.id}`;

// SAFE - parameterized query
const q = 'SELECT * FROM users WHERE id = ?';
db.query(q, [req.params.id]);

// SAFE - named parameters (pg, knex, TypeORM)
const q = 'SELECT * FROM users WHERE id = :id';
db.query(q, { id: req.params.id });

When fixing SQL injection:

  1. Identify every place user input touches a query
  2. Replace string interpolation/concatenation with parameterized queries
  3. Ensure ORM query builders are used with bound parameters, not raw string injection

See references/express-debugging.md for ORM-specific patterns.


3. React Performance Optimization

See references/react-performance.md for detailed patterns.

Root cause check for re-renders:

  1. Open React DevTools Profiler and record the interaction
  2. Identify which component re-rendered and why (prop change, context change, parent re-render)
  3. Determine if the re-render is necessary or wasteful

Decision tree:

Re-render detected
  -> Is the component's output different? (necessary re-render) -> no action needed
  -> Same output? (wasteful re-render)
       -> Caused by new object/array/function reference each render?
            -> Wrap value in useMemo / useCallback
       -> Caused by parent re-render with irrelevant state?
            -> Wrap component in React.memo
       -> Caused by expensive computation?
            -> Memoize with useMemo
       -> Caused by high-frequency event (input, scroll, resize)?
            -> Apply useDebounce or useThrottle

4. Custom Hooks

useDebounce — canonical implementation:

import { useState, useEffect } from 'react';

function useDebounce<T>(value: T, delayMs: number): T {
  const [debounced, setDebounced] = useState<T>(value);

  useEffect(() => {
    const timer = setTimeout(() => setDebounced(value), delayMs);
    return () => clearTimeout(timer);
  }, [value, delayMs]);

  return debounced;
}

Usage: const debouncedQuery = useDebounce(searchInput, 300);

When creating other custom hooks:


5. Code Quality

Before suggesting refactors, confirm the change is requested or clearly necessary for the fix.

| Issue | Fix |

|---|---|

| Deep prop drilling | Extract context or lift state |

| Repeated fetch logic | Custom hook (useResource, useFetch) |

| Magic numbers/strings | Named constants |

| Inconsistent error handling | Centralized error boundary + Express error middleware |

| Large component | Extract sub-components; apply single-responsibility |


Resources

When NOT to Use This Skill

Common Mistakes

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.