๐๏ธ 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