Part 07 · Self Review · 7.4

Sai lầm và checklist React production

React app đáng tin không đo bằng số Hooks hay libraries. State phải có owner, failure phải có UX, interaction phải accessible, security phải nằm ở server boundary và optimization phải có evidence.

Cách dùng: với mỗi mục, đưa được ví dụ từ code thật, test hoặc trace. “Biết khái niệm” chưa đủ nếu không nhận ra failure mode và chứng minh cách sửa.

6 nhóm red flags

1. Effect thay cho data flow

Dùng Effect để tính derived state, xử lý user event hoặc đồng bộ state với state; suppress dependencies để tránh rerun. Hậu quả là extra render, stale closure, loop và flow khó theo dõi.

2. Identity không ổn định

Dùng index/random key, định nghĩa component lồng trong render hoặc mutate object/array tại chỗ. State, DOM, focus và memo cache có thể gắn sai entity hoặc bị reset liên tục.

3. Nhiều source of truth cho server data

Copy response vào Context, client store và local state; query key thiếu input, invalidation mơ hồ. Các view trở nên stale và optimistic update không thể reconcile đáng tin.

4. UI bị coi là security boundary

Route guard hoặc hidden button được xem như authorization; rich HTML đi thẳng vào dangerouslySetInnerHTML; secret được đưa vào client bundle/storage. Attacker không bị giới hạn bởi UI.

5. Memoization không có baseline

Memo mọi component/callback nhưng không profile network, layout, DOM size, Context churn hay bundle. Complexity tăng trong khi user metric không đổi hoặc comparator còn đắt hơn render.

6. Production gaps bị che

Suppress hydration warning, chỉ có snapshot/class-selector tests, bỏ keyboard/failure/race và không có release telemetry. Green CI không chứng minh app hoạt động trên browser và traffic thật.

Checklist năng lực cốt lõi

Definition of Done cho Part 07

Senior review prompts