|
1 | 1 | /**
|
2 |
| - * Core logic copy from https://github.com/facebook/react/blob/28625c6f45423e6edc5ca0e2932281769c0d431e/packages/shared/getComponentNameFromType.js |
| 2 | + * Reference from https://github.com/facebook/react/blob/28625c6f45423e6edc5ca0e2932281769c0d431e/packages/shared/getComponentNameFromType.js |
3 | 3 | *
|
4 | 4 | * @flow
|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | import type { LazyComponent, ReactContext, ReactProviderType } from 'react';
|
8 |
| - |
| 8 | +import { Fragment } from 'react'; |
9 | 9 | import {
|
10 |
| - REACT_CONTEXT_TYPE, |
11 |
| - REACT_FORWARD_REF_TYPE, |
12 |
| - REACT_FRAGMENT_TYPE, |
13 |
| - REACT_PORTAL_TYPE, |
14 |
| - REACT_MEMO_TYPE, |
15 |
| - REACT_PROFILER_TYPE, |
16 |
| - REACT_PROVIDER_TYPE, |
17 |
| - REACT_STRICT_MODE_TYPE, |
18 |
| - REACT_SUSPENSE_TYPE, |
19 |
| - REACT_SUSPENSE_LIST_TYPE, |
20 |
| - REACT_LAZY_TYPE, |
21 |
| - REACT_CACHE_TYPE, |
22 |
| -} from './ReactSymbols'; |
| 10 | + ContextConsumer, |
| 11 | + ContextProvider, |
| 12 | + Element, |
| 13 | + ForwardRef, |
| 14 | + Portal, |
| 15 | + Memo, |
| 16 | + Profiler, |
| 17 | + StrictMode, |
| 18 | + Suspense, |
| 19 | + SuspenseList, |
| 20 | + Lazy, |
| 21 | +} from 'react-is'; |
23 | 22 |
|
24 | 23 | // Keep in sync with react-reconciler/getComponentNameFromFiber
|
25 | 24 | function getWrappedName(
|
@@ -55,47 +54,42 @@ function getComponentNameFromType(type: mixed): string | null {
|
55 | 54 | }
|
56 | 55 | // eslint-disable-next-line default-case
|
57 | 56 | switch (type) {
|
58 |
| - case REACT_FRAGMENT_TYPE: |
| 57 | + case Fragment: |
59 | 58 | return 'Fragment';
|
60 |
| - case REACT_PORTAL_TYPE: |
| 59 | + case Portal: |
61 | 60 | return 'Portal';
|
62 |
| - case REACT_PROFILER_TYPE: |
| 61 | + case Profiler: |
63 | 62 | return 'Profiler';
|
64 |
| - case REACT_STRICT_MODE_TYPE: |
| 63 | + case StrictMode: |
65 | 64 | return 'StrictMode';
|
66 |
| - case REACT_SUSPENSE_TYPE: |
| 65 | + case Suspense: |
67 | 66 | return 'Suspense';
|
68 |
| - case REACT_SUSPENSE_LIST_TYPE: |
| 67 | + case SuspenseList: |
69 | 68 | return 'SuspenseList';
|
70 |
| - case REACT_CACHE_TYPE: |
71 |
| - return 'Cache'; |
| 69 | + // case REACT_CACHE_TYPE: |
| 70 | + // return 'Cache'; |
72 | 71 | }
|
73 | 72 | if (typeof type === 'object') {
|
74 | 73 | // eslint-disable-next-line default-case
|
75 | 74 | switch (type.$$typeof) {
|
76 |
| - case REACT_CONTEXT_TYPE: |
77 |
| - // eslint-disable-next-line no-case-declarations |
78 |
| - const context: ReactContext<any> = (type: any); |
| 75 | + case ContextConsumer: |
79 | 76 | /**
|
80 | 77 | * in DEV, should get context from `_context`.
|
81 | 78 | * https://github.com/facebook/react/blob/e16d61c3000e2de6217d06b9afad162e883f73c4/packages/react/src/ReactContext.js#L44-L125
|
82 | 79 | */
|
83 |
| - return `${getContextName(context._context ?? context)}.Consumer`; |
84 |
| - case REACT_PROVIDER_TYPE: |
85 |
| - // eslint-disable-next-line no-case-declarations |
86 |
| - const provider: ReactProviderType<any> = (type: any); |
87 |
| - return `${getContextName(provider._context)}.Provider`; |
88 |
| - case REACT_FORWARD_REF_TYPE: |
| 80 | + return `${getContextName(type._context ?? type)}.Consumer`; |
| 81 | + case ContextProvider: |
| 82 | + return `${getContextName(type._context)}.Provider`; |
| 83 | + case ForwardRef: |
89 | 84 | // eslint-disable-next-line no-case-declarations
|
90 | 85 | return getWrappedName(type, type.render, 'ForwardRef');
|
91 |
| - case REACT_MEMO_TYPE: |
92 |
| - // eslint-disable-next-line no-case-declarations |
| 86 | + case Memo: |
93 | 87 | const outerName = (type: any).displayName || null;
|
94 | 88 | if (outerName !== null) {
|
95 | 89 | return outerName;
|
96 | 90 | }
|
97 | 91 | return getComponentNameFromType(type.type) || 'Memo';
|
98 |
| - case REACT_LAZY_TYPE: { |
| 92 | + case Lazy: { |
99 | 93 | const lazyComponent: LazyComponent<any, any> = (type: any);
|
100 | 94 | const payload = lazyComponent._payload;
|
101 | 95 | const init = lazyComponent._init;
|
|
0 commit comments