-
-
Notifications
You must be signed in to change notification settings - Fork 996
Description
As of Next.js v12, there are console warnings when accessing res after getServerSideProps finishes. The warning looks like this:
warn - You should not access 'res' after getServerSideProps resolves.
Read more: https://nextjs.org/docs/messages/gssp-no-mutating-res
This appears to be due to the automatic committing of session changes within express-session here:
Lines 246 to 250 in 66634e9
| // proxy end() to commit the session | |
| var _end = res.end; | |
| var _write = res.write; | |
| var ended = false; | |
| res.end = function end(chunk, encoding) { |
The library next-session uses a similar mechanism, but allows disabling it via option {autoCommit: false}:
https://github.com/hoangvvo/next-session/blob/b87f2cae77b321fb8960358cb3e85cfda9ecd701/src/session.ts#L119-L124
In the Next.js PR related to this change, they noted that this warning shouldn't break anything, but would prevent future adoption of streaming features. They suggested that libraries like express-session could support manual committing of session changes in order to avoid this issue:
vercel/next.js#29010 (comment)
Would you be open to this additional option?