lightsoutAlpha

loader-owns-first-paint

How a screen's data is fetched.

Deterministic checkAgent checkAdvises by default

The rule

Agents read this text as written when they write and review code.

Fetch what a screen shows on its first render in the route loader, with ensureQueryData on the screen's query options, and read it in the screen with useSuspenseQuery on the same object. The screen then has no loading branch for that data.

Never wrap a query in a hook that only calls it: a useIssues whose body is useQuery(issuesQueryOptions()) is a second name for the same thing. Call the query where it is used, and write a hook only when it holds logic of its own.

Data a screen needs later, after an interaction or below the fold, is fetched where it is needed with useQuery.

Then a route is complete when its loader resolves, and a reader finds the fetch in two places that name one object.

Examples

The check flags the incorrect code and passes the correct code; the agent judges what the check cannot see. Each example is a small repo, because this rule looks across files. It opens on the file that matters; the other files are the repo around it.

Incorrect

srcfeaturesissueshooksqueriesscreensservertypesroutes
src/features/issues/screens/IssuesScreen.tsx
import { useIssues } from '../hooks/useIssues.ts';
// Incorrect: nothing prefetched, so the screen paints a loading branch first,
// and it reads the query through a hook that only renames it.
export const IssuesScreen = () => {
const { data: issues, isLoading } = useIssues();
if (isLoading || issues === undefined) {
return <p>Loading…</p>;
}
return (
<ul>
{issues.map((issue) => (
<li key={issue.id}>{issue.title}</li>
))}
</ul>
);
};

Correct

srcfeaturesissuesqueriesscreensservertypesroutes
src/routes/issues.tsx
import { createFileRoute } from '@tanstack/react-router';
import { IssuesScreen } from '../features/issues/screens/IssuesScreen.tsx';
import { issuesQueryOptions } from '../features/issues/queries/issuesQueryOptions.ts';
// Correct: the loader fetches through the object the screen reads, so the
// screen's first render has its data.
export const Route = createFileRoute('/issues')({
loader: ({ context }) => context.queryClient.ensureQueryData(issuesQueryOptions()),
component: IssuesScreen,
});

Configure

  • Block"blocking"Stops a run when a file the run changed breaks the rule.
  • Advise"advisory"Reports it and hands it to the refactor agent. Never stops a run.
    Default
  • Off"off"Not checked. Use it when your own linter already enforces the rule.

Add this to your lightsout.config.json, then change the value.

lightsout.config.json
{
"standards-rule-settings": {
"loader-owns-first-paint": "advisory"
}
}

Packs that select it