next 16.2.11 → 16.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.build-commit +1 -1
- package/dist/bin/next +2 -2
- package/dist/build/index.js +3 -3
- package/dist/build/load-jsconfig.js +40 -20
- package/dist/build/load-jsconfig.js.map +1 -1
- package/dist/build/next-config-ts/transpile-config.js +3 -114
- package/dist/build/next-config-ts/transpile-config.js.map +1 -1
- package/dist/build/swc/index.js +1 -1
- package/dist/build/turbopack-analyze/index.js +1 -1
- package/dist/build/turbopack-build/impl.js +1 -1
- package/dist/build/type-check.js +20 -13
- package/dist/build/type-check.js.map +1 -1
- package/dist/build/webpack-config.js +3 -3
- package/dist/bundle-analyzer/404.html +2 -2
- package/dist/bundle-analyzer/__next.__PAGE__.txt +1 -1
- package/dist/bundle-analyzer/__next._full.txt +1 -1
- package/dist/bundle-analyzer/__next._head.txt +1 -1
- package/dist/bundle-analyzer/__next._index.txt +1 -1
- package/dist/bundle-analyzer/__next._tree.txt +1 -1
- package/dist/bundle-analyzer/_not-found/__next._full.txt +1 -1
- package/dist/bundle-analyzer/_not-found/__next._head.txt +1 -1
- package/dist/bundle-analyzer/_not-found/__next._index.txt +1 -1
- package/dist/bundle-analyzer/_not-found/__next._not-found.__PAGE__.txt +1 -1
- package/dist/bundle-analyzer/_not-found/__next._not-found.txt +1 -1
- package/dist/bundle-analyzer/_not-found/__next._tree.txt +1 -1
- package/dist/bundle-analyzer/_not-found.html +2 -2
- package/dist/bundle-analyzer/_not-found.txt +1 -1
- package/dist/bundle-analyzer/index.html +2 -2
- package/dist/bundle-analyzer/index.txt +1 -1
- package/dist/cli/next-test.js +2 -1
- package/dist/cli/next-test.js.map +1 -1
- package/dist/cli/next-typegen.js +2 -1
- package/dist/cli/next-typegen.js.map +1 -1
- package/dist/client/app-bootstrap.js +1 -1
- package/dist/client/index.js +1 -1
- package/dist/compiled/next-server/pages-api-turbo.runtime.dev.js +1 -1
- package/dist/compiled/next-server/pages-api-turbo.runtime.dev.js.map +1 -1
- package/dist/compiled/next-server/pages-turbo.runtime.dev.js +1 -1
- package/dist/compiled/next-server/pages-turbo.runtime.dev.js.map +1 -1
- package/dist/compiled/next-server/server.runtime.prod.js +1 -1
- package/dist/compiled/next-server/server.runtime.prod.js.map +1 -1
- package/dist/docs/01-app/01-getting-started/01-installation.md +33 -0
- package/dist/docs/01-app/01-getting-started/02-project-structure.md +1 -1
- package/dist/docs/01-app/01-getting-started/06-fetching-data.md +1 -1
- package/dist/docs/01-app/01-getting-started/09-revalidating.md +1 -1
- package/dist/docs/01-app/02-guides/authentication.md +18 -10
- package/dist/docs/01-app/02-guides/backend-for-frontend.md +1 -1
- package/dist/docs/01-app/02-guides/debugging.md +2 -2
- package/dist/docs/01-app/02-guides/migrating/app-router-migration.md +18 -14
- package/dist/docs/01-app/02-guides/single-page-applications.md +1 -1
- package/dist/docs/01-app/02-guides/static-exports.md +2 -0
- package/dist/docs/01-app/03-api-reference/02-components/form.md +1 -1
- package/dist/docs/01-app/03-api-reference/03-file-conventions/error.md +2 -0
- package/dist/docs/01-app/03-api-reference/03-file-conventions/not-found.md +3 -1
- package/dist/docs/01-app/03-api-reference/04-functions/redirect.md +1 -0
- package/dist/docs/01-app/03-api-reference/04-functions/refresh.md +4 -1
- package/dist/docs/01-app/03-api-reference/04-functions/revalidatePath.md +3 -0
- package/dist/docs/01-app/03-api-reference/04-functions/revalidateTag.md +3 -0
- package/dist/docs/01-app/03-api-reference/04-functions/unstable_cache.md +5 -5
- package/dist/docs/01-app/03-api-reference/04-functions/use-search-params.md +1 -1
- package/dist/docs/01-app/03-api-reference/05-config/01-next-config-js/headers.md +11 -11
- package/dist/docs/01-app/03-api-reference/05-config/01-next-config-js/redirects.md +10 -10
- package/dist/docs/01-app/03-api-reference/05-config/01-next-config-js/rewrites.md +16 -16
- package/dist/docs/01-app/03-api-reference/05-config/01-next-config-js/serverActions.md +4 -1
- package/dist/docs/01-app/03-api-reference/05-config/01-next-config-js/useTypeScriptCli.md +62 -0
- package/dist/docs/01-app/03-api-reference/05-config/02-typescript.md +55 -1
- package/dist/docs/01-app/03-api-reference/07-adapters/05-routing-with-next-routing.md +0 -3
- package/dist/docs/02-pages/02-guides/forms.md +6 -6
- package/dist/docs/02-pages/03-building-your-application/01-routing/08-custom-error.md +2 -0
- package/dist/docs/02-pages/04-api-reference/04-config/01-next-config-js/useTypeScriptCli.md +8 -0
- package/dist/esm/build/index.js +3 -3
- package/dist/esm/build/load-jsconfig.js +40 -20
- package/dist/esm/build/load-jsconfig.js.map +1 -1
- package/dist/esm/build/next-config-ts/transpile-config.js +3 -73
- package/dist/esm/build/next-config-ts/transpile-config.js.map +1 -1
- package/dist/esm/build/swc/index.js +1 -1
- package/dist/esm/build/turbopack-analyze/index.js +1 -1
- package/dist/esm/build/turbopack-build/impl.js +1 -1
- package/dist/esm/build/type-check.js +20 -13
- package/dist/esm/build/type-check.js.map +1 -1
- package/dist/esm/build/webpack-config.js +3 -3
- package/dist/esm/client/app-bootstrap.js +1 -1
- package/dist/esm/client/index.js +1 -1
- package/dist/esm/lib/has-necessary-dependencies.js.map +1 -1
- package/dist/esm/lib/install-dependencies.js +1 -1
- package/dist/esm/lib/install-dependencies.js.map +1 -1
- package/dist/esm/lib/patch-incorrect-lockfile.js +3 -3
- package/dist/esm/lib/typescript/loadTsConfig.js +129 -0
- package/dist/esm/lib/typescript/loadTsConfig.js.map +1 -0
- package/dist/esm/lib/typescript/missingDependencyError.js +1 -1
- package/dist/esm/lib/typescript/missingDependencyError.js.map +1 -1
- package/dist/esm/lib/typescript/runTypeCheck.js.map +1 -1
- package/dist/esm/lib/typescript/runTypeCheckCli.js +38 -0
- package/dist/esm/lib/typescript/runTypeCheckCli.js.map +1 -0
- package/dist/esm/lib/typescript/runTypeScriptCli.js +217 -0
- package/dist/esm/lib/typescript/runTypeScriptCli.js.map +1 -0
- package/dist/esm/lib/verify-typescript-setup.js +87 -52
- package/dist/esm/lib/verify-typescript-setup.js.map +1 -1
- package/dist/esm/server/config-schema.js +1 -0
- package/dist/esm/server/config-schema.js.map +1 -1
- package/dist/esm/server/config-shared.js +1 -0
- package/dist/esm/server/config-shared.js.map +1 -1
- package/dist/esm/server/config.js +1 -1
- package/dist/esm/server/dev/hot-reloader-turbopack.js +2 -2
- package/dist/esm/server/dev/hot-reloader-webpack.js +1 -1
- package/dist/esm/server/lib/app-info-log.js +1 -1
- package/dist/esm/server/lib/router-utils/setup-dev-bundler.js +2 -1
- package/dist/esm/server/lib/router-utils/setup-dev-bundler.js.map +1 -1
- package/dist/esm/server/lib/start-server.js +1 -1
- package/dist/esm/shared/lib/errors/canary-only-config-error.js +1 -1
- package/dist/lib/has-necessary-dependencies.d.ts +2 -0
- package/dist/lib/has-necessary-dependencies.js.map +1 -1
- package/dist/lib/install-dependencies.js +1 -1
- package/dist/lib/install-dependencies.js.map +1 -1
- package/dist/lib/patch-incorrect-lockfile.js +3 -3
- package/dist/lib/typescript/loadTsConfig.d.ts +13 -0
- package/dist/lib/typescript/loadTsConfig.js +181 -0
- package/dist/lib/typescript/loadTsConfig.js.map +1 -0
- package/dist/lib/typescript/missingDependencyError.js +1 -1
- package/dist/lib/typescript/missingDependencyError.js.map +1 -1
- package/dist/lib/typescript/runTypeCheck.d.ts +2 -2
- package/dist/lib/typescript/runTypeCheck.js.map +1 -1
- package/dist/lib/typescript/runTypeCheckCli.d.ts +12 -0
- package/dist/lib/typescript/runTypeCheckCli.js +53 -0
- package/dist/lib/typescript/runTypeCheckCli.js.map +1 -0
- package/dist/lib/typescript/runTypeScriptCli.d.ts +38 -0
- package/dist/lib/typescript/runTypeScriptCli.js +256 -0
- package/dist/lib/typescript/runTypeScriptCli.js.map +1 -0
- package/dist/lib/verify-typescript-setup.d.ts +16 -1
- package/dist/lib/verify-typescript-setup.js +97 -56
- package/dist/lib/verify-typescript-setup.js.map +1 -1
- package/dist/server/config-schema.d.ts +1 -0
- package/dist/server/config-schema.js +1 -0
- package/dist/server/config-schema.js.map +1 -1
- package/dist/server/config-shared.d.ts +6 -0
- package/dist/server/config-shared.js +1 -0
- package/dist/server/config-shared.js.map +1 -1
- package/dist/server/config.js +1 -1
- package/dist/server/dev/hot-reloader-turbopack.js +2 -2
- package/dist/server/dev/hot-reloader-webpack.js +1 -1
- package/dist/server/lib/app-info-log.js +1 -1
- package/dist/server/lib/router-utils/setup-dev-bundler.js +2 -1
- package/dist/server/lib/router-utils/setup-dev-bundler.js.map +1 -1
- package/dist/server/lib/start-server.js +1 -1
- package/dist/shared/lib/errors/canary-only-config-error.js +1 -1
- package/dist/telemetry/anonymous-meta.js +1 -1
- package/dist/telemetry/events/build.d.ts +1 -0
- package/dist/telemetry/events/build.js.map +1 -1
- package/dist/telemetry/events/session-stopped.js +2 -2
- package/dist/telemetry/events/swc-load-failure.js +1 -1
- package/dist/telemetry/events/version.js +2 -2
- package/package.json +10 -10
- /package/dist/bundle-analyzer/_next/static/{yuLxudwpXbv0jKSL-s0ZM → xR78HbVQBty3GRl-Ydf7i}/_buildManifest.js +0 -0
- /package/dist/bundle-analyzer/_next/static/{yuLxudwpXbv0jKSL-s0ZM → xR78HbVQBty3GRl-Ydf7i}/_clientMiddlewareManifest.json +0 -0
- /package/dist/bundle-analyzer/_next/static/{yuLxudwpXbv0jKSL-s0ZM → xR78HbVQBty3GRl-Ydf7i}/_ssgManifest.js +0 -0
|
@@ -348,6 +348,39 @@ You can enable the plugin in VS Code by:
|
|
|
348
348
|
|
|
349
349
|
See the [TypeScript reference](/docs/app/api-reference/config/typescript) page for more information.
|
|
350
350
|
|
|
351
|
+
<AppOnly>
|
|
352
|
+
|
|
353
|
+
## Set up your editor
|
|
354
|
+
|
|
355
|
+
The App Router names files by convention, like `page.tsx`, `layout.tsx`, and `route.ts`, so your editor quickly fills with same-named tabs. Label each tab with its enclosing folders, like `blog/[id]`, so you can tell them apart.
|
|
356
|
+
|
|
357
|
+
In VS Code 1.88+ or Cursor, add [custom editor labels](https://code.visualstudio.com/updates/v1_88#_customize-editor-labels) to `.vscode/settings.json`. Labeling two folders deep keeps dynamic routes like `blog/[id]/page.tsx` from all collapsing to the same `[id]` label:
|
|
358
|
+
|
|
359
|
+
```json filename=".vscode/settings.json"
|
|
360
|
+
{
|
|
361
|
+
"workbench.editor.customLabels.patterns": {
|
|
362
|
+
"**/app/**/page.tsx": "${dirname(1)}/${dirname} - page.tsx",
|
|
363
|
+
"**/app/**/layout.tsx": "${dirname(1)}/${dirname} - layout.tsx",
|
|
364
|
+
"**/app/**/loading.tsx": "${dirname(1)}/${dirname} - loading.tsx",
|
|
365
|
+
"**/app/**/error.tsx": "${dirname(1)}/${dirname} - error.tsx",
|
|
366
|
+
"**/app/**/not-found.tsx": "${dirname(1)}/${dirname} - not-found.tsx",
|
|
367
|
+
"**/app/**/template.tsx": "${dirname(1)}/${dirname} - template.tsx",
|
|
368
|
+
"**/app/**/default.tsx": "${dirname(1)}/${dirname} - default.tsx",
|
|
369
|
+
"**/app/**/route.ts": "${dirname(1)}/${dirname} - route.ts"
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
Or copy this prompt to have your coding agent set it up:
|
|
375
|
+
|
|
376
|
+
```prompt
|
|
377
|
+
Set up custom editor labels so my Next.js App Router files are easy to tell apart. Read https://nextjs.org/docs/app/getting-started/installation#set-up-your-editor and add the workbench.editor.customLabels.patterns config shown there to my .vscode/settings.json, creating the file if it doesn't exist. Adjust the labels to taste. If I use a different editor, apply the equivalent setting or tell me it's automatic, and leave my other settings untouched.
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
> **Good to know:** JetBrains IDEs (WebStorm, IntelliJ) show the folder for same-named files automatically, so no setup is needed.
|
|
381
|
+
|
|
382
|
+
</AppOnly>
|
|
383
|
+
|
|
351
384
|
## Set up linting
|
|
352
385
|
|
|
353
386
|
Next.js supports linting with either ESLint or Biome. Choose a linter and run it directly via `package.json` scripts.
|
|
@@ -368,7 +368,7 @@ To organize routes without affecting the URL, create a group to keep related rou
|
|
|
368
368
|
height="930"
|
|
369
369
|
/>
|
|
370
370
|
|
|
371
|
-
Even though routes inside `(marketing)` and `(shop)` share the same URL hierarchy, you can create a different layout for each group by adding a `layout.js` file inside their folders.
|
|
371
|
+
Even though routes inside `(marketing)` and `(shop)` share the same URL hierarchy, you can create a different layout for each group by adding a `layout.js` file inside their folders. These layouts nest within the existing app layout.
|
|
372
372
|
|
|
373
373
|
<Image
|
|
374
374
|
alt="Route Groups with Multiple Layouts"
|
|
@@ -374,7 +374,7 @@ export default function BlogPage() {
|
|
|
374
374
|
|
|
375
375
|
Sequential data fetching happens when one request depends on data from another.
|
|
376
376
|
|
|
377
|
-
For example, `<Playlists>` can only fetch data after
|
|
377
|
+
For example, `<Playlists>` can only fetch data after `getArtist()` resolves because it needs the `artistID`:
|
|
378
378
|
|
|
379
379
|
```tsx filename="app/artist/[username]/page.tsx" switcher
|
|
380
380
|
export default async function Page({
|
|
@@ -118,7 +118,7 @@ See the [`revalidateTag` API reference](/docs/app/api-reference/functions/revali
|
|
|
118
118
|
|
|
119
119
|
## `updateTag`
|
|
120
120
|
|
|
121
|
-
`updateTag` immediately expires cached data for read-your-own-writes scenarios — the user sees their change right away instead of stale content. Unlike `revalidateTag`, it can only be used in [Server Actions](/docs/app/
|
|
121
|
+
`updateTag` immediately expires cached data for read-your-own-writes scenarios — the user sees their change right away instead of stale content. Unlike `revalidateTag`, it can only be used in [Server Actions](/docs/app/guides/server-actions).
|
|
122
122
|
|
|
123
123
|
```tsx filename="app/lib/actions.ts" highlight={1,12} switcher
|
|
124
124
|
import { updateTag } from 'next/cache'
|
|
@@ -878,7 +878,7 @@ To create and manage database sessions, you'll need to follow these steps:
|
|
|
878
878
|
For example:
|
|
879
879
|
|
|
880
880
|
```ts filename="app/lib/session.ts" switcher
|
|
881
|
-
import cookies from 'next/headers'
|
|
881
|
+
import { cookies } from 'next/headers'
|
|
882
882
|
import { db } from '@/app/lib/db'
|
|
883
883
|
import { encrypt } from '@/app/lib/session'
|
|
884
884
|
|
|
@@ -913,7 +913,7 @@ export async function createSession(id: number) {
|
|
|
913
913
|
```
|
|
914
914
|
|
|
915
915
|
```js filename="app/lib/session.js" switcher
|
|
916
|
-
import cookies from 'next/headers'
|
|
916
|
+
import { cookies } from 'next/headers'
|
|
917
917
|
import { db } from '@/app/lib/db'
|
|
918
918
|
import { encrypt } from '@/app/lib/session'
|
|
919
919
|
|
|
@@ -1351,9 +1351,17 @@ Due to [Partial Rendering](/docs/app/getting-started/linking-and-navigating#clie
|
|
|
1351
1351
|
|
|
1352
1352
|
Instead, you should do the checks close to your data source or the component that'll be conditionally rendered.
|
|
1353
1353
|
|
|
1354
|
-
For example, consider a shared layout that fetches the user data and displays the user image in a nav. Instead of doing the auth check in the layout, you should fetch the user data (`getUser()`) in the layout and do the auth check in your DAL.
|
|
1354
|
+
For example, consider a shared layout that fetches the user data and displays the user image in a nav. Instead of doing the auth check in the layout, you should fetch the user data (`getUser()`) in the layout and do the auth check in your [DAL](#creating-a-data-access-layer-dal).
|
|
1355
|
+
|
|
1356
|
+
This guarantees that wherever `getUser()` is called within your application, the auth check is performed, and prevents developers from forgetting to check that the user is authorized to access the data.
|
|
1357
|
+
|
|
1358
|
+
#### Auth and streaming
|
|
1355
1359
|
|
|
1356
|
-
|
|
1360
|
+
Session and user data often appear in shell UI (header, nav) that repeats across routes. A top-level `await` on `cookies()`, `headers()`, or the DAL in a layout delays the first streamed chunk for that segment and holds `{children}` behind that work.
|
|
1361
|
+
|
|
1362
|
+
If only part of the shell needs session data (for example, a user menu), move the `await` into a nested Server Component and wrap it in `<Suspense>` so the rest of the page streams first. See [Push dynamic access down](/docs/app/guides/streaming#push-dynamic-access-down) for the pattern.
|
|
1363
|
+
|
|
1364
|
+
Client Components can't import the DAL. Run `verifySession()`, `getUser()`, or similar in a parent Server Component, then pass data to client children as props or through a [Context Provider](#context-providers). To share data across multiple Server Components without re-fetching, see [Sharing data with context and `React.cache`](/docs/app/getting-started/fetching-data#sharing-data-with-context-and-reactcache).
|
|
1357
1365
|
|
|
1358
1366
|
#### Auth checks in page components
|
|
1359
1367
|
|
|
@@ -1448,7 +1456,7 @@ This pattern allows you to show or hide UI elements based on user permissions wh
|
|
|
1448
1456
|
|
|
1449
1457
|
### Server Actions
|
|
1450
1458
|
|
|
1451
|
-
Treat [Server Actions](/docs/app/
|
|
1459
|
+
Treat [Server Actions](/docs/app/guides/server-actions) with the same security considerations as public-facing API endpoints, and verify if the user is allowed to perform a mutation.
|
|
1452
1460
|
|
|
1453
1461
|
In the example below, we check the user's role before allowing the action to proceed:
|
|
1454
1462
|
|
|
@@ -1546,7 +1554,7 @@ Using context providers for auth works due to [interleaving](/docs/app/getting-s
|
|
|
1546
1554
|
|
|
1547
1555
|
This works, but any child Server Components will be rendered on the server first, and will not have access to the context provider’s session data:
|
|
1548
1556
|
|
|
1549
|
-
```tsx filename="app/layout.
|
|
1557
|
+
```tsx filename="app/layout.tsx" switcher
|
|
1550
1558
|
import { ContextProvider } from 'auth-lib'
|
|
1551
1559
|
|
|
1552
1560
|
export default function RootLayout({ children }) {
|
|
@@ -1560,8 +1568,8 @@ export default function RootLayout({ children }) {
|
|
|
1560
1568
|
}
|
|
1561
1569
|
```
|
|
1562
1570
|
|
|
1563
|
-
```tsx filename="app/ui/profile.
|
|
1564
|
-
'use client'
|
|
1571
|
+
```tsx filename="app/ui/profile.tsx" switcher
|
|
1572
|
+
'use client'
|
|
1565
1573
|
|
|
1566
1574
|
import { useSession } from "auth-lib";
|
|
1567
1575
|
|
|
@@ -1575,8 +1583,8 @@ export default function Profile() {
|
|
|
1575
1583
|
}
|
|
1576
1584
|
```
|
|
1577
1585
|
|
|
1578
|
-
```jsx filename="app/ui/profile.
|
|
1579
|
-
'use client'
|
|
1586
|
+
```jsx filename="app/ui/profile.jsx" switcher
|
|
1587
|
+
'use client'
|
|
1580
1588
|
|
|
1581
1589
|
import { useSession } from "auth-lib";
|
|
1582
1590
|
|
|
@@ -897,7 +897,7 @@ For these, use community libraries like [`swr`](https://swr.vercel.app/) or [`re
|
|
|
897
897
|
|
|
898
898
|
### Server Actions
|
|
899
899
|
|
|
900
|
-
Server Actions let you run server-side code from the client. Their primary purpose is to mutate data from your frontend client.
|
|
900
|
+
[Server Actions](/docs/app/guides/server-actions) let you run server-side code from the client. Their primary purpose is to mutate data from your frontend client.
|
|
901
901
|
|
|
902
902
|
Server Actions are queued. Using them for data fetching introduces sequential execution.
|
|
903
903
|
|
|
@@ -8,7 +8,7 @@ description: Learn how to debug your Next.js application with VS Code, Chrome De
|
|
|
8
8
|
|
|
9
9
|
This documentation explains how you can debug your Next.js frontend and backend code with full source maps support using the [VS Code debugger](https://code.visualstudio.com/docs/editor/debugging), [Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools), or [Firefox DevTools](https://firefox-source-docs.mozilla.org/devtools-user/).
|
|
10
10
|
|
|
11
|
-
Any debugger that can attach to Node.js can also be used to debug a Next.js application. You can find more details in the Node.js [Debugging Guide](https://nodejs.org/
|
|
11
|
+
Any debugger that can attach to Node.js can also be used to debug a Next.js application. You can find more details in the Node.js [Debugging Guide](https://nodejs.org/learn/getting-started/debugging/).
|
|
12
12
|
|
|
13
13
|
## Debugging with VS Code
|
|
14
14
|
|
|
@@ -137,7 +137,7 @@ Launching the Next.js server with the `--inspect` flag will look something like
|
|
|
137
137
|
|
|
138
138
|
```bash filename="Terminal"
|
|
139
139
|
Debugger listening on ws://127.0.0.1:9229/0cf90313-350d-4466-a748-cd60f4e47c95
|
|
140
|
-
For help, see: https://nodejs.org/
|
|
140
|
+
For help, see: https://nodejs.org/learn/getting-started/debugging
|
|
141
141
|
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
|
|
142
142
|
```
|
|
143
143
|
|
|
@@ -525,18 +525,20 @@ The `pages` directory uses `getServerSideProps` and `getStaticProps` to fetch da
|
|
|
525
525
|
|
|
526
526
|
```tsx filename="app/page.tsx" switcher
|
|
527
527
|
export default async function Page() {
|
|
528
|
-
//
|
|
528
|
+
// Opt into the Next.js Data Cache for this request.
|
|
529
|
+
// The cached response can be reused across requests and revalidated on demand.
|
|
529
530
|
// Similar to `getStaticProps`.
|
|
530
|
-
|
|
531
|
-
const staticData = await fetch(`https://...`, { cache: 'force-cache' })
|
|
531
|
+
const cachedData = await fetch('https://...', { cache: 'force-cache' })
|
|
532
532
|
|
|
533
|
-
//
|
|
533
|
+
// Opt out of caching for this request.
|
|
534
|
+
// Next.js fetches this from the data source on every request.
|
|
535
|
+
// This is the default fetch behavior.
|
|
534
536
|
// Similar to `getServerSideProps`.
|
|
535
|
-
const
|
|
537
|
+
const uncachedData = await fetch('https://...', { cache: 'no-store' })
|
|
536
538
|
|
|
537
|
-
//
|
|
539
|
+
// Cache this request, but revalidate it at most every 10 seconds.
|
|
538
540
|
// Similar to `getStaticProps` with the `revalidate` option.
|
|
539
|
-
const revalidatedData = await fetch(
|
|
541
|
+
const revalidatedData = await fetch('https://...', {
|
|
540
542
|
next: { revalidate: 10 },
|
|
541
543
|
})
|
|
542
544
|
|
|
@@ -546,18 +548,20 @@ export default async function Page() {
|
|
|
546
548
|
|
|
547
549
|
```jsx filename="app/page.js" switcher
|
|
548
550
|
export default async function Page() {
|
|
549
|
-
//
|
|
551
|
+
// Opt into the Next.js Data Cache for this request.
|
|
552
|
+
// The cached response can be reused across requests and revalidated on demand.
|
|
550
553
|
// Similar to `getStaticProps`.
|
|
551
|
-
|
|
552
|
-
const staticData = await fetch(`https://...`, { cache: 'force-cache' })
|
|
554
|
+
const cachedData = await fetch('https://...', { cache: 'force-cache' })
|
|
553
555
|
|
|
554
|
-
//
|
|
556
|
+
// Opt out of caching for this request.
|
|
557
|
+
// Next.js fetches this from the data source on every request.
|
|
558
|
+
// This is the default fetch behavior.
|
|
555
559
|
// Similar to `getServerSideProps`.
|
|
556
|
-
const
|
|
560
|
+
const uncachedData = await fetch('https://...', { cache: 'no-store' })
|
|
557
561
|
|
|
558
|
-
//
|
|
562
|
+
// Cache this request, but revalidate it at most every 10 seconds.
|
|
559
563
|
// Similar to `getStaticProps` with the `revalidate` option.
|
|
560
|
-
const revalidatedData = await fetch(
|
|
564
|
+
const revalidatedData = await fetch('https://...', {
|
|
561
565
|
next: { revalidate: 10 },
|
|
562
566
|
})
|
|
563
567
|
|
|
@@ -25,7 +25,7 @@ Next.js can automatically code split your JavaScript bundles, and generate multi
|
|
|
25
25
|
|
|
26
26
|
The [`next/link`](/docs/app/api-reference/components/link) component automatically [prefetches](/docs/app/api-reference/components/link#prefetch) routes, giving you the fast page transitions of a strict SPA, but with the advantage of persisting application routing state to the URL for linking and sharing.
|
|
27
27
|
|
|
28
|
-
Next.js can start as a static site or even a strict SPA where everything is rendered client-side. If your project grows, Next.js allows you to progressively add more server features (e.g. [React Server Components](/docs/app/getting-started/server-and-client-components), [Server Actions](/docs/app/
|
|
28
|
+
Next.js can start as a static site or even a strict SPA where everything is rendered client-side. If your project grows, Next.js allows you to progressively add more server features (e.g. [React Server Components](/docs/app/getting-started/server-and-client-components), [Server Actions](/docs/app/guides/server-actions), and more) as needed.
|
|
29
29
|
|
|
30
30
|
## Examples
|
|
31
31
|
|
|
@@ -358,6 +358,8 @@ server {
|
|
|
358
358
|
}
|
|
359
359
|
```
|
|
360
360
|
|
|
361
|
+
To deploy to GitHub Pages, use our [template](https://github.com/nextjs/deploy-github-pages) to create a new project or as a reference for configuring an existing project.
|
|
362
|
+
|
|
361
363
|
## Version History
|
|
362
364
|
|
|
363
365
|
| Version | Changes |
|
|
@@ -401,6 +401,6 @@ export default async function PostPage({ params }) {
|
|
|
401
401
|
}
|
|
402
402
|
```
|
|
403
403
|
|
|
404
|
-
See
|
|
404
|
+
See [Mutating data](/docs/app/getting-started/mutating-data) for more examples.
|
|
405
405
|
|
|
406
406
|
</AppOnly>
|
|
@@ -162,6 +162,8 @@ In most cases, you should use [`unstable_retry()`](#unstable_retry) instead. How
|
|
|
162
162
|
|
|
163
163
|
While less common, you can handle errors in the root layout or template using `global-error.jsx`, located in the root app directory, even when leveraging [internationalization](/docs/app/guides/internationalization). Global error UI must define its own `<html>` and `<body>` tags, global styles, fonts, or other dependencies that your error page requires. This file replaces the root layout or template when active.
|
|
164
164
|
|
|
165
|
+
> **Good to know**: `global-error` and the built-in 500 page render their own document and do **not** include your global styles, so an app-level theme toggle (a class or `data-theme` attribute) won't reach them. The default UI follows the OS color scheme; to match your app's theme, apply it inside your own `global-error` component.
|
|
166
|
+
|
|
165
167
|
> **Good to know**: Error boundaries must be [Client Components](/docs/app/getting-started/server-and-client-components#using-client-components), which means that [`metadata` and `generateMetadata`](/docs/app/getting-started/metadata-and-og-images) exports are not supported in `global-error.jsx`. As an alternative, you can use the React [`<title>`](https://react.dev/reference/react-dom/components/title) component.
|
|
166
168
|
|
|
167
169
|
```tsx filename="app/global-error.tsx" switcher
|
|
@@ -42,11 +42,13 @@ export default function NotFound() {
|
|
|
42
42
|
|
|
43
43
|
In the [component hierarchy](/docs/app/getting-started/project-structure#component-hierarchy), `not-found.js` renders between `loading.js` and `page.js`. It is wrapped by the `<Suspense>` boundary from `loading.js` and the error boundary from `error.js` in the same segment.
|
|
44
44
|
|
|
45
|
+
> **Good to know**: The default not found UI follows the operating system's color scheme via `prefers-color-scheme` and does not read an app-level theme (such as a class or `data-theme` attribute on `<html>`). Because it renders inside your root layout, the quickest way to match an explicit theme is to add a higher-specificity rule pair in your global stylesheet, scoped to your theme selector — for example `html[data-theme='light'] body` and `html[data-theme='dark'] body`. For full control over the markup, provide your own `not-found.js`.
|
|
46
|
+
|
|
45
47
|
## `global-not-found.js` (experimental)
|
|
46
48
|
|
|
47
49
|
The `global-not-found.js` file lets you define a 404 page for your entire application. Unlike `not-found.js`, which works at the route level, this is used when a requested URL doesn't match any route at all. Next.js **skips rendering** and directly returns this global page.
|
|
48
50
|
|
|
49
|
-
The `global-not-found.js` file bypasses your app's normal rendering, which means you'll need to import any global styles, fonts, or other dependencies that your 404 page requires.
|
|
51
|
+
The `global-not-found.js` file bypasses your app's normal rendering, which means you'll need to import any global styles, fonts, or other dependencies that your 404 page requires. This includes your theme: because `global-not-found.js` bypasses your layout, the OS color scheme is the only signal the default UI sees, so apply your theme (class or attribute) inside this file.
|
|
50
52
|
|
|
51
53
|
> **Good to know**: A smaller version of your global styles, and a simpler font family could improve performance of this page.
|
|
52
54
|
|
|
@@ -4,6 +4,7 @@ description: API Reference for the redirect function.
|
|
|
4
4
|
related:
|
|
5
5
|
links:
|
|
6
6
|
- app/api-reference/functions/permanentRedirect
|
|
7
|
+
- app/guides/server-actions
|
|
7
8
|
---
|
|
8
9
|
|
|
9
10
|
The `redirect` function allows you to redirect the user to another URL. `redirect` can be used while rendering in [Server and Client Components](/docs/app/getting-started/server-and-client-components), [Route Handlers](/docs/app/api-reference/file-conventions/route), and [Server Functions](/docs/app/getting-started/mutating-data).
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: refresh
|
|
3
3
|
description: API Reference for the refresh function.
|
|
4
|
+
related:
|
|
5
|
+
links:
|
|
6
|
+
- app/guides/server-actions
|
|
4
7
|
---
|
|
5
8
|
|
|
6
|
-
`refresh` allows you to refresh the client router from within a [Server Action](/docs/app/
|
|
9
|
+
`refresh` allows you to refresh the client router from within a [Server Action](/docs/app/guides/server-actions).
|
|
7
10
|
|
|
8
11
|
## Usage
|
|
9
12
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: revalidatePath
|
|
3
3
|
description: API Reference for the revalidatePath function.
|
|
4
|
+
related:
|
|
5
|
+
links:
|
|
6
|
+
- app/guides/server-actions
|
|
4
7
|
---
|
|
5
8
|
|
|
6
9
|
`revalidatePath` allows you to invalidate [cached data](/docs/app/getting-started/caching) on-demand for a specific path.
|
|
@@ -72,20 +72,20 @@ export default async function Page({
|
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
```jsx filename="app/page.jsx" switcher
|
|
75
|
-
import { unstable_cache } from 'next/cache'
|
|
75
|
+
import { unstable_cache } from 'next/cache'
|
|
76
76
|
|
|
77
|
-
export default async function Page({ params }
|
|
77
|
+
export default async function Page({ params }) {
|
|
78
78
|
const { userId } = await params
|
|
79
79
|
const getCachedUser = unstable_cache(
|
|
80
80
|
async () => {
|
|
81
|
-
return { id: userId }
|
|
81
|
+
return { id: userId }
|
|
82
82
|
},
|
|
83
83
|
[userId], // add the user ID to the cache key
|
|
84
84
|
{
|
|
85
|
-
tags: [
|
|
85
|
+
tags: ['users'],
|
|
86
86
|
revalidate: 60,
|
|
87
87
|
}
|
|
88
|
-
)
|
|
88
|
+
)
|
|
89
89
|
|
|
90
90
|
//...
|
|
91
91
|
}
|
|
@@ -83,7 +83,7 @@ If a route is [prerendered](/docs/app/glossary#prerendering), calling `useSearch
|
|
|
83
83
|
|
|
84
84
|
This allows a part of the route to be prerendered while the dynamic part that uses `useSearchParams` is client-side rendered.
|
|
85
85
|
|
|
86
|
-
We recommend wrapping the Client Component that uses `useSearchParams` in a `<Suspense/>` boundary. This will allow any Client Components above it to be prerendered and sent as part of initial HTML.
|
|
86
|
+
We recommend wrapping the Client Component that uses `useSearchParams` in a `<Suspense/>` boundary. This will allow any Client Components above it to be prerendered and sent as part of initial HTML.
|
|
87
87
|
|
|
88
88
|
For example:
|
|
89
89
|
|
|
@@ -11,7 +11,7 @@ To set custom HTTP headers you can use the `headers` key in `next.config.js`:
|
|
|
11
11
|
|
|
12
12
|
```js filename="next.config.js"
|
|
13
13
|
module.exports = {
|
|
14
|
-
|
|
14
|
+
headers() {
|
|
15
15
|
return [
|
|
16
16
|
{
|
|
17
17
|
source: '/about',
|
|
@@ -31,7 +31,7 @@ module.exports = {
|
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
`headers`
|
|
34
|
+
`headers` can be defined as a synchronous or async function. It should return, or resolve to, an array of objects with `source` and `headers` properties:
|
|
35
35
|
|
|
36
36
|
- `source` is the incoming request path pattern.
|
|
37
37
|
- `headers` is an array of response header objects, with `key` and `value` properties.
|
|
@@ -48,7 +48,7 @@ If two headers match the same path and set the same header key, the last header
|
|
|
48
48
|
|
|
49
49
|
```js filename="next.config.js"
|
|
50
50
|
module.exports = {
|
|
51
|
-
|
|
51
|
+
headers() {
|
|
52
52
|
return [
|
|
53
53
|
{
|
|
54
54
|
source: '/:path*',
|
|
@@ -79,7 +79,7 @@ Path matches are allowed, for example `/blog/:slug` will match `/blog/first-post
|
|
|
79
79
|
|
|
80
80
|
```js filename="next.config.js"
|
|
81
81
|
module.exports = {
|
|
82
|
-
|
|
82
|
+
headers() {
|
|
83
83
|
return [
|
|
84
84
|
{
|
|
85
85
|
source: '/blog/:slug',
|
|
@@ -111,7 +111,7 @@ To match a wildcard path you can use `*` after a parameter, for example `/blog/:
|
|
|
111
111
|
|
|
112
112
|
```js filename="next.config.js"
|
|
113
113
|
module.exports = {
|
|
114
|
-
|
|
114
|
+
headers() {
|
|
115
115
|
return [
|
|
116
116
|
{
|
|
117
117
|
source: '/blog/:slug*',
|
|
@@ -137,7 +137,7 @@ To match a regex path you can wrap the regex in parenthesis after a parameter, f
|
|
|
137
137
|
|
|
138
138
|
```js filename="next.config.js"
|
|
139
139
|
module.exports = {
|
|
140
|
-
|
|
140
|
+
headers() {
|
|
141
141
|
return [
|
|
142
142
|
{
|
|
143
143
|
source: '/blog/:post(\\d{1,})',
|
|
@@ -157,7 +157,7 @@ The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for reg
|
|
|
157
157
|
|
|
158
158
|
```js filename="next.config.js"
|
|
159
159
|
module.exports = {
|
|
160
|
-
|
|
160
|
+
headers() {
|
|
161
161
|
return [
|
|
162
162
|
{
|
|
163
163
|
// this will match `/english(default)/something` being requested
|
|
@@ -186,7 +186,7 @@ To only apply a header when header, cookie, or query values also match the `has`
|
|
|
186
186
|
|
|
187
187
|
```js filename="next.config.js"
|
|
188
188
|
module.exports = {
|
|
189
|
-
|
|
189
|
+
headers() {
|
|
190
190
|
return [
|
|
191
191
|
// if the header `x-add-header` is present,
|
|
192
192
|
// the `x-another-header` header will be applied
|
|
@@ -296,7 +296,7 @@ When leveraging [`basePath` support](/docs/app/api-reference/config/next-config-
|
|
|
296
296
|
module.exports = {
|
|
297
297
|
basePath: '/docs',
|
|
298
298
|
|
|
299
|
-
|
|
299
|
+
headers() {
|
|
300
300
|
return [
|
|
301
301
|
{
|
|
302
302
|
source: '/with-basePath', // becomes /docs/with-basePath
|
|
@@ -343,7 +343,7 @@ module.exports = {
|
|
|
343
343
|
defaultLocale: 'en',
|
|
344
344
|
},
|
|
345
345
|
|
|
346
|
-
|
|
346
|
+
headers() {
|
|
347
347
|
return [
|
|
348
348
|
{
|
|
349
349
|
source: '/with-locale', // automatically handles all locales
|
|
@@ -486,7 +486,7 @@ export async function getServerSideProps({ req, res }) {
|
|
|
486
486
|
[Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/docs/Web/HTTP/CORS) is a security feature that allows you to control which sites can access your resources. You can set the `Access-Control-Allow-Origin` header to allow a specific origin to access your <PagesOnly>API Endpoints</PagesOnly><AppOnly>Route Handlers</AppOnly>.
|
|
487
487
|
|
|
488
488
|
```js
|
|
489
|
-
|
|
489
|
+
headers() {
|
|
490
490
|
return [
|
|
491
491
|
{
|
|
492
492
|
source: "/api/:path*",
|
|
@@ -11,7 +11,7 @@ To use redirects you can use the `redirects` key in `next.config.js`:
|
|
|
11
11
|
|
|
12
12
|
```js filename="next.config.js"
|
|
13
13
|
module.exports = {
|
|
14
|
-
|
|
14
|
+
redirects() {
|
|
15
15
|
return [
|
|
16
16
|
{
|
|
17
17
|
source: '/about',
|
|
@@ -23,7 +23,7 @@ module.exports = {
|
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
`redirects`
|
|
26
|
+
`redirects` can be defined as a synchronous or async function. It should return, or resolve to, an array of objects with `source`, `destination`, and `permanent` properties:
|
|
27
27
|
|
|
28
28
|
- `source` is the incoming request path pattern.
|
|
29
29
|
- `destination` is the path you want to route to.
|
|
@@ -60,7 +60,7 @@ Path matches are allowed, for example `/old-blog/:slug` will match `/old-blog/fi
|
|
|
60
60
|
|
|
61
61
|
```js filename="next.config.js"
|
|
62
62
|
module.exports = {
|
|
63
|
-
|
|
63
|
+
redirects() {
|
|
64
64
|
return [
|
|
65
65
|
{
|
|
66
66
|
source: '/old-blog/:slug',
|
|
@@ -84,7 +84,7 @@ To match a wildcard path you can use `*` after a parameter, for example `/blog/:
|
|
|
84
84
|
|
|
85
85
|
```js filename="next.config.js"
|
|
86
86
|
module.exports = {
|
|
87
|
-
|
|
87
|
+
redirects() {
|
|
88
88
|
return [
|
|
89
89
|
{
|
|
90
90
|
source: '/blog/:slug*',
|
|
@@ -102,7 +102,7 @@ To match a regex path you can wrap the regex in parentheses after a parameter, f
|
|
|
102
102
|
|
|
103
103
|
```js filename="next.config.js"
|
|
104
104
|
module.exports = {
|
|
105
|
-
|
|
105
|
+
redirects() {
|
|
106
106
|
return [
|
|
107
107
|
{
|
|
108
108
|
source: '/post/:slug(\\d{1,})',
|
|
@@ -118,7 +118,7 @@ The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for reg
|
|
|
118
118
|
|
|
119
119
|
```js filename="next.config.js"
|
|
120
120
|
module.exports = {
|
|
121
|
-
|
|
121
|
+
redirects() {
|
|
122
122
|
return [
|
|
123
123
|
{
|
|
124
124
|
// this will match `/english(default)/something` being requested
|
|
@@ -143,7 +143,7 @@ To only match a redirect when header, cookie, or query values also match the `ha
|
|
|
143
143
|
|
|
144
144
|
```js filename="next.config.js"
|
|
145
145
|
module.exports = {
|
|
146
|
-
|
|
146
|
+
redirects() {
|
|
147
147
|
return [
|
|
148
148
|
// if the header `x-redirect-me` is present,
|
|
149
149
|
// this redirect will be applied
|
|
@@ -233,7 +233,7 @@ When leveraging [`basePath` support](/docs/app/api-reference/config/next-config-
|
|
|
233
233
|
module.exports = {
|
|
234
234
|
basePath: '/docs',
|
|
235
235
|
|
|
236
|
-
|
|
236
|
+
redirects() {
|
|
237
237
|
return [
|
|
238
238
|
{
|
|
239
239
|
source: '/with-basePath', // automatically becomes /docs/with-basePath
|
|
@@ -262,7 +262,7 @@ For dynamic or per-request locale handling, use [dynamic route segments and prox
|
|
|
262
262
|
|
|
263
263
|
```js filename="next.config.js"
|
|
264
264
|
module.exports = {
|
|
265
|
-
|
|
265
|
+
redirects() {
|
|
266
266
|
return [
|
|
267
267
|
{
|
|
268
268
|
// Manually handle locale prefixes for App Router
|
|
@@ -306,7 +306,7 @@ module.exports = {
|
|
|
306
306
|
defaultLocale: 'en',
|
|
307
307
|
},
|
|
308
308
|
|
|
309
|
-
|
|
309
|
+
redirects() {
|
|
310
310
|
return [
|
|
311
311
|
{
|
|
312
312
|
source: '/with-locale', // automatically handles all locales
|