mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
bc59f210b0
This PR removes middleware docs and adds a "Migration to Proxy" section to the Proxy docs, which explains the rationale for the renaming to Proxy and provides a migration guide. Did not remove `middleware-upgrade-docs` as it's an upgrade doc from the legacy middleware. Below are untouched as they need codebase changes: - `instrumentation` docs - `onRequestError` has `context.routeType` as `'middleware'` - `adapterPath` docs - has `MiddlewareMatcher` type example - `ProxyConfig` - has a user-facing `MiddlewareMatcher` type --------- Co-authored-by: Joseph Chamochumbi <joseph.chamochumbi@vercel.com>
22 lines
1.1 KiB
Plaintext
22 lines
1.1 KiB
Plaintext
---
|
||
title: 'Must not access ServerResponse after `getServerSideProps` resolves'
|
||
---
|
||
|
||
## Why This Error Occurred
|
||
|
||
`getServerSideProps()` surfaces a `ServerResponse` object through the `res` property of its `context` arg. This object is not intended to be accessed or changed after `getServerSideProps()` resolves.
|
||
|
||
This is because the framework tries to optimize when items like headers or status codes are flushed to the browser. If they are changed after `getServerSideProps()` completes, we can't guarantee that the changes will work.
|
||
|
||
For this reason, accessing the object after this time is disallowed.
|
||
|
||
## Possible Ways to Fix It
|
||
|
||
You can fix this error by moving any access of the `res` object into `getServerSideProps()` itself or any functions that run before `getServerSideProps()` returns.
|
||
|
||
If you’re using a custom server and running into this problem due to session proxy like `next-session` or `express-session`, try installing the proxy in the server instead of `getServerSideProps()`.
|
||
|
||
## Useful Links
|
||
|
||
- [Data Fetching Docs](/docs/pages/building-your-application/data-fetching)
|