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/TypeScript, Web Components
web-componentsasyncdomreadability
Await customElements.whenDefined instead of polling with timeouts
To act on a web component once it is ready, await customElements.whenDefined rather than retry loops or setTimeout guesses.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const id = setInterval(() => { |
| 2 | if (editorRef.current?.shadowRoot) { |
| 3 | clearInterval(id); |
| 4 | setupEditor(editorRef.current); |
| 5 | } |
| 6 | }, 100); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | await customElements.whenDefined('rich-text-editor'); |
| 2 | if (editorRef.current?.shadowRoot) setupEditor(editorRef.current); |
Explanation (EN)
Objašnjenje (HR)