Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Default GETs to SSR data access
Route GET requests through the server-side data layer by default to keep data fetching centralized, cacheable, and consistent.
Bad example
| 1 | "use client"; |
| 2 | import { useEffect, useState } from "react"; |
| 3 |
|
| 4 | export function SearchResults() { |
| 5 | const [items, setItems] = useState<any[]>([]); |
| 6 |
|
| 7 | useEffect(() => { |
| 8 | fetch("/api/search") |
| 9 | .then((res) => res.json()) |
| 10 | .then(setItems); |
| 11 | }, []); |
| 12 |
|
| 13 | return <ResultsList items={items} />; |
| 14 | } |
Explanation (EN)
Client-side GETs spread data fetching logic across the app and make caching and error handling inconsistent. This often increases waterfall requests and hurts performance.
Objašnjenje (HR)
GET zahtjevi na klijentu raspršuju logiku dohvaćanja, otežavaju cache i ujednačeno rukovanje greškama. To često povećava waterfall i šteti performansama.
Good example
| 1 | // Server-side GET via api.server.ts |
| 2 | import { getSearchResults } from "@/utils/api.server"; |
| 3 |
|
| 4 | export default async function SearchResultsPage() { |
| 5 | const items = await getSearchResults(); |
| 6 | return <ResultsList items={items} />; |
| 7 | } |
Explanation (EN)
Server-side GETs keep data access centralized and consistent, enable caching, and reduce client waterfalls. The component stays focused on rendering.
Objašnjenje (HR)
Server-side GET drži data access centraliziranim i konzistentnim, omogućuje cache i smanjuje waterfall. Komponenta ostaje fokusirana na render.
Notes (EN)
Most GETs should go through src/utils/api.server.ts.
Bilješke (HR)
Većina GET-ova treba ići kroz src/utils/api.server.ts.
Exceptions / Tradeoffs (EN)
Use client fetching only for purely client-interactive or real-time flows where SSR is not practical.
Iznimke / Tradeoffi (HR)
Koristi client fetch samo za potpuno client-interaktivne ili real-time tokove gdje SSR nije praktičan.