File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
react-client/src/__tests__ Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,34 @@ describe('ReactFlight', () => {
169169 expect ( ReactNoop ) . toMatchRenderedOutput ( < span > Hello, Seb Smith</ span > ) ;
170170 } ) ;
171171
172+ it ( 'can render an iterable as an array' , async ( ) => {
173+ function ItemListClient ( props ) {
174+ return < span > { props . items } </ span > ;
175+ }
176+ const ItemList = clientReference ( ItemListClient ) ;
177+
178+ function Items ( ) {
179+ const iterable = {
180+ [ Symbol . iterator ] : function * ( ) {
181+ yield 'A' ;
182+ yield 'B' ;
183+ yield 'C' ;
184+ } ,
185+ } ;
186+ return < ItemList items = { iterable } /> ;
187+ }
188+
189+ const model = < Items /> ;
190+
191+ const transport = ReactNoopFlightServer . render ( model ) ;
192+
193+ await act ( async ( ) => {
194+ ReactNoop . render ( await ReactNoopFlightClient . read ( transport ) ) ;
195+ } ) ;
196+
197+ expect ( ReactNoop ) . toMatchRenderedOutput ( < span > ABC</ span > ) ;
198+ } ) ;
199+
172200 it ( 'can render a lazy component as a shared component on the server' , async ( ) => {
173201 function SharedComponent ( { text} ) {
174202 return (
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ import {
7373} from './ReactFlightNewContext' ;
7474
7575import {
76+ getIteratorFn ,
7677 REACT_ELEMENT_TYPE ,
7778 REACT_FORWARD_REF_TYPE ,
7879 REACT_FRAGMENT_TYPE ,
@@ -1059,6 +1060,12 @@ export function resolveModelToJSON(
10591060 }
10601061 return ( undefined : any ) ;
10611062 }
1063+ if ( ! isArray ( value ) ) {
1064+ const iteratorFn = getIteratorFn ( value ) ;
1065+ if ( iteratorFn ) {
1066+ return Array . from ( ( value : any ) ) ;
1067+ }
1068+ }
10621069
10631070 if ( __DEV__ ) {
10641071 if ( value !== null && ! isArray ( value ) ) {
You can’t perform that action at this time.
0 commit comments