Skip to main content

Debugging, performance, and security scenarios

Senior interviews increasingly ask what do you do next? rather than asking for API definitions.

Scenario-answer methodโ€‹

1Clarify symptom
2Assess impact
3Reproduce
4Gather evidence
5Form hypotheses
6Change one variable
7Verify + prevent

For an active incident, mitigation or rollback may come before complete diagnosis.

Slow input with thousands of resultsโ€‹

Do not begin with โ€œadd useMemo and useCallback.โ€

Why is typing slow?
Every keypress renders thousands of rowsVirtualization / narrower update scope
Filtering calculation dominatesAlgorithm/server filtering/targeted memoization after measurement
Results are expensive but non-urgentDeferred value / Transition scheduling
Browser layout/paint dominatesFix DOM/CSS/layout cost, not React memoization

Scheduling can improve responsiveness without reducing the total CPU cost.

Broad Context rerendersโ€‹

A provider mixing user, theme, notifications, live prices, permissions, and commands may create broad coupling.

Fix ownership/subscription scope before memoizing symptoms
High-frequency live value
updates multiple times/sec
Many consumers reconsider
broad update surface
Focused contexts / external selectors
narrow subscriptions

Effect repeatedly reconnectsโ€‹

useEffect(() => {
const socket = connect({ roomId, options });
return () => socket.close();
}, [roomId, options]);

If options is recreated every render, the dependency changes by identity. Prefer deriving stable primitive dependencies or creating the object inside the Effect when that matches semantics. Do not delete dependencies to silence the linter.

Fetch raceโ€‹

Request ordering is a data-layer concern
Request A
started first ยท finishes late
Request B
started later ยท should own current screen
Cancellation/version check
AbortController ยท request ID ยท data library

A Transition does not solve stale network responses.

State appears on the wrong rowโ€‹

If editable rows use key={index}, sorting can move component state to a different logical record. Use stable domain identity such as key={record.id}.

Form submits twiceโ€‹

UI duplicate prevention and backend correctness are separate layers
Frontend pending state
reduces repeated user intent
Server idempotency/transaction
protects correctness
Repeated-submit tests
regression contract

Optimistic update conflicts with live server eventโ€‹

How do optimistic and live state converge?
Server returns revision/versionUse version-aware reconciliation
Conflict can be automatically rebasedDefine deterministic merge policy
Conflict is ambiguous/user-significantSurface conflict and restore canonical state
No canonical owner is definedFix architecture before UI behavior

Hydration mismatch only in productionโ€‹

Investigate time/timezone, randomness, browser-only APIs, locale, server/client feature flags, session snapshots, invalid HTML, and third-party DOM mutation.

Hydration mismatch means two initial snapshots disagree
Server HTML
snapshot A
First client render
snapshot B
Mismatch/recovery
find cause before suppressing warning

Suspense fallback replaces whole pageโ€‹

Boundary placement may be too high, navigation may not use Transition semantics, nested reveal structure may be missing, or identity may intentionally reset. Design reveal groups from UX.

Lazy chunk fails after deploymentโ€‹

Chunk failure can be a deployment version-skew problem
Old client runtime
references old hashed chunk
Chunk load failure
route cannot load
Asset retention + recovery
immutable assets ยท reload UX ยท deployment strategy

Memory grows over timeโ€‹

Check missing subscription/timer/listener cleanup, third-party teardown, unbounded caches, retained closures, and detached DOM. Reproduce repeated mount/unmount, inspect heap retention after GC, and verify cleanup invariants.

Infinite Effect loopโ€‹

useEffect(() => {
setItems(transform(items));
}, [items]);

Ask first whether the value should be derived during render. Do not โ€œfixโ€ the loop by hiding a real dependency.

memo did not helpโ€‹

Why did memoization fail to improve UX?
Props/Context still changeSkip cannot occur; inspect identity/update source
Render was cheapOptimization target was irrelevant
Comparison cost offsets render savingsRemove/customize only with evidence
Bottleneck is network/browser/Effect/serverFix the dominant layer
Compiler already handles equivalent ordinary workAvoid duplicate complexity

Fast locally, slow in productionโ€‹

Compare realistic data, network, device CPU, production build, third-party scripts, hydration/server latency, cache state, feature flags, and observability instrumentation.

Security scenario methodโ€‹

Client behavior never replaces server trust checks
1Identify caller-controlled input
2Validate runtime shape
3Authenticate identity
4Authorize resource/action
5Perform mutation safely
6Log only safe context

What a strong scenario answer sounds likeโ€‹

Evidence
measure/reproduce before prescribing
Classification
React vs browser vs network vs backend vs deployment
Prevention
tests ยท telemetry ยท architecture ยท rollout changes

The goal is not to name the most React APIs. It is to isolate the actual failure and choose the smallest change that addresses its real cause.