diff --git a/.changeset/moody-parents-breathe.md b/.changeset/moody-parents-breathe.md new file mode 100644 index 000000000000..2016c70fc88b --- /dev/null +++ b/.changeset/moody-parents-breathe.md @@ -0,0 +1,6 @@ +--- +'@modern-js/prod-server': patch +--- + +fix(prod-server): the server need use headersSent without use flushHeader +fix(prod-server): 没有 flushHeader 时 server 应该使用 headersSent diff --git a/packages/server/prod-server/src/libs/preload/flushServerHeader.ts b/packages/server/prod-server/src/libs/preload/flushServerHeader.ts index 84c769a54ae6..6e0790725900 100644 --- a/packages/server/prod-server/src/libs/preload/flushServerHeader.ts +++ b/packages/server/prod-server/src/libs/preload/flushServerHeader.ts @@ -37,4 +37,5 @@ export async function flushServerHeader({ } res.flushHeaders(); + res.modernFlushedHeaders = true; } diff --git a/packages/server/prod-server/src/server/modernServer.ts b/packages/server/prod-server/src/server/modernServer.ts index f6967f45f0eb..830f88ef7d16 100644 --- a/packages/server/prod-server/src/server/modernServer.ts +++ b/packages/server/prod-server/src/server/modernServer.ts @@ -635,7 +635,11 @@ export class ModernServer implements ModernServerInterface { private isSend(res: ServerResponse) { /// Is true after response.end() has been called. - if (res.writableEnded) { + if (res.modernFlushedHeaders) { + if (res.writableFinished) { + return true; + } + } else if (res.headersSent) { return true; } diff --git a/packages/server/prod-server/src/type.ts b/packages/server/prod-server/src/type.ts index bd80f7c1abfa..154fb5711afd 100644 --- a/packages/server/prod-server/src/type.ts +++ b/packages/server/prod-server/src/type.ts @@ -21,6 +21,7 @@ declare module 'http' { interface OutgoingMessage { set: (key: string, value: any) => this; + modernFlushedHeaders?: boolean; } }