File tree 2 files changed +23
-19
lines changed
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
92
92
` ` ` ts
93
93
function renderToWebStream(
94
94
input: App | VNode,
95
- context?: SSRContext,
96
- Ctor?: { new (): ReadableStream }
95
+ context?: SSRContext
97
96
): ReadableStream
98
97
` ` `
99
98
Original file line number Diff line number Diff line change @@ -74,9 +74,7 @@ export function renderToSimpleStream<T extends SimpleReadable>(
74
74
75
75
Promise . resolve ( renderComponentVNode ( vnode ) )
76
76
. then ( buffer => unrollBuffer ( buffer , stream ) )
77
- . then ( ( ) => {
78
- stream . push ( null )
79
- } )
77
+ . then ( ( ) => stream . push ( null ) )
80
78
. catch ( error => {
81
79
stream . destroy ( error )
82
80
} )
@@ -180,20 +178,27 @@ export function pipeToWebWritable(
180
178
const writer = writable . getWriter ( )
181
179
const encoder = new TextEncoder ( )
182
180
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
196
191
}
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
+ }
198
203
} )
199
204
}
You can’t perform that action at this time.
0 commit comments