@@ -16,7 +16,6 @@ import {
1616 createRequest ,
1717 startWork ,
1818 startFlowing ,
19- stopFlowing ,
2019 abort ,
2120} from 'react-server/src/ReactFizzServer' ;
2221
@@ -25,56 +24,63 @@ import {
2524 createRootFormatContext ,
2625} from './ReactDOMServerFormatConfig' ;
2726
27+ type NextStreamSource = {
28+ start : ( controller : Destination ) => void ,
29+ pull : ( controller : Destination ) => void ,
30+ cancel : ( reason : mixed ) => void ,
31+ } ;
32+
2833type Options = { |
2934 identifierPrefix ? : string ,
3035 namespaceURI ? : string ,
36+ nonce ? : string ,
37+ bootstrapScriptContent ? : string ,
38+ bootstrapScripts ?: Array < string > ,
39+ bootstrapModules ?: Array < string > ,
3140 progressiveChunkSize ? : number ,
32- onReadyToStream ?: ( ) => void ,
41+ signal ? : AbortSignal ,
42+ onCompleteShell ?: ( ) => void ,
3343 onCompleteAll ?: ( ) => void ,
3444 onError ?: ( error : mixed ) => void ,
3545| } ;
3646
37- type Controls = { |
38- abort ( ) : void ,
39- update ( ) : void ,
40- | } ;
41-
42- function createRequestImpl (
47+ function renderToNextStream (
4348 children : ReactNodeList ,
44- destination : Destination ,
45- options : void | Options ,
46- ) {
47- return createRequest (
49+ options ?: Options ,
50+ ) : NextStreamSource {
51+ const request = createRequest (
4852 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+ ) ,
5160 createRootFormatContext ( options ? options . namespaceURI : undefined ) ,
5261 options ? options . progressiveChunkSize : undefined ,
5362 options ? options . onError : undefined ,
5463 options ? options . onCompleteAll : undefined ,
55- options ? options . onReadyToStream : undefined ,
64+ options ? options . onCompleteShell : undefined ,
5665 ) ;
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 = ( ) = > {
6869 abort ( request ) ;
70+ signal . removeEventListener ( 'abort' , listener ) ;
71+ } ;
72+ signal . addEventListener ( 'abort ', listener ) ;
73+ }
74+ const stream = {
75+ start ( controller ) {
76+ startWork ( request ) ;
6977 } ,
70- update ( ) {
71- if ( destination . ready ) {
72- startFlowing ( request ) ;
73- } else {
74- stopFlowing ( request ) ;
75- }
78+ pull ( controller ) {
79+ startFlowing ( request , controller ) ;
7680 } ,
81+ cancel ( reason ) { } ,
7782 } ;
83+ return stream ;
7884}
7985
8086export { renderToNextStream , ReactVersion as version } ;
0 commit comments