From 9feb4aa0be8064d2aed8c08d68cf957b91205f80 Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Tue, 1 Jun 2021 13:32:16 +0800 Subject: [PATCH] fix(ssr/renderToStream): A Readable object should at least implement an empty _read method. Nor it will throw errors. See https://github.com/nodejs/node/issues/38865. The tests passes in jest before because jest mock the global promise and causes inconsistant behavior compared with native nodejs. https://github.com/facebook/jest/issues/11497 --- packages/server-renderer/src/renderToStream.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/server-renderer/src/renderToStream.ts b/packages/server-renderer/src/renderToStream.ts index 4952b51c267..cf0c3debb74 100644 --- a/packages/server-renderer/src/renderToStream.ts +++ b/packages/server-renderer/src/renderToStream.ts @@ -47,6 +47,10 @@ function unrollBufferSync(buffer: SSRBuffer, stream: Readable) { } } +class PushSafeReadable extends Readable { + _read() {} +} + export function renderToStream( input: App | VNode, context: SSRContext = {} @@ -62,7 +66,7 @@ export function renderToStream( // provide the ssr context to the tree input.provide(ssrContextKey, context) - const stream = new Readable() + const stream = new PushSafeReadable() Promise.resolve(renderComponentVNode(vnode)) .then(buffer => unrollBuffer(buffer, stream))