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 ruleP1universalStack: javascript
lifecyclememory-leakthird-partycleanup
Scope third-party instances locally and dispose on unmount
Instantiate third-party widget/library objects as instance fields (not module globals) and destroy them on unmount, so behavior isn't leaked across all uses.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | configureSortableGlobally(); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | componentDidMount() { |
| 2 | this.sortable = new Sortable(this.listRef.current, { /* ... */ }); |
| 3 | } |
| 4 | componentWillUnmount() { |
| 5 | this.sortable.destroy(); |
| 6 | } |
Explanation (EN)
Objašnjenje (HR)