@@ -16,7 +16,6 @@ import {
16
16
createRequest ,
17
17
startWork ,
18
18
startFlowing ,
19
- stopFlowing ,
20
19
abort ,
21
20
} from 'react-server/src/ReactFizzServer' ;
22
21
@@ -25,56 +24,63 @@ import {
25
24
createRootFormatContext ,
26
25
} from './ReactDOMServerFormatConfig' ;
27
26
27
+ type NextStreamSource = {
28
+ start : ( controller : Destination ) => void ,
29
+ pull : ( controller : Destination ) => void ,
30
+ cancel : ( reason : mixed ) => void ,
31
+ } ;
32
+
28
33
type Options = { |
29
34
identifierPrefix ? : string ,
30
35
namespaceURI ? : string ,
36
+ nonce ? : string ,
37
+ bootstrapScriptContent ? : string ,
38
+ bootstrapScripts ?: Array < string > ,
39
+ bootstrapModules ?: Array < string > ,
31
40
progressiveChunkSize ? : number ,
32
- onReadyToStream ?: ( ) => void ,
41
+ signal ? : AbortSignal ,
42
+ onCompleteShell ?: ( ) => void ,
33
43
onCompleteAll ?: ( ) => void ,
34
44
onError ?: ( error : mixed ) => void ,
35
45
| } ;
36
46
37
- type Controls = { |
38
- abort ( ) : void ,
39
- update ( ) : void ,
40
- | } ;
41
-
42
- function createRequestImpl (
47
+ function renderToNextStream (
43
48
children : ReactNodeList ,
44
- destination : Destination ,
45
- options : void | Options ,
46
- ) {
47
- return createRequest (
49
+ options ?: Options ,
50
+ ) : NextStreamSource {
51
+ const request = createRequest (
48
52
children ,
49
- destination ,
50
- createResponseState ( options ? options . identifierPrefix : undefined ) ,
53
+ createResponseState (
54
+ options ? options . identifierPrefix : undefined ,
55
+ options ? options . nonce : undefined ,
56
+ options ? options . bootstrapScriptContent : undefined ,
57
+ options ? options . bootstrapScripts : undefined ,
58
+ options ? options . bootstrapModules : undefined ,
59
+ ) ,
51
60
createRootFormatContext ( options ? options . namespaceURI : undefined ) ,
52
61
options ? options . progressiveChunkSize : undefined ,
53
62
options ? options . onError : undefined ,
54
63
options ? options . onCompleteAll : undefined ,
55
- options ? options . onReadyToStream : undefined ,
64
+ options ? options . onCompleteShell : undefined ,
56
65
) ;
57
- }
58
-
59
- function renderToNextStream (
60
- children : ReactNodeList ,
61
- destination : Destination ,
62
- options ?: Options ,
63
- ) : Controls {
64
- const request = createRequestImpl ( children , destination , options ) ;
65
- startWork ( request ) ;
66
- return {
67
- abort ( ) {
66
+ if ( options && options . signal ) {
67
+ const signal = options . signal ;
68
+ const listener = ( ) = > {
68
69
abort ( request ) ;
70
+ signal . removeEventListener ( 'abort' , listener ) ;
71
+ } ;
72
+ signal . addEventListener ( 'abort ', listener ) ;
73
+ }
74
+ const stream = {
75
+ start ( controller ) {
76
+ startWork ( request ) ;
69
77
} ,
70
- update ( ) {
71
- if ( destination . ready ) {
72
- startFlowing ( request ) ;
73
- } else {
74
- stopFlowing ( request ) ;
75
- }
78
+ pull ( controller ) {
79
+ startFlowing ( request , controller ) ;
76
80
} ,
81
+ cancel ( reason ) { } ,
77
82
} ;
83
+ return stream ;
78
84
}
79
85
80
86
export { renderToNextStream , ReactVersion as version } ;
0 commit comments