Skip to content

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

@patshologram

Description

@patshologram

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions