This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Route (app) | |
| ┌ ○ /_not-found | |
| └ ƒ /products/[id] | |
| ○ (Static) prerendered as static content | |
| ƒ (Dynamic) server-rendered on demand |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import type { NextConfig } from 'next'; | |
| const nextConfig: NextConfig = { | |
| devIndicators: { | |
| position: 'bottom-right', // 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right' | |
| }, | |
| }; | |
| export default nextConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const nextConfig: NextConfig = { | |
| devIndicators: false, | |
| }; | |
| export default nextConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // app/profile/page.tsx | |
| import { cookies } from 'next/headers'; | |
| export default async function ProfilePage() { | |
| const isDevelopment = process.env.NODE_ENV === 'development'; | |
| // Conditional request-time API usage | |
| const userCookie = isDevelopment ? undefined : await cookies().get('user'); | |
| return <div>Profile: {userCookie?.value ?? 'Guest'}</div>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // app/posts/page.tsx | |
| export default async function PostsPage() { | |
| // Uncached fetch opts out of static rendering | |
| const response = await fetch('https://api.example.com/posts'); | |
| const posts = await response.json(); | |
| return <div>{posts.map(/* ... */)}</div>; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { revalidatePath } from 'next/cache' | |
| export async function updateProduct(productId: string, data: ProductData) { | |
| await db.product.update({ | |
| where: { id: productId }, | |
| data | |
| }) | |
| // Invalidates all cached data for /products and its dynamic segments | |
| revalidatePath('/products') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { cacheTag } from 'next/cache' | |
| export async function getProduct(id: string) { | |
| 'use cache' | |
| cacheTag(`product:${id}`) | |
| return db.product.findUnique({ | |
| where: { id } | |
| }) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { revalidateTag } from 'next/cache' | |
| export async function updateProduct(productId: string, data: ProductData) { | |
| await db.product.update({ | |
| where: { id: productId }, | |
| data | |
| }) | |
| // Invalidates the product everywhere it appears | |
| revalidateTag(`product:${productId}`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { unstable_cache } from 'next/cache' | |
| // Tag-based approach for shared data | |
| export const getCachedProduct = unstable_cache( | |
| async (id: string) => { | |
| return db.product.findUnique({ | |
| where: { id }, | |
| include: { | |
| category: true, | |
| reviews: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use server' | |
| import { revalidateTag, revalidatePath } from 'next/cache' | |
| export async function updateProduct( | |
| id: string, | |
| data: ProductUpdateInput | |
| ) { | |
| const product = await db.product.update({ | |
| where: { id }, |
NewerOlder