Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SuspenseList to react-is #20874

Merged
merged 2 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/react-is/index.experimental.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

export {
isValidElementType,
typeOf,
ContextConsumer,
ContextProvider,
Element,
ForwardRef,
Fragment,
Lazy,
Memo,
Portal,
Profiler,
StrictMode,
Suspense,
SuspenseList,
isAsyncMode,
isConcurrentMode,
isContextConsumer,
isContextProvider,
isElement,
isForwardRef,
isFragment,
isLazy,
isMemo,
isPortal,
isProfiler,
isStrictMode,
isSuspense,
isSuspenseList,
bvaughn marked this conversation as resolved.
Show resolved Hide resolved
} from './src/ReactIs';
39 changes: 39 additions & 0 deletions packages/react-is/index.stable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

export {
isValidElementType,
typeOf,
ContextConsumer,
ContextProvider,
Element,
ForwardRef,
Fragment,
Lazy,
Memo,
Portal,
Profiler,
StrictMode,
Suspense,
isAsyncMode,
isConcurrentMode,
isContextConsumer,
isContextProvider,
isElement,
isForwardRef,
isFragment,
isLazy,
isMemo,
isPortal,
isProfiler,
isStrictMode,
isSuspense,
} from './src/ReactIs';
4 changes: 4 additions & 0 deletions packages/react-is/src/ReactIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const Portal = REACT_PORTAL_TYPE;
export const Profiler = REACT_PROFILER_TYPE;
export const StrictMode = REACT_STRICT_MODE_TYPE;
export const Suspense = REACT_SUSPENSE_TYPE;
export const SuspenseList = REACT_SUSPENSE_LIST_TYPE;

export {isValidElementType};

Expand Down Expand Up @@ -142,3 +143,6 @@ export function isStrictMode(object: any) {
export function isSuspense(object: any) {
return typeOf(object) === REACT_SUSPENSE_TYPE;
}
export function isSuspenseList(object: any) {
return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
}
12 changes: 12 additions & 0 deletions packages/react-is/src/__tests__/ReactIs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ describe('ReactIs', () => {
expect(ReactIs.isSuspense(<div />)).toBe(false);
});

// @gate experimental
it('should identify suspense list', () => {
expect(ReactIs.isValidElementType(React.unstable_SuspenseList)).toBe(true);
expect(ReactIs.typeOf(<React.unstable_SuspenseList />)).toBe(
ReactIs.SuspenseList,
);
expect(ReactIs.isSuspenseList(<React.unstable_SuspenseList />)).toBe(true);
expect(ReactIs.isSuspenseList({type: ReactIs.SuspenseList})).toBe(false);
expect(ReactIs.isSuspenseList('React.SuspenseList')).toBe(false);
expect(ReactIs.isSuspenseList(<div />)).toBe(false);
});

it('should identify profile root', () => {
expect(ReactIs.isValidElementType(React.Profiler)).toBe(true);
expect(
Expand Down