๐๏ธ The Universal Machine Coding Checklist
Before Writing Any Code ๐ง
- โClarify requirements โ functional & non-functional
- โAsk: what scale? (10 users vs 10M users)
- โDefine data structures / state shape first
- โIdentify: real-time needed? offline support?
- โDefine component boundaries on paper
- โIdentify edge cases (empty state, error state, loading state)
- โAsk about browser support / mobile requirements
- โConfirm: should you handle auth? pagination?
- โAgree on what NOT to implement (time-box scope)
- โTalk through your plan before coding
Every Component Needs These States ๐
- โ Loading state โ spinner / skeleton (not just the happy path!)
- โ Error state โ show error message + retry action
- โ Empty state โ no data yet (first time user experience)
- โ Partial/edge data โ 0 items, 1 item, 10,000 items
// Pattern to always use const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null);
Accessibility Checklist โฟ
- โKeyboard navigable (Tab, Enter, Escape, Arrow keys)
- โProper ARIA roles / labels on interactive elements
- โFocus management on modal open/close
- โAlt text on all images
- โColor contrast โ do not rely on color alone
- โAnnounce dynamic changes with aria-live
Performance Checklist โก
- โDebounce / throttle search inputs and scroll handlers
- โVirtualize long lists (react-virtual, react-window)
- โLazy-load images (loading='lazy' or IntersectionObserver)
- โMemoize expensive computations (useMemo)
- โStable callbacks to avoid child re-renders (useCallback + memo)
- โCode-split heavy components (React.lazy + Suspense)
๐ฏ Common Machine Coding Questions โ Key Points
Search Autocomplete
- โDebounce input (300ms) โ do not fire on every keystroke
- โCancel previous request on new input (AbortController)
- โCache results in a Map to avoid repeat fetches
- โKeyboard: ArrowUp/Down, Enter selects, Escape closes
- โARIA: role='combobox', aria-expanded, role='listbox', role='option'
- โHighlight matched text in suggestions
Infinite Scroll / Pagination
- โIntersectionObserver on sentinel div at bottom โ no scroll listener
- โShow loading skeleton while fetching next page
- โDeduplicate items (server may return duplicates with cursor-based)
- โHandle network errors โ retry button, do not lose loaded data
- โVirtualize if list grows very large (1000+ items)
- โChoose: cursor-based (stable) vs offset-based (simpler but inconsistent)
const observer = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting && !loading) fetchNextPage();
}, { threshold: 0.1 });
observer.observe(sentinelRef.current); File Upload
- โShow progress bar (XHR onprogress or fetch ReadableStream)
- โValidate: file type, size limit BEFORE upload
- โAllow drag-and-drop (ondragover + ondrop)
- โMultiple files โ queue them, upload concurrently or sequentially
- โRetry failed uploads, show per-file status
- โChunked upload for large files (resumable)
// Progress with XHR
const xhr = new XMLHttpRequest();
xhr.upload.onprogress = (e) => {
const pct = Math.round((e.loaded / e.total) * 100);
setProgress(pct);
}; Real-time Chat
- โWebSocket for bidirectional messaging
- โOptimistic UI โ show message immediately, confirm async
- โReconnect logic with exponential backoff
- โScroll to bottom on new message (unless user has scrolled up)
- โShow typing indicators (debounced emit)
- โPresence (online/offline) via WebSocket heartbeat
Drag and Drop
- โHTML5 Drag API: draggable, ondragstart, ondragover, ondrop
- โpreventDefault on ondragover to allow drop
- โVisual feedback โ highlight valid drop zones
- โdataTransfer.setData / getData to pass item id
- โTouch support needs separate pointer event handling
- โKeyboard alternative for accessibility
el.ondragstart = (e) => e.dataTransfer.setData("id", item.id);
drop.ondragover = (e) => e.preventDefault(); // required!
drop.ondrop = (e) => {
const id = e.dataTransfer.getData("id");
reorder(id);
}; Modal / Toast / Tooltip
- โModal: Portal to body, focus trap, lock body scroll, close on Escape
- โRestore focus to trigger element on close
- โToast: auto-dismiss with timer, pause on hover, accessible aria-live='polite'
- โTooltip: show on hover + focus (keyboard users too!), useRef for positioning
- โOverlay click closes modal โ but not click inside modal
Form with Validation
- โValidate on blur (not on every keystroke) to avoid annoying UX
- โRe-validate on submit
- โDisabled submit until valid โ or allow submit and show all errors
- โShow inline errors, not just a toast
- โHandle async validation (email availability check โ debounce!)
- โConsider React Hook Form or Zod for complex forms
Virtualized List (10k+ items)
- โOnly render visible items + overscan buffer
- โCalculate item positions from known / estimated heights
- โFor variable height: measure with ResizeObserver, store heights
- โScroll restoration when navigating away and back
// Core idea const ITEM_HEIGHT = 40; const visibleStart = Math.floor(scrollTop / ITEM_HEIGHT); const visibleEnd = Math.ceil((scrollTop + containerH) / ITEM_HEIGHT); // Render only items[visibleStart..visibleEnd] // Spacer div for total height