File tree Expand file tree Collapse file tree 2 files changed +23
-19
lines changed Expand file tree Collapse file tree 2 files changed +23
-19
lines changed Original file line number Diff line number Diff line change @@ -92,8 +92,7 @@ Renders input as a [Web ReadableStream](https://developer.mozilla.org/en-US/docs
9292` ` ` ts
9393function renderToWebStream(
9494 input: App | VNode,
95- context?: SSRContext,
96- Ctor?: { new (): ReadableStream }
95+ context?: SSRContext
9796): ReadableStream
9897` ` `
9998
Original file line number Diff line number Diff line change @@ -74,9 +74,7 @@ export function renderToSimpleStream<T extends SimpleReadable>(
7474
7575 Promise . resolve ( renderComponentVNode ( vnode ) )
7676 . then ( buffer => unrollBuffer ( buffer , stream ) )
77- . then ( ( ) => {
78- stream . push ( null )
79- } )
77+ . then ( ( ) => stream . push ( null ) )
8078 . catch ( error => {
8179 stream . destroy ( error )
8280 } )
@@ -180,20 +178,27 @@ export function pipeToWebWritable(
180178 const writer = writable . getWriter ( )
181179 const encoder = new TextEncoder ( )
182180
183- writer . ready . then ( ( ) => {
184- renderToSimpleStream ( input , context , {
185- push ( content ) {
186- if ( content != null ) {
187- writer . write ( encoder . encode ( content ) )
188- } else {
189- writer . close ( )
190- }
191- } ,
192- destroy ( err ) {
193- // TODO better error handling?
194- console . log ( err )
195- writer . close ( )
181+ // #4287 CloudFlare workers do not implement `ready` property
182+ let hasReady = false
183+ try {
184+ hasReady = isPromise ( writer . ready )
185+ } catch ( e ) { }
186+
187+ renderToSimpleStream ( input , context , {
188+ async push ( content ) {
189+ if ( hasReady ) {
190+ await writer . ready
196191 }
197- } )
192+ if ( content != null ) {
193+ return writer . write ( encoder . encode ( content ) )
194+ } else {
195+ return writer . close ( )
196+ }
197+ } ,
198+ destroy ( err ) {
199+ // TODO better error handling?
200+ console . log ( err )
201+ writer . close ( )
202+ }
198203 } )
199204}
You can’t perform that action at this time.
0 commit comments