Next.jsMedium

What is the unstable_noStore function?

unstable_noStore() (usually imported as noStore) from next/cache opted a component out of static rendering and caching in the previous model. It is effectively superseded: use await connection() from next/server instead, and with Cache Components it is not needed at all.

What it did

Calling noStore() inside a Server Component told Next.js that the code after it must run per request, similar to fetch(url, { cache: 'no-store' }) but for any code, including database queries made with an ORM. It was introduced in Next.js 14 because fetch options could not express "this database call is dynamic".

Why it is outdated

  • Next.js 15 added connection(), which states the intent more clearly: "wait for an incoming request before continuing". The docs recommend it over unstable_noStore.
  • Cache Components (Next.js 16): nothing is cached unless you add "use cache", so there is nothing to opt out of. Remove noStore() calls. If a component must produce fresh output per request without reading request data (for example Math.random() or a synchronous database driver), call await connection() and wrap the component in <Suspense>.

connection() vs io() (16.3)

  • connection() waits for a real request and excludes the following code from prerendering and prefetching.
  • io() marks a synchronous I/O read (new Date(), node:sqlite) so it suspends during prerendering and resolves immediately at request time and in cached scopes.

Interview answer

"It was the escape hatch for marking non-fetch code dynamic. Today I use connection(), and with Cache Components I only cache what I mark with use cache."

Code example

tsx
1// Before (Next.js 14)
2// import { unstable_noStore as noStore } from "next/cache";
3// export default async function Visitors() {
4// noStore();
5// const count = db.prepare("SELECT count(*) AS n FROM visits").get();
6// return <p>{count.n} visits</p>;
7// }
8
9// Now (Next.js 15+, and with Cache Components)
10import { Suspense } from "react";
11import { connection } from "next/server";
12import { db } from "@/lib/sqlite"; // synchronous driver, e.g. better-sqlite3
13
14async function Visitors() {
15 await connection(); // run per request, not at build time
16 const { n } = db.prepare("SELECT count(*) AS n FROM visits").get() as { n: number };
17 return <p>{n} visits</p>;
18}
19
20export default function Page() {
21 return (
22 <Suspense fallback={<p>Counting…</p>}>
23 <Visitors />
24 </Suspense>
25 );
26}

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app