@@ -20,6 +20,7 @@ import {enableProfilerTimer} from 'shared/ReactFeatureFlags';
20
20
import { OMITTED_PROP_ERROR } from './ReactFlightPropertyAccess' ;
21
21
22
22
import hasOwnProperty from 'shared/hasOwnProperty' ;
23
+ import isArray from 'shared/isArray' ;
23
24
24
25
const supportsUserTiming =
25
26
enableProfilerTimer &&
@@ -32,20 +33,39 @@ const supportsUserTiming =
32
33
const IO_TRACK = 'Server Requests ⚛' ;
33
34
const COMPONENTS_TRACK = 'Server Components ⚛' ;
34
35
35
- function isPrimitiveArray ( array : Object ) {
36
+ const EMPTY_ARRAY = 0 ;
37
+ const COMPLEX_ARRAY = 1 ;
38
+ const PRIMITIVE_ARRAY = 2 ; // Primitive values only
39
+ const ENTRIES_ARRAY = 3 ; // Tuple arrays of string and value (like Headers, Map, etc)
40
+ function getArrayKind ( array : Object ) : 0 | 1 | 2 | 3 {
41
+ let kind = EMPTY_ARRAY ;
36
42
for ( let i = 0 ; i < array . length ; i ++ ) {
37
43
const value = array [ i ] ;
38
44
if ( typeof value === 'object' && value !== null ) {
39
- return false ;
40
- }
41
- if ( typeof value === 'function' ) {
42
- return false ;
43
- }
44
- if ( typeof value === 'string' && value . length > 50 ) {
45
- return false ;
45
+ if (
46
+ isArray ( value ) &&
47
+ value . length === 2 &&
48
+ typeof value [ 0 ] === 'string'
49
+ ) {
50
+ // Key value tuple
51
+ if ( kind !== EMPTY_ARRAY && kind !== ENTRIES_ARRAY ) {
52
+ return COMPLEX_ARRAY ;
53
+ }
54
+ kind = ENTRIES_ARRAY ;
55
+ } else {
56
+ return COMPLEX_ARRAY ;
57
+ }
58
+ } else if ( typeof value === 'function' ) {
59
+ return COMPLEX_ARRAY ;
60
+ } else if ( typeof value === 'string' && value . length > 50 ) {
61
+ return COMPLEX_ARRAY ;
62
+ } else if ( kind !== EMPTY_ARRAY && kind !== PRIMITIVE_ARRAY ) {
63
+ return COMPLEX_ARRAY ;
64
+ } else {
65
+ kind = PRIMITIVE_ARRAY ;
46
66
}
47
67
}
48
- return true ;
68
+ return kind ;
49
69
}
50
70
51
71
function addObjectToProperties (
@@ -77,9 +97,20 @@ function addValueToProperties(
77
97
// $FlowFixMe[method-unbinding]
78
98
const objectToString = Object . prototype . toString . call ( value ) ;
79
99
const objectName = objectToString . slice ( 8 , objectToString . length - 1 ) ;
80
- if ( objectName === 'Array' && isPrimitiveArray ( value ) ) {
81
- desc = JSON . stringify ( value ) ;
82
- break ;
100
+ if ( objectName === 'Array' ) {
101
+ const array : Array < any > = (value: any);
102
+ const kind = getArrayKind(array);
103
+ if (kind === PRIMITIVE_ARRAY || kind === EMPTY_ARRAY) {
104
+ desc = JSON . stringify ( array ) ;
105
+ break ;
106
+ } else if (kind === ENTRIES_ARRAY) {
107
+ properties . push ( [ '\xa0\xa0' . repeat ( indent ) + propertyName , '' ] ) ;
108
+ for ( let i = 0 ; i < array . length ; i ++ ) {
109
+ const entry = array [ i ] ;
110
+ addValueToProperties ( entry [ 0 ] , entry [ 1 ] , properties , indent + 1 ) ;
111
+ }
112
+ return;
113
+ }
83
114
}
84
115
properties . push ( [
85
116
'\xa0\xa0' . repeat ( indent ) + propertyName ,
0 commit comments