Repository: next.js
Issue: Failure to Revalidate
Labels: bug,Navigation,Pages Router

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:
      Platform: linux
      Arch: x64
      Version: #85-Ubuntu SMP Fri Jul 7 15:25:09 UTC 2023
    Binaries:
      Node: 20.3.0
      npm: 9.6.7
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.4.20-canary.2
      eslint-config-next: 13.4.12
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.0.4
    Next.js Config:
      output: N/A
```


### Which area(s) of Next.js are affected? (leave empty if unsure)

Data fetching (gS(S)P, getInitialProps), Routing (next/router, next/navigation, next/link)

### Link to the code that reproduces this issue or a replay of the bug

https://codesandbox.io/p/sandbox/stackoverflow-76909444-1-jsg3nd?file=/pages/api/revalidate.ts:13,1

### To Reproduce

1. Run the provided sandbox
2. Click the link "/resource/1".
3. Click the link "/resource/1/edit"
4. Click the "Revalidate" button.
5. Everything works.

~When a helpful Stack Overflow user downloaded and ran that same sandbox locally, he saw the same thing.~
**Edit:** Actually, he later reported that he saw the same error as I did ...

However, when I download and run that sandbox, and repeat the steps, I get:

```
Error: Invalid response 200
    at Object.revalidate (/home/me project/test2/node_modules/next/dist/server/lib/router-server.js:114:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Server.<anonymous> (/home/me project/test2/node_modules/next/dist/server/lib/server-ipc/index.js:56:30)
```

**NOTE:** The sandbox doesn't come with canary Next, but I changed it to canary locally and still saw this issue.

### Describe the Bug

I get a server-side error everytime I try to `revaluate` (in sandbox test projects or in my own).

I tried to understand why the bug is happening, so I looked at the `revalidate`  source code.  All I can tell is that `revalidate` creates some sort of mock server, runs a request (to the URL being revalidated) through it, and then checks the (mock) response ...

        if (mocked.res.getHeader("x-nextjs-cache") !== "REVALIDATED" && !(mocked.res.statusCode === 404 && opts.unstable_onlyGenerated)) {
            throw new Error(`Invalid response ${mocked.res.statusCode}`);
        }

`mocked.res.getHeader("x-nextjs-cache")` isn't `"REVALIDATED"` ... it's `"MISS"`, so the error gets thrown.

That header (I think?) comes from `base-server.js`:

```
        if (isSSG && !this.minimalMode) {
            // set x-nextjs-cache header to match the header
            // we set for the image-optimizer
            res.setHeader("x-nextjs-cache", isOnDemandRevalidate ? "REVALIDATED" : cacheEntry.isMiss ? "MISS" : cacheEntry.isStale ? "STALE" : "HIT");
        }
```

but I can't understand what's going on there enough to explain why the header is being set to `"MISS"` on my machine.

~I _certainly_ can't explain why I'm having this error, and another dev running identical code isn't.~  Any help understanding why, and how to fix it, would be appreciated.

### Expected Behavior

I can follow the repro steps and not get an error.

### Which browser are you using? (if relevant)

n/a

### How are you deploying your application? (if relevant)

n/a