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
reacthydrationrefsbug
Don't swap a hydration ref onto an empty element
Pointing a component's ref at a fresh empty <div> means hydration has nothing to attach to and silently does nothing; keep the ref on the real placeholder markup.
PR: hegnar-web · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codejavascript
| 1 | ref.current = document.createElement('div'); // empty, nothing hydrates |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | // keep ref pointed at the server-rendered placeholder element |
Explanation (EN)
Objašnjenje (HR)