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: React
reactportaldomarchitecture
Mount a portal target outside the React root element
A portal whose container lives inside the same React root defeats the purpose and can malfunction. Create a sibling element for portals (and if it is already inside the root, you do not need a portal at all).
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetsx
| 1 | // portalRoot is a child of the React root element |
| 2 | return <div ref={setReactRoot}>{createPortal(modal, reactRootChild)}</div>; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | // web component creates two siblings: react root + portal root |
| 2 | shadowRoot.appendChild(reactRoot); |
| 3 | shadowRoot.appendChild(portalRoot); |
| 4 | createRoot(reactRoot).render(<App portalRoot={portalRoot} />); |
Explanation (EN)
Objašnjenje (HR)