@@ -119,6 +119,15 @@ export function createRequest( |
119 | 119 | function attemptResolveElement(element: React$Element<any>): ReactModel { |
120 | 120 | const type = element.type; |
121 | 121 | const props = element.props; |
| 122 | + if (element.ref !== null && element.ref !== undefined) { |
| 123 | + // When the ref moves to the regular props object this will implicitly |
| 124 | + // throw for functions. We could probably relax it to a DEV warning for other |
| 125 | + // cases. |
| 126 | + invariant( |
| 127 | + false, |
| 128 | + 'Refs cannot be used in server components, nor passed to client components.', |
| 129 | + ); |
| 130 | + } |
122 | 131 | if (typeof type === 'function') { |
123 | 132 | // This is a server-side component. |
124 | 133 | return type(props); |
@@ -153,7 +162,11 @@ function attemptResolveElement(element: React$Element<any>): ReactModel { |
153 | 162 | } |
154 | 163 | } |
155 | 164 | } |
156 | | - invariant(false, 'Unsupported type.'); |
| 165 | + invariant( |
| 166 | + false, |
| 167 | + 'Unsupported server component type: %s', |
| 168 | + describeValueForErrorMessage(type), |
| 169 | + ); |
157 | 170 | } |
158 | 171 |
|
159 | 172 | function pingSegment(request: Request, segment: Segment): void { |
@@ -218,7 +231,19 @@ function isSimpleObject(object): boolean { |
218 | 231 | const names = Object.getOwnPropertyNames(object); |
219 | 232 | for (let i = 0; i < names.length; i++) { |
220 | 233 | const descriptor = Object.getOwnPropertyDescriptor(object, names[i]); |
221 | | - if (!descriptor || !descriptor.enumerable) { |
| 234 | + if (!descriptor) { |
| 235 | + return false; |
| 236 | + } |
| 237 | + if (!descriptor.enumerable) { |
| 238 | + if ( |
| 239 | + (names[i] === 'key' || names[i] === 'ref') && |
| 240 | + typeof descriptor.get === 'function' |
| 241 | + ) { |
| 242 | + // React adds key and ref getters to props objects to issue warnings. |
| 243 | + // Those getters will not be transferred to the client, but that's ok, |
| 244 | + // so we'll special case them. |
| 245 | + continue; |
| 246 | + } |
222 | 247 | return false; |
223 | 248 | } |
224 | 249 | } |
@@ -249,7 +274,7 @@ function describeValueForErrorMessage(value: ReactModel): string { |
249 | 274 | return '[...]'; |
250 | 275 | } |
251 | 276 | const name = objectName(value); |
252 | | - if (name === '[object Object]') { |
| 277 | + if (name === 'Object') { |
253 | 278 | return '{...}'; |
254 | 279 | } |
255 | 280 | return name; |
@@ -266,6 +291,7 @@ function describeObjectForErrorMessage( |
266 | 291 | objectOrArray: |
267 | 292 | | {+[key: string | number]: ReactModel} |
268 | 293 | | $ReadOnlyArray<ReactModel>, |
| 294 | + expandedName?: string, |
269 | 295 | ): string { |
270 | 296 | if (isArray(objectOrArray)) { |
271 | 297 | let str = '['; |
@@ -279,7 +305,16 @@ function describeObjectForErrorMessage( |
279 | 305 | str += '...'; |
280 | 306 | break; |
281 | 307 | } |
282 | | - str += describeValueForErrorMessage(array[i]); |
| 308 | + const value = array[i]; |
| 309 | + if ( |
| 310 | + '' + i === expandedName && |
| 311 | + typeof value === 'object' && |
| 312 | + value !== null |
| 313 | + ) { |
| 314 | + str += describeObjectForErrorMessage(value); |
| 315 | + } else { |
| 316 | + str += describeValueForErrorMessage(value); |
| 317 | + } |
283 | 318 | } |
284 | 319 | str += ']'; |
285 | 320 | return str; |
@@ -297,10 +332,17 @@ function describeObjectForErrorMessage( |
297 | 332 | break; |
298 | 333 | } |
299 | 334 | const name = names[i]; |
300 | | - str += |
301 | | - describeKeyForErrorMessage(name) + |
302 | | - ': ' + |
303 | | - describeValueForErrorMessage(object[name]); |
| 335 | + str += describeKeyForErrorMessage(name) + ': '; |
| 336 | + const value = object[name]; |
| 337 | + if ( |
| 338 | + name === expandedName && |
| 339 | + typeof value === 'object' && |
| 340 | + value !== null |
| 341 | + ) { |
| 342 | + str += describeObjectForErrorMessage(value); |
| 343 | + } else { |
| 344 | + str += describeValueForErrorMessage(value); |
| 345 | + } |
304 | 346 | } |
305 | 347 | str += '}'; |
306 | 348 | return str; |
@@ -444,7 +486,7 @@ export function resolveModelToJSON( |
444 | 486 | 'Classes or other objects with methods are not supported. ' + |
445 | 487 | 'Remove %s from these props: %s', |
446 | 488 | describeKeyForErrorMessage(key), |
447 | | - describeObjectForErrorMessage(parent), |
| 489 | + describeObjectForErrorMessage(parent, key), |
448 | 490 | ); |
449 | 491 | } else if (Object.getOwnPropertySymbols) { |
450 | 492 | const symbols = Object.getOwnPropertySymbols(value); |
@@ -455,7 +497,7 @@ export function resolveModelToJSON( |
455 | 497 | 'Remove %s from these props: %s', |
456 | 498 | symbols[0].description, |
457 | 499 | describeKeyForErrorMessage(key), |
458 | | - describeObjectForErrorMessage(parent), |
| 500 | + describeObjectForErrorMessage(parent, key), |
459 | 501 | ); |
460 | 502 | } |
461 | 503 | } |
|