Skip to content

Commit c13a6b6

Browse files
committed
[Flight] Better compat with http.createServer
1 parent 62ef250 commit c13a6b6

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

packages/react-server/src/ReactServerHostConfigNode.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ export function flushBuffered(destination: Destination) {
2121
// If we don't have any more data to send right now.
2222
// Flush whatever is in the buffer to the wire.
2323
if (typeof destination.flush === 'function') {
24-
// By convention the Zlib streams provide a flush function for this purpose.
25-
destination.flush();
24+
// http.createServer response have flush(), but it has a different meaning and
25+
// is deprecated in favor of flushHeaders(). Detect to avoid a warning.
26+
if (typeof destination.flushHeaders !== 'function') {
27+
// By convention the Zlib streams provide a flush function for this purpose.
28+
destination.flush();
29+
}
2630
}
2731
}
2832

2933
export function beginWriting(destination: Destination) {
30-
destination.cork();
34+
// Older Node streams like http.createServer don't have this.
35+
if (typeof destination.cork === 'function') {
36+
destination.cork();
37+
}
3138
}
3239

3340
export function writeChunk(destination: Destination, buffer: Uint8Array) {
@@ -36,7 +43,10 @@ export function writeChunk(destination: Destination, buffer: Uint8Array) {
3643
}
3744

3845
export function completeWriting(destination: Destination) {
39-
destination.uncork();
46+
// Older Node streams like http.createServer don't have this.
47+
if (typeof destination.uncork === 'function') {
48+
destination.uncork();
49+
}
4050
}
4151

4252
export function close(destination: Destination) {

0 commit comments

Comments
 (0)