From 3ea64dd57c3404df2f0f5a70ac1e3d4733e22dde Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 24 Oct 2018 15:06:41 -0700 Subject: [PATCH] [react-is] add back proper AsyncMode symbol, for back compat - Partial revert of #13732 - Fixes #13958. --- packages/react-is/src/ReactIs.js | 8 +++++--- packages/react-is/src/__tests__/ReactIs-test.js | 2 +- packages/shared/ReactSymbols.js | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/react-is/src/ReactIs.js b/packages/react-is/src/ReactIs.js index 97a4212d6c85e..0c1edb811370d 100644 --- a/packages/react-is/src/ReactIs.js +++ b/packages/react-is/src/ReactIs.js @@ -10,6 +10,7 @@ 'use strict'; import { + REACT_ASYNC_MODE_TYPE, REACT_CONCURRENT_MODE_TYPE, REACT_CONTEXT_TYPE, REACT_ELEMENT_TYPE, @@ -32,6 +33,7 @@ export function typeOf(object: any) { const type = object.type; switch (type) { + case REACT_ASYNC_MODE_TYPE: case REACT_CONCURRENT_MODE_TYPE: case REACT_FRAGMENT_TYPE: case REACT_PROFILER_TYPE: @@ -57,8 +59,8 @@ export function typeOf(object: any) { return undefined; } -// AsyncMode alias is deprecated along with isAsyncMode -export const AsyncMode = REACT_CONCURRENT_MODE_TYPE; +// AsyncMode is deprecated along with isAsyncMode +export const AsyncMode = REACT_ASYNC_MODE_TYPE; export const ConcurrentMode = REACT_CONCURRENT_MODE_TYPE; export const ContextConsumer = REACT_CONTEXT_TYPE; export const ContextProvider = REACT_PROVIDER_TYPE; @@ -86,7 +88,7 @@ export function isAsyncMode(object: any) { ); } } - return isConcurrentMode(object); + return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE; } export function isConcurrentMode(object: any) { return typeOf(object) === REACT_CONCURRENT_MODE_TYPE; diff --git a/packages/react-is/src/__tests__/ReactIs-test.js b/packages/react-is/src/__tests__/ReactIs-test.js index 6fc58b34cf07d..3cf74ea6febb9 100644 --- a/packages/react-is/src/__tests__/ReactIs-test.js +++ b/packages/react-is/src/__tests__/ReactIs-test.js @@ -69,7 +69,7 @@ describe('ReactIs', () => { expect(ReactIs.isValidElementType({type: 'div', props: {}})).toEqual(false); }); - it('should identify async mode', () => { + it('should identify concurrent mode', () => { expect(ReactIs.typeOf()).toBe( ReactIs.ConcurrentMode, ); diff --git a/packages/shared/ReactSymbols.js b/packages/shared/ReactSymbols.js index cc86ccbeeb723..a2a7c3c009b85 100644 --- a/packages/shared/ReactSymbols.js +++ b/packages/shared/ReactSymbols.js @@ -32,6 +32,9 @@ export const REACT_PROVIDER_TYPE = hasSymbol export const REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; +export const REACT_ASYNC_MODE_TYPE = hasSymbol + ? Symbol.for('react.async_mode') + : 0xeacf; export const REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;