vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.95k stars 26.98k forks source link

On-Demand Revalidation not working if Server Actions are used #51504

Open patshologram opened 1 year ago

patshologram commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:24 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.16.0
      npm: 9.6.7
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.4.6
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5

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

App directory (appDir: true), Standalone mode (output: "standalone")

Link to the code that reproduces this issue or a replay of the bug

https://github.com/patshologram/revalidation-with-server-actions.git

To Reproduce

  1. clone the provided project
  2. install the dependencies via yarn
  3. built the standalone server via yarn build
  4. start the standalone server via node .next/standalone/server.js
  5. execute http://localhost:3000/api/revalidate

Side-Note: I've tried to reproduce this with 13.4.7-canary.1 but I get the following exception with the latest canary

❯ node .next/standalone/server.js
Listening on port 3000 url: http://localhost:3000
Error: connect ECONNREFUSED ::1:57906
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 57906
}
Error: connect ECONNREFUSED ::1:57906
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 57906
}

Describe the Bug

Upon revalidation, an exception is thrown

Revalidating static pages
Error: Invalid response 200
    at NextNodeServer.revalidate (/Users/martonpa/Sources/revalidation-with-server-actions/.next/standalone/node_modules/next/dist/server/next-server.js:1286:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Server.<anonymous> (/Users/martonpa/Sources/revalidation-with-server-actions/.next/standalone/node_modules/next/dist/server/lib/server-ipc/index.js:55:30)
Error revalidating Error: Failed to revalidate /: Invalid response 200
    at revalidate (/Users/martonpa/Sources/revalidation-with-server-actions/.next/standalone/node_modules/next/dist/server/api-utils/node.js:387:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async handler (/Users/martonpa/Sources/revalidation-with-server-actions/.next/standalone/.next/server/pages/api/revalidate.js:18:9)

Removing the serverActions: true from nextjs.config.js and the use server from actions.ts leads to a working revalidation.

Expected Behavior

On-Demand Revalidation should work despite the activated Server Actions.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

EC2 Instance

patshologram commented 1 year ago

Possible related issues:

quinm0 commented 1 year ago

@patshologram does this crash your browser when you run it? If so I'm seeing the same issue

AeroWang commented 1 year ago

It seems to be more than just output: standalone. On-Demand Revalidation not working if Server Actions are used