From c4090d2cf02998e4c312f33675d8b9ad1def7a3a Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 25 Feb 2021 10:59:14 -0500 Subject: [PATCH 1/2] Added SuspenseList to react-is experimental release 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. --- packages/react-is/index.experimental.js | 41 +++++++++++++++++++ packages/react-is/index.stable.js | 39 ++++++++++++++++++ packages/react-is/src/ReactIs.js | 4 ++ .../react-is/src/__tests__/ReactIs-test.js | 12 ++++++ 4 files changed, 96 insertions(+) create mode 100644 packages/react-is/index.experimental.js create mode 100644 packages/react-is/index.stable.js diff --git a/packages/react-is/index.experimental.js b/packages/react-is/index.experimental.js new file mode 100644 index 0000000000000..5b80389daa9ce --- /dev/null +++ b/packages/react-is/index.experimental.js @@ -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, +} from './src/ReactIs'; diff --git a/packages/react-is/index.stable.js b/packages/react-is/index.stable.js new file mode 100644 index 0000000000000..ad64178a1c537 --- /dev/null +++ b/packages/react-is/index.stable.js @@ -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'; diff --git a/packages/react-is/src/ReactIs.js b/packages/react-is/src/ReactIs.js index 2f132ba5de9a0..dd81ec036158d 100644 --- a/packages/react-is/src/ReactIs.js +++ b/packages/react-is/src/ReactIs.js @@ -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}; @@ -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; +} diff --git a/packages/react-is/src/__tests__/ReactIs-test.js b/packages/react-is/src/__tests__/ReactIs-test.js index cddd479c4344e..d107c9977f119 100644 --- a/packages/react-is/src/__tests__/ReactIs-test.js +++ b/packages/react-is/src/__tests__/ReactIs-test.js @@ -186,6 +186,18 @@ describe('ReactIs', () => { expect(ReactIs.isSuspense(
)).toBe(false); }); + // @gate experimental + it('should identify suspense list', () => { + expect(ReactIs.isValidElementType(React.unstable_SuspenseList)).toBe(true); + expect(ReactIs.typeOf()).toBe( + ReactIs.SuspenseList, + ); + expect(ReactIs.isSuspenseList()).toBe(true); + expect(ReactIs.isSuspenseList({type: ReactIs.SuspenseList})).toBe(false); + expect(ReactIs.isSuspenseList('React.SuspenseList')).toBe(false); + expect(ReactIs.isSuspenseList(
)).toBe(false); + }); + it('should identify profile root', () => { expect(ReactIs.isValidElementType(React.Profiler)).toBe(true); expect( From 73c472c20121134a90ffa0a09bc0d64c5617e5a9 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 25 Feb 2021 16:01:11 -0500 Subject: [PATCH 2/2] Rename react-is SuspenseList exports to have unstable_ prefix --- packages/react-is/index.experimental.js | 4 ++-- packages/react-is/src/ReactIs.js | 4 ++-- packages/react-is/src/__tests__/ReactIs-test.js | 16 +++++++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/react-is/index.experimental.js b/packages/react-is/index.experimental.js index 5b80389daa9ce..560283842b594 100644 --- a/packages/react-is/index.experimental.js +++ b/packages/react-is/index.experimental.js @@ -23,7 +23,7 @@ export { Profiler, StrictMode, Suspense, - SuspenseList, + unstable_SuspenseList, isAsyncMode, isConcurrentMode, isContextConsumer, @@ -37,5 +37,5 @@ export { isProfiler, isStrictMode, isSuspense, - isSuspenseList, + unstable_isSuspenseList, } from './src/ReactIs'; diff --git a/packages/react-is/src/ReactIs.js b/packages/react-is/src/ReactIs.js index dd81ec036158d..1958043bb2243 100644 --- a/packages/react-is/src/ReactIs.js +++ b/packages/react-is/src/ReactIs.js @@ -72,7 +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 const unstable_SuspenseList = REACT_SUSPENSE_LIST_TYPE; export {isValidElementType}; @@ -143,6 +143,6 @@ export function isStrictMode(object: any) { export function isSuspense(object: any) { return typeOf(object) === REACT_SUSPENSE_TYPE; } -export function isSuspenseList(object: any) { +export function unstable_isSuspenseList(object: any) { return typeOf(object) === REACT_SUSPENSE_LIST_TYPE; } diff --git a/packages/react-is/src/__tests__/ReactIs-test.js b/packages/react-is/src/__tests__/ReactIs-test.js index d107c9977f119..e054cdbc4d485 100644 --- a/packages/react-is/src/__tests__/ReactIs-test.js +++ b/packages/react-is/src/__tests__/ReactIs-test.js @@ -190,12 +190,18 @@ describe('ReactIs', () => { it('should identify suspense list', () => { expect(ReactIs.isValidElementType(React.unstable_SuspenseList)).toBe(true); expect(ReactIs.typeOf()).toBe( - ReactIs.SuspenseList, + ReactIs.unstable_SuspenseList, ); - expect(ReactIs.isSuspenseList()).toBe(true); - expect(ReactIs.isSuspenseList({type: ReactIs.SuspenseList})).toBe(false); - expect(ReactIs.isSuspenseList('React.SuspenseList')).toBe(false); - expect(ReactIs.isSuspenseList(
)).toBe(false); + expect( + ReactIs.unstable_isSuspenseList(), + ).toBe(true); + expect( + ReactIs.unstable_isSuspenseList({type: ReactIs.unstable_SuspenseList}), + ).toBe(false); + expect(ReactIs.unstable_isSuspenseList('React.unstable_SuspenseList')).toBe( + false, + ); + expect(ReactIs.unstable_isSuspenseList(
)).toBe(false); }); it('should identify profile root', () => {