@@ -20,6 +20,7 @@ import {enableProfilerTimer} from 'shared/ReactFeatureFlags';
2020import { OMITTED_PROP_ERROR } from './ReactFlightPropertyAccess' ;
2121
2222import hasOwnProperty from 'shared/hasOwnProperty' ;
23+ import isArray from 'shared/isArray' ;
2324
2425const supportsUserTiming =
2526 enableProfilerTimer &&
@@ -32,20 +33,39 @@ const supportsUserTiming =
3233const IO_TRACK = 'Server Requests ⚛' ;
3334const COMPONENTS_TRACK = 'Server Components ⚛' ;
3435
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 ;
3642 for ( let i = 0 ; i < array . length ; i ++ ) {
3743 const value = array [ i ] ;
3844 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 ;
4666 }
4767 }
48- return true ;
68+ return kind ;
4969}
5070
5171function addObjectToProperties (
@@ -77,9 +97,20 @@ function addValueToProperties(
7797 // $FlowFixMe[method-unbinding]
7898 const objectToString = Object . prototype . toString . call ( value ) ;
7999 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+ }
83114 }
84115 properties . push ( [
85116 '\xa0\xa0' . repeat ( indent ) + propertyName ,
0 commit comments