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: Next.js App Router / React
nextjsrsccontextproviders
Wrap context providers at the lowest common ancestor, not the root layout
Adding a client-side provider and 'use client' to the root layout opts the entire app out of server rendering. Wrap providers around only the subtree that needs them.
PR: hegnar-bellsheep-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetsx
| 1 | 'use client'; |
| 2 | export default function RootLayout({ children }) { |
| 3 | return ( |
| 4 | <QueryClientProvider client={queryClient}> |
| 5 | <html lang="en"><body>{children}</body></html> |
| 6 | </QueryClientProvider> |
| 7 | ); |
| 8 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | // app/dashboard/layout.tsx — wrap only the subtree that needs the client provider |
| 2 | 'use client'; |
| 3 | export default function DashboardLayout({ children }) { |
| 4 | return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>; |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)