Add SuspenseList to react-is (#20874)
This commit also adds explicit index.stable and index.experimental forks to the react-is package so that we can avoid exporting references to SuspenseList in a stable release.
Brian Vaughn committed
Feb 25, 2021 at 16:22 UTC
90bde6505e43434596ff6398c2c8acb67ced815b
4 files changed
+102
packages/react-is/index.experimental.js
new
+41
@@ -0,0 +1,41 @@
1
+/**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
8
+ */
9
+
10
+'use strict';
11
+
12
+export {
13
+ isValidElementType,
14
+ typeOf,
15
+ ContextConsumer,
16
+ ContextProvider,
17
+ Element,
18
+ ForwardRef,
19
+ Fragment,
20
+ Lazy,
21
+ Memo,
22
+ Portal,
23
+ Profiler,
24
+ StrictMode,
25
+ Suspense,
26
+ unstable_SuspenseList,
27
+ isAsyncMode,
28
+ isConcurrentMode,
29
+ isContextConsumer,
30
+ isContextProvider,
31
+ isElement,
32
+ isForwardRef,
33
+ isFragment,
34
+ isLazy,
35
+ isMemo,
36
+ isPortal,
37
+ isProfiler,
38
+ isStrictMode,
39
+ isSuspense,
40
+ unstable_isSuspenseList,
41
+} from './src/ReactIs';
packages/react-is/index.stable.js
new
+39
@@ -0,0 +1,39 @@
1
+/**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
8
+ */
9
+
10
+'use strict';
11
+
12
+export {
13
+ isValidElementType,
14
+ typeOf,
15
+ ContextConsumer,
16
+ ContextProvider,
17
+ Element,
18
+ ForwardRef,
19
+ Fragment,
20
+ Lazy,
21
+ Memo,
22
+ Portal,
23
+ Profiler,
24
+ StrictMode,
25
+ Suspense,
26
+ isAsyncMode,
27
+ isConcurrentMode,
28
+ isContextConsumer,
29
+ isContextProvider,
30
+ isElement,
31
+ isForwardRef,
32
+ isFragment,
33
+ isLazy,
34
+ isMemo,
35
+ isPortal,
36
+ isProfiler,
37
+ isStrictMode,
38
+ isSuspense,
39
+} from './src/ReactIs';
packages/react-is/src/ReactIs.js
+4
@@ -72,6 +72,7 @@ export const Portal = REACT_PORTAL_TYPE;
72
export const Profiler = REACT_PROFILER_TYPE;
73
export const StrictMode = REACT_STRICT_MODE_TYPE;
74
export const Suspense = REACT_SUSPENSE_TYPE;
75
+export const unstable_SuspenseList = REACT_SUSPENSE_LIST_TYPE;
76
77
export {isValidElementType};
78
@@ -142,3 +143,6 @@ export function isStrictMode(object: any) {
143
export function isSuspense(object: any) {
144
return typeOf(object) === REACT_SUSPENSE_TYPE;
145
}
146
+export function unstable_isSuspenseList(object: any) {
147
+ return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
148
+}
packages/react-is/src/__tests__/ReactIs-test.js
+18
@@ -186,6 +186,24 @@ describe('ReactIs', () => {
186
expect(ReactIs.isSuspense(<div />)).toBe(false);
187
});
188
189
+ // @gate experimental
190
+ it('should identify suspense list', () => {
191
+ expect(ReactIs.isValidElementType(React.unstable_SuspenseList)).toBe(true);
192
+ expect(ReactIs.typeOf(<React.unstable_SuspenseList />)).toBe(
193
+ ReactIs.unstable_SuspenseList,
194
+ );
195
+ expect(
196
+ ReactIs.unstable_isSuspenseList(<React.unstable_SuspenseList />),
197
+ ).toBe(true);
198
+ expect(
199
+ ReactIs.unstable_isSuspenseList({type: ReactIs.unstable_SuspenseList}),
200
+ ).toBe(false);
201
+ expect(ReactIs.unstable_isSuspenseList('React.unstable_SuspenseList')).toBe(
202
+ false,
203
+ );
204
+ expect(ReactIs.unstable_isSuspenseList(<div />)).toBe(false);
205
+ });
206
+
207
it('should identify profile root', () => {
208
expect(ReactIs.isValidElementType(React.Profiler)).toBe(true);
209
expect(