Commit Graph

23 Commits

Author SHA1 Message Date
Joseph b2c48352d6 docs: correct the upper stale bound for App Shell exclusion in cacheLife (#97653)
Clarifying that:

> - **`stale` from 30 seconds up to 5 minutes**: included in prerenders,
but excluded from the route's [App Shell](/docs/app/glossary#app-shell).

Means, 30 <= stale and stale < 5minutes
2026-08-21 14:46:44 +02:00
Joseph e551922083 docs: app router reference accuracy (#97477)
- Adding
docs/01-app/03-api-reference/05-config/01-next-config-js/cacheMaxMemorySize.mdx
- Various use cache snippet fixes
- Break nuance for fetch default
- Point to correct turbopack cache flags
2026-08-18 11:52:26 +02:00
Joseph 6f7ed2ecb9 docs: document the App Shell stale time threshold for cached content (#96312)
Closes:
https://linear.app/vercel/issue/DOC-6480/app-shells-exclude-stale-5-minutes-caches
2026-07-31 10:15:09 -04:00
Joseph b3118fca9f docs: recommend explicit cacheLife and clarify overriding built-in cache profiles (#95311)
- Lead use cache Revalidation with explicit cacheLife; split into
Time-based and On-demand.
- Recommend cacheLife in every use cache scope; drop "optional."
- Reorder cacheLife reference: Overriding before Custom; reword both.
- Document that overrides reach the generated cacheLife type signature.
- Add the override option to the config reference and migration guide.
2026-07-01 15:09:01 +02:00
Aurora Scharff 743615ba32 docs: clarify cacheLife() cannot be called at module scope (#92326)
### What?

Update the "Good to know" callout in the `cacheLife` docs to explicitly
state that `cacheLife()` must be called inside a function body, not at
module scope, and that doing so throws an error.

### Why?

Calling `cacheLife('days')` at module scope in a file with `'use cache'`
at the top throws: `` `cacheLife()` can only be called inside a "use
cache" function ``. This is technically correct (module scope is not
inside a function), but the previous docs only said `cacheLife` "should
be placed within the function" without mentioning it errors. Both
developers and AI agents hit this when they place `cacheLife()` next to
the file-level `'use cache'` directive at the top of the module.

### How?

Replaced the soft "should be placed within the function" language with
explicit "must be called inside a function body, not at module scope"
and noted that it throws an error otherwise.

## PR checklist (Improving Documentation)

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening
the PR
- [x] Follow the docs contribution guide:
https://nextjs.org/docs/community/contribution-guide

Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2026-04-08 16:06:07 +02:00
Delba de Oliveira c2b4c0815c Unify caching story across the docs (#90149)
This PRs unifies the caching story across the docs, making Cache
Components the happy path, while still providing guidance to users in
the old model. However, instead of explaining the old model and its
caching layers, we've created a new guide focusing on what APIs to use
and when.

This follow-up PR aligns terminology across the docs:
https://github.com/vercel/next.js/pull/90589

## IA updates

Getting Started section: 

- Improves Getting Started progression:
- **Before:** CC → Fetching Data → Updating Data → Caching and
Revalidating (old and new model mixed)
- **After:** Fetching Data (Dynamic) → Mutating Data (Dynamic) → Caching
with CC (Prerendering) → Revalidating with CC.
- New: `caching.mdx` (CC-first)
   - Structure: 
      - Enabling Cache Components
      - Data vs UI-level caching
      - Working with request time APIs
      - Passing request values to cached functions
      - Working with non-deterministic operations
      - Working with synchronous operations
      - How rendering works (PPR and static shell story)
- New: `revalidating.mdx` (CC-first)
   - Explains how to use `cacheLife` and `cacheTag`

Guides Section: 

- New: `caching-and-revalidating.mdx` (Previous Model)
- For users who are not using CC, includes `fetch` options and route
segment config
- Moves route segment config options that don't apply to CC from API
reference to this guide (for easy archiving in the future).
- New: `migrating-to-cache-components.mdx` (WIP)
- Del: `caching.mdx` 😌 

## Terminology

We should remove caching layers from the docs. Users only needed to be
exposed to them when they were configured independently, but the new CC
APIs work across layers.

To make it easier to review this PR, I'm consolidating terminology and
fixing broken links in a new PR:
https://github.com/vercel/next.js/pull/90589

---------

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2026-03-03 13:14:24 +00:00
Jinsoo Lee 5c589abdf4 docs: document cacheLife expire omission behavior and fix default preset value (#89913)
## Summary
- Add note that omitting `expire` in `cacheLife` results in cache never
expiring
- Fix `default` preset table: `expire` was documented as "1 year" but
actual code uses `INFINITE_CACHE` (never)
- Add mention of expire omission behavior in custom profiles section

## Why
The `expire` property is optional (`expire?: number`), but the
documentation didn't explain
what happens when it's omitted. The source code shows it defaults to
`INFINITE_CACHE` (0xfffffffe),
meaning the cache never expires. Additionally, the preset profile table
incorrectly listed
the `default` profile's expire as "1 year" when the actual value is
`INFINITE_CACHE`.

### Source code references
- `packages/next/src/lib/constants.ts:45` — `INFINITE_CACHE =
0xfffffffe`
- `packages/next/src/server/config-shared.ts:1580` — `default.expire:
INFINITE_CACHE`
- `packages/next/src/server/use-cache/cache-life.ts:156` — only sets
`explicitExpire` when `expire !== undefined`
- `packages/next/src/server/use-cache/use-cache-wrapper.ts:477-479` —
falls back to `defaultCacheLife.expire` (INFINITE_CACHE)

---------

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2026-02-13 13:52:38 +01:00
Hendrik Liebau 469e513c5f Require explicit cacheLife on outer "use cache" when nesting short-lived caches (#89481)
This PR adds error handling for nested `"use cache"` where the inner
cache has a very short lifetime (zero `revalidate` or `expire` under 5
minutes) but the outer cache doesn't have an explicit `cacheLife()`
call.

Short-lived caches become "dynamic holes" that are excluded from
prerenders. When such a cache is nested inside another `"use cache"`
without an explicit `cacheLife`, the outer cache's lifetime would
silently become short too via
[propagation](https://nextjs.org/docs/app/api-reference/functions/cacheLife#nested-caching-behavior),
which can lead to unexpected behavior. To prevent this accidental
misconfiguration, Next.js now throws an error during prerendering,
requiring developers to explicitly declare their intent by adding
`cacheLife()` to the outer cache.

The implementation tracks whether `revalidate` and `expire` were
explicitly set via `hasExplicitRevalidate` and `hasExplicitExpire` flags
on the collected cache result. Errors are wrapped with
`wrapAsInvalidDynamicUsageError` to capture proper stack traces and
prevent userland try/catch from suppressing the build error.

Documentation has been updated with a new "Prerendering behavior"
section in the `cacheLife` API reference explaining how short-lived
caches become dynamic holes, and a "Nested short-lived caches"
subsection with examples showing how to fix the error.

closes NAR-761
2026-02-05 15:39:08 +00:00
Joseph 22cc5be063 docs: cacheLife feedback (#86128)
- Adjust nested behavior
- Include conditional calls to cacheLife

---------

Co-authored-by: Ismael <ismael@vercel.com>
2025-11-21 21:27:44 +01:00
Bernd Strehl 9dc96c89e5 Remove redundant example code for cacheLife docs (#86043)
Remove redundant example code for overriding cache profiles.

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR. ✅ (no changes)
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide ✅

### What?

Remove a redundant example in the `cacheLife` docs.

### Why?

Because the redundant example is confusing.

### How?

Closes NEXT-
Fixes #

-->
2025-11-13 20:39:08 +00:00
Joseph c22f05b94e docs: cache life rework (#85224)
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
2025-10-31 14:21:37 +01:00
Joseph 5ce476a811 docs: stabilize apis in docs (#85219) 2025-10-22 14:12:17 +02:00
Zack Tanner 1b949df737 [cache components] stabilize cacheLife profiles (#85050)
As part of stabilizing `cacheComponents`, `cacheLife` profiles should
also be accessible from a top-level config. This updates the
configuration, adds the warning, and updates relevant docs.
2025-10-18 18:50:00 -07:00
Zack Tanner 85c3d20a91 [cache components]: move flag out of experimental (#85035)
This moves `experimental.cacheComponents` to a top level config. As part
of this, I disabled some tests in `build-output-prerender` that assert
on `cacheComponents` appearing in the experimental list. In a separate
PR, I'm going to show that Cache Components is enabled next to the
bundler info.

This also updates some docs pages to remove "experimental" language.
2025-10-18 14:13:44 -07:00
Janka Uryga bae8bf4606 [Cache Components] fix docs for cacheLife("seconds") (#85004)
Looks like this was missed in #82332, when we bumped the staletime to
30s.
2025-10-17 23:09:58 +02:00
Joseph 45fcbdea7a docs: x-nextjs-stale-time header (#84901)
Let's add a note about this header.

-
https://github.com/vercel/next.js/blob/3ae7ace09338bcde92ececb6b03a03760f302aed/packages/next/src/server/app-render/app-render.tsx#L2076-L2079

-
https://github.com/vercel/next.js/blob/3ae7ace09338bcde92ececb6b03a03760f302aed/packages/next/src/client/components/segment-cache-impl/cache.ts#L262-L268

-
https://github.com/vercel/next.js/blob/3ae7ace09338bcde92ececb6b03a03760f302aed/packages/next/src/client/components/segment-cache-impl/cache.ts#L318-L326

---------

Co-authored-by: Ismael <ismael@vercel.com>
2025-10-17 00:45:09 +02:00
Josh Story 8cab15c0c9 [Cache Components] Remove unstable prefix from unstable_cacheLife (#84877)
`cacheLife` is now stable and does not require an unstable prefix
2025-10-15 08:14:04 -07:00
Wyatt Johnson 8abbb3dc2e refactor: rename experimental.dynamicIO to experimental.cacheComponents (#81562)
## What?

Rename `experimental.dynamicIO` to `experimental.cacheComponents` across
the Next.js codebase.

## Why?

We're going to be merging the functionality of the `ppr`, `dynamicIO`
and `useCache` experimental flags into the singular `cacheComponents`
flag to reduce complexity of the codebase and simplify adoption for
users wanting to experiment with experimental features.

## How?

- Renamed the configuration option from `experimental.dynamicIO` to
`experimental.cacheComponents`
- Added deprecation handling with automatic migration for the old option
name
- Updated all documentation, tests, and internal references
- Updated Rust code in SWC transforms and Turbopack
- Maintained backward compatibility with deprecation warnings

NAR-158
2025-07-17 19:30:28 -06:00
Delba de Oliveira 2e2ee08b60 Docs IA 2.0: Delete routing section, add BFF guide, polish getting started (#80365)
Closes:
https://linear.app/vercel/issue/DOC-4686/clean-up-routing-section
Redirects: https://github.com/vercel/front/pull/47151

---------

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-06-16 13:42:20 +01:00
Delba de Oliveira 67921c23ef Docs: Create Examples section (#73858)
Closes: https://linear.app/vercel/issue/DOC-4047/create-examples-section

Redirects: https://github.com/vercel/front/pull/39878
2024-12-13 12:08:44 +00:00
LEE HAJIN 32c9b7bdd1 Documentation Fix: Typo and URL Correction (#73397)
### What?
This pull request addresses two minor documentation issues in the
Next.js project:
1. A typo fix in the API reference for the `cacheLife` function.
2. A correction of an incorrect URL for the `experimental.typedRoutes`
in the Turbopack documentation.

### Why?
Accurate documentation is crucial for developers to effectively use the
features of Next.js. By ensuring the clarity and correctness of these
documents, we improve the user experience and aid in preventing
potential confusion when navigating and implementing the API features.

### How?
- **Typo Correction**: In
`docs/01-app/03-api-reference/04-functions/cacheLife.mdx`, the
`cacheLife` function documentation had a capitalization error in the
phrase “The `cacheLife` function.” This has been corrected to use the
correct lowercase styling: “the `cacheLife` function”.
  
- **URL Correction**: In
`docs/01-app/03-api-reference/08-turbopack.mdx`, the link pointing to
`experimental.typedRoutes` was incorrect. The link has been updated to
the correct URL:
`https://nextjs.org/docs/app/api-reference/next-config-js/typedRoutes`.

These changes ensure the accuracy and readability of the documentation,
aligning it with Next.js standards.

---

---------

Co-authored-by: Sam Ko <sam@vercel.com>
2024-12-02 02:34:48 +00:00
Delba de Oliveira 0b35ddd825 Docs: Move next.config.js API pages under a config folder, fix headings in TS and ESLint config pages (#72465)
This PR:

- Moves `next.config.js` options under a "config" folder which includes
references for other configuration such as the ESLint plugin. I figure
it would be tidier than having "Next.config.js Options" and "Config" in
the API reference.
- Fixes the issue with the "config" folder not showing up in canary:
https://linear.app/vercel/issue/DOC-3749/bug-figure-out-why-new-config-folder-isnt-showing-up-in-the-canary
- Fixes the indentation issues and missing example header (caused by an
invisible character).

Redirects: https://github.com/vercel/front/pull/38704
2024-11-08 14:48:55 +00:00
Delba de Oliveira fa8d558154 Docs: Split Getting Started between App and Pages, improve Installation page (#72178)
Prepare **Getting Started** Section for upcoming changes, and work on
the first page: `Installation`.

Closes: 
-
https://linear.app/vercel/issue/DOC-3703/update-how-getting-started-is-handled-in-next-site
-
https://linear.app/vercel/issue/DOC-3694/page-how-to-set-up-a-new-nextjs-project-installation
- https://linear.app/vercel/issue/DOC-3707/create-subsection-for-plugins
- https://linear.app/vercel/issue/DOC-3709/eslint-plugin-api-reference
- https://linear.app/vercel/issue/DOC-3710/typescript-reference-page

### Key Changes: 

- Duplicate Getting Started Section between App and Pages Router docs 
- Since getting started will vary between the routers, each docs needs
to have their own Getting Started section
- Reorganize folder numbers
   
**Installation Page**: 
- Split app and pages router specific information
- Rename "Installation" to "How to set up a Next.js application" for SEO
- Add setup instructions for **TypeScript**
- Add setup instructions for **ESLint**
- Add setup instructions for **Absolute Imports and Module Path
Aliases**

**Side effects from moving content around**:
- Create a subsection in API Reference called **Configuration**. 
   - Add ESLint Plugin page, and update it to follow template
   - Add TypeScript page, and update it to follow template
- Remove the **Absolute Imports and Module Path Aliases** page, it's
small enough to live under the set up instructions.

---------

Co-authored-by: Rich Haines <hello@richardhaines.dev>
2024-11-06 12:32:05 +00:00