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
reactrsccachingperformance
Only use React cache() for calls repeated within a single render/request
React's cache() dedupes only within one request scope; don't rely on it to dedupe calls across layouts/routes that run in separate scopes.
PR: hegnar-forum-web · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codets
| 1 | // expecting cache() to dedupe across layout.tsx, generateMetadata and page.tsx |
| 2 | export const getTicker = cache(fetchTicker); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | // cache() dedupes within one request scope only; |
| 2 | // to share across routes, fetch once and pass the data down |
| 3 | const ticker = await getTicker(id); |
| 4 | return <Page ticker={ticker} />; |
Explanation (EN)
Objašnjenje (HR)