Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On-Demand revalidation fails with "res.hasHeader is not a function" when cookies() is used (/app directory) #45481

Closed
1 task done
patshologram opened this issue Feb 1, 2023 · 2 comments · Fixed by #45681
Labels
bug Issue was opened via the bug report template.

Comments

@patshologram
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000
Binaries:
  Node: 18.12.1
  npm: 9.2.0
  Yarn: 1.22.19
  pnpm: N/A
Relevant packages:
  next: 13.1.7-canary.1
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue

https://github.com/patshologram/revalidation-error

To Reproduce

TypeError: res.hasHeader is not a function
    at Object.setRevalidateHeaders (/Users/martonpa/Sources/my-app/node_modules/next/dist/server/send-payload/revalidate-headers.js:8:37)
    at Object.sendRenderResult (/Users/martonpa/Sources/my-app/node_modules/next/dist/server/send-payload/index.js:62:33)
    at NextNodeServer.sendRenderResult (/Users/martonpa/Sources/my-app/node_modules/next/dist/server/next-server.js:394:34)
    at NextNodeServer.pipe (/Users/martonpa/Sources/my-app/node_modules/next/dist/server/base-server.js:419:25)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.fn (/Users/martonpa/Sources/my-app/node_modules/next/dist/server/next-server.js:759:21)
    at async Router.execute (/Users/martonpa/Sources/my-app/node_modules/next/dist/server/router.js:253:36)
    at async NextNodeServer.run (/Users/martonpa/Sources/my-app/node_modules/next/dist/server/base-server.js:384:29)
    at async NextNodeServer.handleRequest (/Users/martonpa/Sources/my-app/node_modules/next/dist/server/base-server.js:322:20)

Describe the Bug

Using cookies within a server component breaks the on-demand revalidation.

Expected Behavior

On-demand revalidation should work for pages using next/headers functions.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@patshologram patshologram added the bug Issue was opened via the bug report template. label Feb 1, 2023
@ijjk
Copy link
Member

ijjk commented Feb 8, 2023

Hi, using cookies() causes a page to be dynamic and not statically generated so On-Demand ISR isn't necessary. The above error shouldn't be thrown though so that will be addressed in #45681

ijjk added a commit that referenced this issue Feb 8, 2023
Replaces usage of `hasHeader` of `getHeader` and also ensures we include
`hasHeader` in our `mockRes` we create during revalidate for good
measure.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Closes: #34929
Closes: #37338
Closes: #45481
jankaifer pushed a commit to jankaifer/next.js that referenced this issue Feb 14, 2023
Replaces usage of `hasHeader` of `getHeader` and also ensures we include
`hasHeader` in our `mockRes` we create during revalidate for good
measure.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Closes: vercel#34929
Closes: vercel#37338
Closes: vercel#45481
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants