Unverified Commit 02405e22 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix getServerSideProps hanging in dev on early end (#33366)

This fixes the case where calling `res.end()` is `getServerSideProps` would cause the request to hang in development due to our `Proxy` around `res` causing internal `ServerResponse` fields to not be available ([related post](https://javascript.info/proxy#built-in-objects-internal-slots)). I also migrated our `getServerSideProps` test suite to an e2e suite with a test for this case. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/15118
Fixes: https://github.com/vercel/next.js/issues/32824
Closes: https://github.com/vercel/next.js/pull/33129
parent 10c4f5d1
......@@ -961,7 +961,15 @@ export async function renderToHTML(
warn(message)
}
}
return Reflect.get(obj, prop, receiver)
const value = Reflect.get(obj, prop, receiver)
// since ServerResponse uses internal fields which
// proxy can't map correctly we need to ensure functions
// are bound correctly while being proxied
if (typeof value === 'function') {
return value.bind(obj)
}
return value
},
})
}
......
import Link from 'next/link'
import path from 'path'
import fs from 'fs'
import findUp from 'find-up'
export async function getServerSideProps() {
const text = fs
.readFileSync(
findUp.sync('world.txt', {
// prevent webpack from intercepting
// eslint-disable-next-line no-eval
cwd: eval(`__dirname`),
}),
'utf8'
)
.readFileSync(path.join(process.cwd(), 'world.txt'), 'utf8')
.trim()
return {
......
export function getServerSideProps({ res }) {
res.statusCode = 200
res.end('hello from gssp')
return {
props: {},
}
}
export default function Page(props) {
return <p>early request end</p>
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment