Skip to content

Commit

Permalink
docs: unify the header deps by removing # (#72391)
Browse files Browse the repository at this point in the history
## Summary
Remove redundant `#` from [error
pages](https://github.com/vercel/next.js/tree/canary/errors).

## Description
Follow up #52038 and #72263.
Updated
[template.txt](https://github.com/vercel/next.js/blob/canary/errors/template.txt)
and clarified the header deps.
Then rewrite as per the template.

### Improving Documentation

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening
the PR.
- [x] Read the Docs Contribution Guide to ensure your contribution
follows the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

Co-authored-by: Delba de Oliveira <[email protected]>
  • Loading branch information
JamBalaya56562 and delbaoliveira authored Nov 7, 2024
1 parent 3066987 commit 74a19b7
Show file tree
Hide file tree
Showing 37 changed files with 83 additions and 81 deletions.
8 changes: 4 additions & 4 deletions errors/class-component-in-server-component.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ You are rendering a React Class Component in a Server Component, `React.Componen

Use a Function Component.

##### Before
### Before

```jsx filename="app/page.js"
export default class Page extends React.Component {
Expand All @@ -20,7 +20,7 @@ export default class Page extends React.Component {
}
```

##### After
### After

```jsx filename="app/page.js"
export default function Page() {
Expand All @@ -30,7 +30,7 @@ export default function Page() {

Mark the component rendering the React Class Component as a Client Component by adding `'use client'` at the top of the file.

##### Before
### Before

```jsx filename="app/page.js"
export default class Page extends React.Component {
Expand All @@ -40,7 +40,7 @@ export default class Page extends React.Component {
}
```

##### After
### After

```jsx filename="app/page.js"
'use client'
Expand Down
4 changes: 2 additions & 2 deletions errors/context-in-server-component.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ You are using `createContext` in a Server Component but it only works in Client

Mark the component using `createContext` as a Client Component by adding `'use client'` at the top of the file.

##### Before
### Before

```jsx filename="app/example-component.js"
import { createContext } from 'react'

const Context = createContext()
```

##### After
### After

```jsx filename="app/example-component.js"
'use client'
Expand Down
2 changes: 1 addition & 1 deletion errors/css-global.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ There are two possible ways to fix this error:
- Move all global CSS imports to your [`pages/_app.js` file](/docs/pages/building-your-application/routing/custom-app).
- If you do not wish your stylesheet to be global, update it to use [CSS Modules](/docs/pages/building-your-application/styling/css). This will allow you to import the stylesheet and scope the styles to a specific component.

#### Example
### Example

Consider the stylesheet named [`styles.css`](/docs/pages/building-your-application/styling/css)

Expand Down
2 changes: 1 addition & 1 deletion errors/custom-document-image-import.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Custom documents aren't compiled for the browser and images statically imported

If your image needs to be displayed on every page you can relocate it to your [`pages/_app.js`](/docs/pages/building-your-application/routing/custom-app) file.

#### Example
### Example

```jsx filename="pages/_app.js"
import yourImage from 'path/to/your/image'
Expand Down
2 changes: 1 addition & 1 deletion errors/dynamic-server-error.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: DynamicServerError - Dynamic Server Usage
---

#### Why This Message Occurred
## Why This Message Occurred

You attempted to use a Next.js function that depends on Async Context (such as `headers` or `cookies` from `next/headers`) but it was not bound to the same call stack as the function that ran it (e.g., calling `cookies()` inside of a `setTimeout` or `setInterval`).

Expand Down
2 changes: 1 addition & 1 deletion errors/empty-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: 'Detected `next.config.js`, no exported configuration found'
---

#### Why This Warning Occurred
## Why This Warning Occurred

There is no object exported from next.config.js or the object is empty.

Expand Down
2 changes: 1 addition & 1 deletion errors/experimental-jest-transformer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: '`next/jest` Experimental'
---

#### Why This Message Occurred
## Why This Message Occurred

You are using `next/jest` which is currently an experimental feature of Next.js. In a future version of Next.js `next/jest` will be marked as stable.

Expand Down
2 changes: 1 addition & 1 deletion errors/failed-loading-swc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: SWC Failed to Load
---

#### Why This Message Occurred
## Why This Message Occurred

Next.js now uses Rust-based compiler [SWC](https://swc.rs/) to compile JavaScript/TypeScript. This new compiler is up to 17x faster than Babel when compiling individual files and up to 5x faster Fast Refresh.

Expand Down
2 changes: 1 addition & 1 deletion errors/get-initial-props-export.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: '`getInitialProps` Export Warning'
---

#### Why This Warning Occurred
## Why This Warning Occurred

You attempted to statically export your application via `output: 'export'` or `next export`, however, one or more of your pages uses `getInitialProps`.

Expand Down
4 changes: 2 additions & 2 deletions errors/google-fonts-missing-subsets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ Preload is enabled for a font that is missing a specified subset.

## Possible Ways to Fix It

##### Specify which subsets to preload for that font.
### Specify which subsets to preload for that font.

```js filename="example.js"
const inter = Inter({ subsets: ['latin'] })
```

Note: previously it was possible to specify default subsets in your `next.config.js` with the `experimental.fontLoaders` option, but this is no longer supported.

##### Disable preloading for that font
### Disable preloading for that font

If it's not possible to preload your intended subset you can disable preloading.

Expand Down
4 changes: 2 additions & 2 deletions errors/invalid-route-source.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This could have been due to trying to use normal `RegExp` syntax like negative l

Wrap the `RegExp` part of your `source` as an un-named parameter.

##### Custom Routes
### Custom Routes

**Before**

Expand All @@ -32,7 +32,7 @@ Wrap the `RegExp` part of your `source` as an un-named parameter.
}
```

##### Middleware
### Middleware

**Before**

Expand Down
6 changes: 3 additions & 3 deletions errors/missing-root-layout-tags.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
title: Missing Root Layout tags
---

#### Why This Error Occurred
## Why This Error Occurred

You forgot to define the `<html>` and/or `<body>` tags in your Root Layout.

#### Possible Ways to Fix It
## Possible Ways to Fix It

To fix this error, make sure that both `<html>` and `<body>` are present in your Root Layout.

Expand All @@ -24,6 +24,6 @@ export default function Layout({ children }: { children: React.ReactNode }) {
}
```

### Useful Links
## Useful Links

- [Root Layout](https://nextjs.org/docs/app/building-your-application/routing/layouts-and-templates#root-layout-required)
8 changes: 4 additions & 4 deletions errors/missing-suspense-with-csr-bailout.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
title: Missing Suspense boundary with useSearchParams
---

#### Why This Error Occurred
## Why This Error Occurred

Reading search parameters through `useSearchParams()` without a Suspense boundary will opt the entire page into client-side rendering. This could cause your page to be blank until the client-side JavaScript has loaded.

#### Possible Ways to Fix It
## Possible Ways to Fix It

Ensure that calls to `useSearchParams()` are wrapped in a Suspense boundary.

Expand Down Expand Up @@ -56,7 +56,7 @@ export function Searchbar() {

This will ensure the page does not de-opt to client-side rendering.

#### Disabling
## Disabling

> Note: This is only available with Next.js version 14.x. If you're in versions above 14 please fix it with the approach above.
Expand All @@ -72,6 +72,6 @@ module.exports = {

This configuration option will be removed in a future major version.

### Useful Links
## Useful Links

- [`useSearchParams`](https://nextjs.org/docs/app/api-reference/functions/use-search-params)
8 changes: 4 additions & 4 deletions errors/module-not-found.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A module not found error can occur for many different reasons:

## Possible Ways to Fix It

##### The module you're trying to import is not installed in your dependencies
### The module you're trying to import is not installed in your dependencies

When importing a module from [npm](https://npmjs.com) this module has to be installed locally.

Expand All @@ -28,11 +28,11 @@ The `swr` module has to be installed using a package manager.
- When using `npm`: `npm install swr`
- When using `yarn`: `yarn add swr`

##### The module you're trying to import is in a different directory
### The module you're trying to import is in a different directory

Make sure that the path you're importing refers to the right directory and file.

##### The module you're trying to import has a different casing
### The module you're trying to import has a different casing

Make sure the casing of the file is correct.

Expand All @@ -51,7 +51,7 @@ import MyComponent from '../components/Mycomponent'

Incorrect casing will lead to build failures on case-sensitive environments like most Linux-based continuous integration and can cause issues with Fast Refresh.

##### The module you're trying to import uses Node.js specific modules
### The module you're trying to import uses Node.js specific modules

`getStaticProps`, `getStaticPaths`, and `getServerSideProps` allow for using modules that can only run in the Node.js environment. This allows you to do direct database queries or reading data from Redis to name a few examples.

Expand Down
6 changes: 3 additions & 3 deletions errors/next-dynamic-api-wrong-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
title: Dynamic API was called outside request
---

#### Why This Error Occurred
## Why This Error Occurred

A Dynamic API was called outside a request scope. (Eg.: Global scope).

Note that Dynamic APIs could have been called deep inside other modules/functions (eg.: third-party libraries) that are not immediately visible.

#### Possible Ways to Fix It
## Possible Ways to Fix It

Make sure that all Dynamic API calls happen in a request scope.

Expand All @@ -34,7 +34,7 @@ export async function GET() {
}
```

### Useful Links
## Useful Links

- [`headers()` function](https://nextjs.org/docs/app/api-reference/functions/headers)
- [`cookies()` function](https://nextjs.org/docs/app/api-reference/functions/cookies)
Expand Down
2 changes: 1 addition & 1 deletion errors/next-image-unconfigured-host.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
}
```

#### Fixing older versions of Next.js
### Fixing older versions of Next.js

<details>
<summary>Using Next.js prior to 12.3.0?</summary>
Expand Down
6 changes: 3 additions & 3 deletions errors/next-prerender-crypto.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
title: Cannot access `crypto.getRandomValue()`, `crypto.randomUUID()`, or another web or node crypto API that generates random values synchronously while prerendering
---

#### Why This Error Occurred
## Why This Error Occurred

An API that produces a random value synchronously from the Web Crypto API or from Node's `crypto` API was called outside of a `"use cache"` scope and without first calling `await connection()`. Random values that are produced synchronously must either be inside a `"use cache"` scope or be preceded with `await connection()` to explicitly communicate to Next.js whether the random values produced can be reused across many requests (cached) or if they must be unique per Request (`await connection()`).

If the API used has an async version you can also switch to that in instead of using `await connection()`.

#### Possible Ways to Fix It
## Possible Ways to Fix It

If you are generating a token to talk to a database that itself should be cached move the token generation inside the `"use cache"`.

Expand Down Expand Up @@ -91,7 +91,7 @@ export default async function Page() {
}
```

### Useful Links
## Useful Links

- [`connection` function](https://nextjs.org/docs/app/api-reference/functions/connection)
- [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)
Expand Down
14 changes: 7 additions & 7 deletions errors/next-prerender-current-time.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
title: Cannot infer intended usage of current time with `Date.now()`, `Date()`, or `new Date()`
---

#### Why This Error Occurred
## Why This Error Occurred

Reading the current time can be ambiguous. Sometimes you intend to capture the time when something was cached, other times you intend to capture the time of a user Request. You might also be trying to measure runtime performance to track elapsed time.

In this instance Next.js cannot determine your intent from usage so it needs you to clarify your intent. The way you do that depends on your use case. See the possible solutions below for how to move forward.

#### Possible Ways to Fix It
## Possible Ways to Fix It

##### Performance use case
### Performance use case

If you are using the current time for performance tracking with elapsed time use `performance.now()`.

Expand Down Expand Up @@ -41,7 +41,7 @@ export default async function Page() {

Note: If you need report an absolute time to an observability tool you can also use `performance.timeOrigin + performance.now()`.

##### Cacheable use cases
### Cacheable use cases

If you want to read the time when some cache entry is created (such as when a Next.js page is rendered at build-time or when revalidating a static page), move the current time read inside a cached function using `"use cache"`.

Expand Down Expand Up @@ -94,7 +94,7 @@ export default async function Page() {
}
```

##### Reactive use case
### Reactive use case

If you want the current time to change and be reactive, consider moving this usage to a Client Component. Note that Server Side Rendering timestamps in a Client Component is also considered ambiguous so to implement this properly Next.js needs you to only read the time in the browser, for instance by using `useLayoutEffect()` or `useEffect()`.

Expand Down Expand Up @@ -149,7 +149,7 @@ export default async function Page() {
}
```

##### Request-time use case
### Request-time use case

If you want the current time to represent the time of a user Request, add `await connection()` before you read the current time. This instructs Next.js that everything after the `await connection()` requires there to be a user Request before it can run. If you add `await connection()` you will also need to ensure there is a Suspense boundary somewhere above the waiting component that describes a fallback UI React can use. The Suspense can be anywhere in the parent component stack but it is shown here above the waiting component for demonstration purposes.

Expand Down Expand Up @@ -192,7 +192,7 @@ async function DynamicBanner() {
}
```

### Useful Links
## Useful Links

- [`Date.now` API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
- [`Date constructor` API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date)
Expand Down
Loading

0 comments on commit 74a19b7

Please sign in to comment.