-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' into fix/typescript-get-img-props-alt-text
- Loading branch information
Showing
41 changed files
with
859 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: Cannot access `cookies()` or `headers()` in `"use cache"` | ||
--- | ||
|
||
#### Why This Error Occurred | ||
|
||
A function is trying to read from the current incoming request inside the scope of a function annotated with `"use cache"`. This is not supported because it would make the cache invalidated by every request which is probably not what you intended. | ||
|
||
#### Possible Ways to Fix It | ||
|
||
Instead of calling this inside the `"use cache"` function, move it outside the function and pass the value in as an argument. The specific value will now be part of the cache key through its arguments. | ||
|
||
Before: | ||
|
||
```jsx filename="app/page.js" | ||
import { cookies } from 'next/headers' | ||
|
||
async function getExampleData() { | ||
"use cache" | ||
- const isLoggedIn = (await cookies()).has('token') | ||
... | ||
} | ||
|
||
export default async function Page() { | ||
const data = await getExampleData() | ||
return ... | ||
} | ||
``` | ||
|
||
After: | ||
|
||
```jsx filename="app/page.js" | ||
import { cookies } from 'next/headers' | ||
|
||
async function getExampleData(isLoggedIn) { | ||
"use cache" | ||
... | ||
} | ||
|
||
export default async function Page() { | ||
+ const isLoggedIn = (await cookies()).has('token') | ||
const data = await getExampleData(isLoggedIn) | ||
return ... | ||
} | ||
``` | ||
|
||
### Useful Links | ||
|
||
- [`headers()` function](https://nextjs.org/docs/app/api-reference/functions/headers) | ||
- [`cookies()` function](https://nextjs.org/docs/app/api-reference/functions/cookies) | ||
- [`draftMode()` function](https://nextjs.org/docs/app/api-reference/functions/draft-mode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
import type { NextConfig } from '../server/config-shared' | ||
|
||
export function needsExperimentalReact(config: NextConfig) { | ||
return Boolean( | ||
config.experimental?.ppr || | ||
config.experimental?.taint || | ||
config.experimental?.dynamicIO | ||
) | ||
return Boolean(config.experimental?.ppr || config.experimental?.taint) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.