From 63e029804eaaec607a139674b3248a4cca184df2 Mon Sep 17 00:00:00 2001 From: Lee Robinson Date: Wed, 4 Sep 2024 19:56:45 -0500 Subject: [PATCH] docs: fix data fetching with ORM (#69702) Follow up from https://github.com/vercel/next.js/pull/69695. --- .../02-data-fetching/01-fetching.mdx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/02-app/01-building-your-application/02-data-fetching/01-fetching.mdx b/docs/02-app/01-building-your-application/02-data-fetching/01-fetching.mdx index 8311b5155844f..99a1dfca41614 100644 --- a/docs/02-app/01-building-your-application/02-data-fetching/01-fetching.mdx +++ b/docs/02-app/01-building-your-application/02-data-fetching/01-fetching.mdx @@ -87,7 +87,7 @@ export default async function Page() { } ``` -If you are not using any [dynamic functions](/docs/app/building-your-application/rendering/server-components#dynamic-rendering) anywhere else in your application, this page will be prerendered during `next build` to a static page. The data can then be updated using [Incremental Static Regeneration](/docs/app/building-your-application/data-fetching/incremental-static-regeneration). +If you are not using any [dynamic functions](/docs/app/building-your-application/rendering/server-components#dynamic-rendering) anywhere else in this route, it will be prerendered during `next build` to a static page. The data can then be updated using [Incremental Static Regeneration](/docs/app/building-your-application/data-fetching/incremental-static-regeneration). If you do _not_ want to cache the response from `fetch`, you can do the following: @@ -97,7 +97,7 @@ let data = await fetch('https://api.vercel.app/blog', { cache: 'no-store' }) ### Fetching data on the server with an ORM or database -This page will be SSG by default. The page will be prerendered during `next build`. It can be revalidated using [Incremental Static Regeneration](/docs/app/building-your-application/data-fetching/incremental-static-regeneration). +This component will fetch and display a list of blog posts. The response from the database will be cached. ```tsx filename="app/page.tsx" switcher import { db, posts } from '@/lib/db' @@ -129,7 +129,15 @@ export default async function Page() { } ``` -The database call will run again every time you revalidate the page using [Incremental Static Regeneration](/docs/app/building-your-application/data-fetching/incremental-static-regeneration). +If you are not using any [dynamic functions](/docs/app/building-your-application/rendering/server-components#dynamic-rendering) anywhere else in this route, it will be prerendered during `next build` to a static page. The data can then be updated using [Incremental Static Regeneration](/docs/app/building-your-application/data-fetching/incremental-static-regeneration). + +If you do _not_ want to cache the response from the database, you can add the following to your file: + +```js +export const dynamic = 'force-dynamic' +``` + +However, you will commonly use functions like `cookies()`, `headers()`, or reading the incoming `searchParams` from the page props, which will automatically make the page render dynamically. In this case, you do _not_ need to explicitly use `force-dynamic`. ### Fetching data on the client