Unverified Commit 2ba4a854 authored by Joseph's avatar Joseph Committed by GitHub

global-error, revalidatePath and PWA headings (#82408)

Complement to: https://github.com/vercel/next.js/issues/82379

Also adding corrections to other sections
parent d016157c
......@@ -23,6 +23,8 @@ The Metadata APIs can be used to define your application metadata for improved S
With all the options above, Next.js will automatically generate the relevant `<head>` tags for your page, which can be inspected in the browser's developer tools.
The `metadata` object and `generateMetadata` function exports are only supported in Server Components.
## Default fields
There are two default `meta` tags that are always added even if a route doesn't define metadata:
......
......@@ -648,7 +648,7 @@ Let’s go over each of these options:
Learn more about defining [Content Security Policies](/docs/app/guides/content-security-policy) with Next.js.
## Next Steps
## Extending your PWA
1. **Exploring PWA Capabilities**: PWAs can leverage various web APIs to provide advanced functionality. Consider exploring features like background sync, periodic background sync, or the File System Access API to enhance your application. For inspiration and up-to-date information on PWA capabilities, you can refer to resources like [What PWA Can Do Today](https://whatpwacando.today/).
2. **Static Exports:** If your application requires not running a server, and instead using a static export of files, you can update the Next.js configuration to enable this change. Learn more in the [Next.js Static Export documentation](/docs/app/guides/static-exports). However, you will need to move from Server Actions to calling an external API, as well as moving your defined headers to your proxy.
......
......@@ -153,7 +153,9 @@ export default function Error({ error, reset }) {
### Global Error
While less common, you can handle errors in the root layout or template using `global-error.js`, 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. This file replaces the root layout or template when active.
While less common, you can handle errors in the root layout or template using `global-error.js`, 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.
> **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.js`. As an alternative, you can use the React [`<title>`](https://react.dev/reference/react-dom/components/title) component.
```tsx filename="app/global-error.tsx" switcher
'use client' // Error boundaries must be Client Components
......
......@@ -35,7 +35,17 @@ The path parameter can point to pages, layouts, or route handlers:
- **Pages**: Revalidates the specific page
- **Layouts**: Revalidates the layout and all pages beneath it
- **GET Route Handlers**: Only if they're statically generated
- **Route Handlers**: Revalidates Data Cache entries accessed within route handlers. For example `revalidatePath("/api/data")` revalidates this GET handler:
```ts filename="app/api/data/route.ts"
export async function GET() {
const data = await fetch('https://api.vercel.app/blog', {
cache: 'force-cache',
})
return Response.json(await data.json())
}
```
## Relationship with `revalidateTag`
......@@ -84,7 +94,7 @@ This pattern ensures that both the specific page and any other pages using the s
## Examples
### Revalidating A Specific URL
### Revalidating a specific URL
```ts
import { revalidatePath } from 'next/cache'
......@@ -93,7 +103,7 @@ revalidatePath('/blog/post-1')
This will revalidate one specific URL on the next page visit.
### Revalidating A Page Path
### Revalidating a Page path
```ts
import { revalidatePath } from 'next/cache'
......@@ -104,7 +114,7 @@ revalidatePath('/(main)/blog/[slug]', 'page')
This will revalidate any URL that matches the provided `page` file on the next page visit. This will _not_ invalidate pages beneath the specific page. For example, `/blog/[slug]` won't invalidate `/blog/[slug]/[author]`.
### Revalidating A Layout Path
### Revalidating a Layout path
```ts
import { revalidatePath } from 'next/cache'
......@@ -115,7 +125,7 @@ revalidatePath('/(main)/post/[slug]', 'layout')
This will revalidate any URL that matches the provided `layout` file on the next page visit. This will cause pages beneath with the same layout to revalidate on the next visit. For example, in the above case, `/blog/[slug]/[another]` would also revalidate on the next visit.
### Revalidating All Data
### Revalidating all data
```ts
import { revalidatePath } from 'next/cache'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment