forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn when mutating res if not streaming (vercel#30284)
In vercel#29010, we started throwing an error if the res was mutated after getServerSideProps() returned. This was to support classic streaming, where it would be possible to accidentally mutate the response headers after they were already sent. However, this change also caught [a few non-streaming cases](vercel#29010 (comment)) that we don't want to break. As such, with this change, we only throw the error if res is mutated after gSSP returns *and* you've opted into using classic streaming. Otherwise, we will only add a warning to the console.
- Loading branch information
Showing
4 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
test/integration/getserversideprops/pages/promise/mutate-res-no-streaming.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
let mutatedResNoStreaming | ||
|
||
export async function getServerSideProps(context) { | ||
mutatedResNoStreaming = context.res | ||
return { | ||
props: { | ||
text: 'res', | ||
}, | ||
} | ||
} | ||
|
||
export default ({ text }) => { | ||
mutatedResNoStreaming.setHeader('test-header', 'this is a test header') | ||
|
||
return ( | ||
<> | ||
<div>hello {text}</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters