Skip to content

Commit 90bde65

Browse files
author
Brian Vaughn
authored
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.
1 parent 8336f19 commit 90bde65

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -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

+39
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const Portal = REACT_PORTAL_TYPE;
7272
export const Profiler = REACT_PROFILER_TYPE;
7373
export const StrictMode = REACT_STRICT_MODE_TYPE;
7474
export const Suspense = REACT_SUSPENSE_TYPE;
75+
export const unstable_SuspenseList = REACT_SUSPENSE_LIST_TYPE;
7576

7677
export {isValidElementType};
7778

@@ -142,3 +143,6 @@ export function isStrictMode(object: any) {
142143
export function isSuspense(object: any) {
143144
return typeOf(object) === REACT_SUSPENSE_TYPE;
144145
}
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
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,24 @@ describe('ReactIs', () => {
186186
expect(ReactIs.isSuspense(<div />)).toBe(false);
187187
});
188188

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+
189207
it('should identify profile root', () => {
190208
expect(ReactIs.isValidElementType(React.Profiler)).toBe(true);
191209
expect(

0 commit comments

Comments
 (0)