Skip to content

Commit 9d10885

Browse files
committed
Support REACT_LEGACY_ELEMENT_TYPE for formatting JSX
DevTools shouldn't use react-is since that's versioned to one version of React. We don't need to since we use all the symbols from shared/ReactSymbols anyway and have a fork of typeOf that can cover both.
1 parent e831c23 commit 9d10885

File tree

1 file changed

+24
-33
lines changed
  • packages/react-devtools-shared/src

1 file changed

+24
-33
lines changed

packages/react-devtools-shared/src/utils.js

+24-33
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,22 @@
88
*/
99

1010
import LRU from 'lru-cache';
11-
import {
12-
isElement,
13-
typeOf,
14-
ContextConsumer,
15-
ContextProvider,
16-
ForwardRef,
17-
Fragment,
18-
Lazy,
19-
Memo,
20-
Portal,
21-
Profiler,
22-
StrictMode,
23-
Suspense,
24-
} from 'react-is';
2511
import {
2612
REACT_CONSUMER_TYPE,
2713
REACT_CONTEXT_TYPE,
2814
REACT_FORWARD_REF_TYPE,
2915
REACT_FRAGMENT_TYPE,
3016
REACT_LAZY_TYPE,
17+
REACT_ELEMENT_TYPE,
3118
REACT_LEGACY_ELEMENT_TYPE,
3219
REACT_MEMO_TYPE,
3320
REACT_PORTAL_TYPE,
3421
REACT_PROFILER_TYPE,
3522
REACT_PROVIDER_TYPE,
3623
REACT_STRICT_MODE_TYPE,
3724
REACT_SUSPENSE_LIST_TYPE,
38-
REACT_SUSPENSE_LIST_TYPE as SuspenseList,
3925
REACT_SUSPENSE_TYPE,
40-
REACT_TRACING_MARKER_TYPE as TracingMarker,
26+
REACT_TRACING_MARKER_TYPE,
4127
} from 'shared/ReactSymbols';
4228
import {enableRenderableContext} from 'shared/ReactFeatureFlags';
4329
import {
@@ -632,10 +618,6 @@ export function getDataType(data: Object): DataType {
632618
return 'undefined';
633619
}
634620

635-
if (isElement(data)) {
636-
return 'react_element';
637-
}
638-
639621
if (typeof HTMLElement !== 'undefined' && data instanceof HTMLElement) {
640622
return 'html_element';
641623
}
@@ -657,6 +639,12 @@ export function getDataType(data: Object): DataType {
657639
return 'number';
658640
}
659641
case 'object':
642+
if (
643+
data.$$typeof === REACT_ELEMENT_TYPE ||
644+
data.$$typeof === REACT_LEGACY_ELEMENT_TYPE
645+
) {
646+
return 'react_element';
647+
}
660648
if (isArray(data)) {
661649
return 'array';
662650
} else if (ArrayBuffer.isView(data)) {
@@ -717,6 +705,7 @@ function typeOfWithLegacyElementSymbol(object: any): mixed {
717705
if (typeof object === 'object' && object !== null) {
718706
const $$typeof = object.$$typeof;
719707
switch ($$typeof) {
708+
case REACT_ELEMENT_TYPE:
720709
case REACT_LEGACY_ELEMENT_TYPE:
721710
const type = object.type;
722711

@@ -761,31 +750,33 @@ function typeOfWithLegacyElementSymbol(object: any): mixed {
761750
export function getDisplayNameForReactElement(
762751
element: React$Element<any>,
763752
): string | null {
764-
const elementType = typeOf(element) || typeOfWithLegacyElementSymbol(element);
753+
const elementType = typeOfWithLegacyElementSymbol(element);
765754
switch (elementType) {
766-
case ContextConsumer:
755+
case REACT_CONSUMER_TYPE:
767756
return 'ContextConsumer';
768-
case ContextProvider:
757+
case REACT_PROVIDER_TYPE:
769758
return 'ContextProvider';
770-
case ForwardRef:
759+
case REACT_CONTEXT_TYPE:
760+
return 'Context';
761+
case REACT_FORWARD_REF_TYPE:
771762
return 'ForwardRef';
772-
case Fragment:
763+
case REACT_FRAGMENT_TYPE:
773764
return 'Fragment';
774-
case Lazy:
765+
case REACT_LAZY_TYPE:
775766
return 'Lazy';
776-
case Memo:
767+
case REACT_MEMO_TYPE:
777768
return 'Memo';
778-
case Portal:
769+
case REACT_PORTAL_TYPE:
779770
return 'Portal';
780-
case Profiler:
771+
case REACT_PROFILER_TYPE:
781772
return 'Profiler';
782-
case StrictMode:
773+
case REACT_STRICT_MODE_TYPE:
783774
return 'StrictMode';
784-
case Suspense:
775+
case REACT_SUSPENSE_TYPE:
785776
return 'Suspense';
786-
case SuspenseList:
777+
case REACT_SUSPENSE_LIST_TYPE:
787778
return 'SuspenseList';
788-
case TracingMarker:
779+
case REACT_TRACING_MARKER_TYPE:
789780
return 'TracingMarker';
790781
default:
791782
const {type} = element;

0 commit comments

Comments
 (0)