rsnext/errors/app-static-to-dynamic-error.mdx
Delba de Oliveira 98c3076eb4
Docs: Document caching mechanisms (#52514)
This PR document the caching semantics in Next.js, how they interact, and what APIs affect them. We're also taking the opportunity to consolidate terminology, remove duplicate content, and update sections of the docs that relate to caching. 

### Documentation

- [x] Create a new section for caching
- [x] Explain how the different caching mechanisms work
   - [x] Request Memoization (React Cache)
   - [x] Persistent Data Cache 
   - [x] Persistent Full Route Cache 
   - [x] In-memory, client-side Router Cache 
- [x] Document how different APIs affect caching
- [x] Document cache interactions 
- [x] Clean up stale information in the other docs sections
   - [x] Routing Section
      - [x] Move advanced navigation topics from fundamentals to **How Navigation Works** section
      - [x] Rewrite the **How Navigation Works** section
   - [x] Rendering Section
      - [x] Simplify fundamentals page
      - [x] Rewrite the **Static and Dynamic Rendering** pages
      - [ ] ~Create a page to explain how **Client and Server Components** are rendered~. Moved to this PR: https://github.com/vercel/next.js/pull/51579
   - [x] Data fetching section 
      - [x] Consolidate data fetching story for fetching, caching, and revalidating
      - [x] Clarify data fetching story with 3rd party libraries and React `cache`
      - [x] Create **Data Fetching Patterns** page
- [x] Document other related behaviors: 
   - [x] Update information on scroll position for back/forward navigation 
   - [x] Remove the concepts of **soft and hard navigation**
   - [x] Remove the concepts of **static and dynamic data fetching**
   - [x] Use consistent terminology **runtime** 👉🏼  **request time**. Runtime for Edge and Node.js, request time to describe when dynamic stuff happens
   - [x] `generateStaticParams` being able to seed the Full Route Cache
- [x] Polish 💅🏼 

---
### Related PRs:

- Diagrams: https://github.com/vercel/front/pull/24142
- Redirects: https://github.com/vercel/front/pull/24179
2023-07-31 17:03:26 +00:00

23 lines
1.7 KiB
Text

---
title: Resolving "app/ Static to Dynamic Error" in Next.js
description: This document explains the "app/ Static to Dynamic Error" in Next.js and provides potential solutions to resolve it.
---
## Why This Error Occurred
The "`app/` Static to Dynamic Error" happens when one of your routes in the `app/` directory is initially generated statically at build time, but during runtime it attempts to use dynamic server values (such as `cookies()` or `headers()`) either for a fallback path or while a path is being revalidated.
Currently, Next.js does not support switching between static and dynamic types during runtime, so the system throws an error.
## Possible Ways to Fix It
To resolve this issue, you have two main options:
1. Prevent the conditional use of dynamic server values that may cause the static/dynamic mode of the page to differ between build time and runtime. This ensures consistency in the rendering mode of your page.
2. Leverage the `dynamic` export to control the handling of your page. If you want to ensure your page is always handled statically, regardless of the usage of dynamic server values, you can use `export const dynamic = 'force-static'`. Conversely, if you prefer your page to always be dynamic, you can use `export const dynamic = 'force-dynamic'`, and your page won't attempt to be statically generated.
## Useful Links
- [Static and Dynamic Rendering](/docs/app/building-your-application/rendering/static-and-dynamic) - Learn more about the differences between static and dynamic rendering in Next.js.
- [Dynamic Functions](/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-functions) - Understand more about the usage of dynamic server functions in your Next.js application.