Performance: Why data patterns determine app architecture
This concept affects how quickly data loads and updates in the app, impacting user experience and responsiveness.
import { json } from '@remix-run/node'; import { useLoaderData } from '@remix-run/react'; export async function loader({ params }) { const partialData = await fetchPartialData(params.id); return json(partialData); } function Component() { const data = useLoaderData(); // renders only needed data chunk return <SmallList data={data} />; }
import { json } from '@remix-run/node'; import { useLoaderData } from '@remix-run/react'; export async function loader() { const allData = await fetchAllData(); return json(allData); } function Component() { const data = useLoaderData(); // renders all data even if only a small part is needed return <LargeList data={data} />; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fetch all data at once | High (large DOM tree) | Multiple reflows | High paint cost | [X] Bad |
| Fetch partial data as needed | Low (small DOM tree) | Single reflow | Low paint cost | [OK] Good |
export async function loader() {
return { message: 'Hello Remix' };
}
export default function Greeting() {
const data = useLoaderData();
return <h1>{data.message}</h1>;
}export async function loader() {
const response = await fetch('/api/data');
const data = response.json();
return data;
}Pass the test and this pattern moves unknown