Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP1stack specificStack: react
reactasynclifecyclecorrectness
Run awaited work before calling onClose/navigation that unmounts the component
When a handler both awaits async work and triggers an unmount (onClose/navigation), do the awaits and final state updates first and unmount last, to avoid state updates and toasts firing from a detached tree.
PR: vinify-frontend · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetsx
| 1 | const onComplete = async () => { |
| 2 | onClose(); // unmounts this component |
| 3 | await refetch(); // runs against an unmounted tree |
| 4 | setLoading(false); // state update after unmount |
| 5 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const onComplete = async () => { |
| 2 | try { |
| 3 | await refetch(); |
| 4 | } finally { |
| 5 | setLoading(false); |
| 6 | } |
| 7 | onClose(); // unmount last, after awaited work |
| 8 | }; |
Explanation (EN)
Objašnjenje (HR)