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 @@ -166,6 +166,34 @@ describe('ReactFlight', () => {
166
166
expect ( ReactNoop ) . toMatchRenderedOutput ( < span > Hello, Seb Smith</ span > ) ;
167
167
} ) ;
168
168
169
+ it ( 'can render an iterable as an array' , async ( ) => {
170
+ function ItemListClient ( props ) {
171
+ return < span > { props . items } </ span > ;
172
+ }
173
+ const ItemList = clientReference ( ItemListClient ) ;
174
+
175
+ function Items ( ) {
176
+ const iterable = {
177
+ [ Symbol . iterator ] : function * ( ) {
178
+ yield 'A' ;
179
+ yield 'B' ;
180
+ yield 'C' ;
181
+ } ,
182
+ } ;
183
+ return < ItemList items = { iterable } /> ;
184
+ }
185
+
186
+ const model = < Items /> ;
187
+
188
+ const transport = ReactNoopFlightServer . render ( model ) ;
189
+
190
+ await act ( async ( ) => {
191
+ ReactNoop . render ( await ReactNoopFlightClient . read ( transport ) ) ;
192
+ } ) ;
193
+
194
+ expect ( ReactNoop ) . toMatchRenderedOutput ( < span > ABC</ span > ) ;
195
+ } ) ;
196
+
169
197
it ( 'can render a lazy component as a shared component on the server' , async ( ) => {
170
198
function SharedComponent ( { text} ) {
171
199
return (
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ import {
73
73
} from './ReactFlightNewContext' ;
74
74
75
75
import {
76
+ getIteratorFn ,
76
77
REACT_ELEMENT_TYPE ,
77
78
REACT_FORWARD_REF_TYPE ,
78
79
REACT_FRAGMENT_TYPE ,
@@ -1053,6 +1054,12 @@ export function resolveModelToJSON(
1053
1054
}
1054
1055
return ( undefined : any ) ;
1055
1056
}
1057
+ if ( ! isArray ( value ) ) {
1058
+ const iteratorFn = getIteratorFn ( value ) ;
1059
+ if ( iteratorFn ) {
1060
+ return Array . from ( ( value : any ) ) ;
1061
+ }
1062
+ }
1056
1063
1057
1064
if ( __DEV__ ) {
1058
1065
if ( value !== null && ! isArray ( value ) ) {
You can’t perform that action at this time.
0 commit comments