Part 16 / Topic 6 of 6
A real gotcha the installed docs name by product: synchronous drivers under Cache Components
A first version of this part's Route Handler (app/api/mandi/guestbook/route.ts) called listEntries() directly, with no runtime API read at all. It built successfully — and next build's route table classified it ○ (static):
├ ○ /api/mandi/guestbook
That means the query ran exactly once, at build time, and the response Next.js would serve forever afterward was whatever the database held at that moment — frozen, with no cacheTag attached to ever invalidate it, unlike section 4's cached page. The installed connection.md reference names this exact situation, by product name, in its own worked example titled "Synchronous database drivers":
"Queries from synchronous database drivers like
better-sqlite3complete during prerendering. If you are not already using Request-time APIs, callconnection()before your query to exclude them from prerendering."
The fix, applied to this harness's real route:
// harness/app/api/mandi/guestbook/route.ts
import { connection } from "next/server";
export async function GET() {
await connection();
const entries = listEntries();
return Response.json({ entries });
}
Rebuilding after this one-line addition reclassifies the exact same route:
├ ƒ /api/mandi/guestbook
ƒ (dynamic) — the handler now runs fresh on every request, exactly as a "give me the very latest entries" endpoint should. This is the sharpest, most specific lesson in this part: a synchronous database call reads like ordinary, safe, request-scoped code, but under Cache Components' default prerendering it can be executed once, at build time, and never again — with nothing in the code itself announcing that it happened.
Done here? The practice set for Part 16 — including the solutions — is on the part page.