@@ -39,7 +39,6 @@ import {
39
39
REACT_MEMO_TYPE ,
40
40
} from 'shared/ReactSymbols' ;
41
41
42
- import * as React from 'react' ;
43
42
import ReactSharedInternals from 'shared/ReactSharedInternals' ;
44
43
import invariant from 'shared/invariant' ;
45
44
@@ -111,10 +110,13 @@ export function createRequest(
111
110
return request ;
112
111
}
113
112
114
- function attemptResolveElement ( element : React$Element < any > ) : ReactModel {
115
- const type = element . type ;
116
- const props = element . props ;
117
- if ( element . ref !== null && element . ref !== undefined ) {
113
+ function attemptResolveElement (
114
+ type : any ,
115
+ key : null | React$Key ,
116
+ ref : mixed ,
117
+ props : any ,
118
+ ) : ReactModel {
119
+ if ( ref !== null && ref !== undefined ) {
118
120
// When the ref moves to the regular props object this will implicitly
119
121
// throw for functions. We could probably relax it to a DEV warning for other
120
122
// cases.
@@ -128,31 +130,30 @@ function attemptResolveElement(element: React$Element<any>): ReactModel {
128
130
return type ( props ) ;
129
131
} else if ( typeof type === 'string' ) {
130
132
// This is a host element. E.g. HTML.
131
- return [ REACT_ELEMENT_TYPE , type , element . key , element . props ] ;
133
+ return [ REACT_ELEMENT_TYPE , type , key , props ] ;
132
134
} else if ( typeof type === 'symbol' ) {
133
135
if ( type === REACT_FRAGMENT_TYPE ) {
134
136
// For key-less fragments, we add a small optimization to avoid serializing
135
137
// it as a wrapper.
136
138
// TODO: If a key is specified, we should propagate its key to any children.
137
139
// Same as if a server component has a key.
138
- return element . props . children ;
140
+ return props . children ;
139
141
}
140
142
// This might be a built-in React component. We'll let the client decide.
141
143
// Any built-in works as long as its props are serializable.
142
- return [ REACT_ELEMENT_TYPE , type, element . key , element . props ] ;
144
+ return [ REACT_ELEMENT_TYPE , type , key , props ] ;
143
145
} else if ( type != null && typeof type === 'object' ) {
144
146
if ( isModuleReference ( type ) ) {
145
147
// This is a reference to a client component.
146
- return [ REACT_ELEMENT_TYPE , type , element . key , element . props ] ;
148
+ return [ REACT_ELEMENT_TYPE , type , key , props ] ;
147
149
}
148
150
switch ( type . $$typeof ) {
149
151
case REACT_FORWARD_REF_TYPE : {
150
152
const render = type . render ;
151
153
return render ( props , undefined ) ;
152
154
}
153
155
case REACT_MEMO_TYPE : {
154
- const nextChildren = React . createElement ( type . type , element . props ) ;
155
- return attemptResolveElement ( nextChildren ) ;
156
+ return attemptResolveElement ( type . type , key , ref , props ) ;
156
157
}
157
158
}
158
159
}
@@ -389,7 +390,12 @@ export function resolveModelToJSON(
389
390
const element : React$Element < any > = (value: any);
390
391
try {
391
392
// Attempt to render the server component.
392
- value = attemptResolveElement ( element ) ;
393
+ value = attemptResolveElement (
394
+ element . type ,
395
+ element . key ,
396
+ element . ref ,
397
+ element . props ,
398
+ ) ;
393
399
} catch (x) {
394
400
if ( typeof x === 'object' && x !== null && typeof x . then === 'function' ) {
395
401
// Something suspended, we'll need to create a new segment and resolve it later.
@@ -600,7 +606,12 @@ function retrySegment(request: Request, segment: Segment): void {
600
606
// Doing this here lets us reuse this same segment if the next component
601
607
// also suspends.
602
608
segment . query = ( ) => value ;
603
- value = attemptResolveElement ( element ) ;
609
+ value = attemptResolveElement (
610
+ element . type ,
611
+ element . key ,
612
+ element . ref ,
613
+ element . props ,
614
+ ) ;
604
615
}
605
616
const processedChunk = processModelChunk ( request , segment . id , value ) ;
606
617
request . completedJSONChunks . push ( processedChunk ) ;
0 commit comments