Skip to content

Commit

Permalink
[react-is] add back proper AsyncMode symbol, for back compat
Browse files Browse the repository at this point in the history
 - Partial revert of #13732
 - Fixes #13958.
  • Loading branch information
ljharb committed Oct 24, 2018
1 parent 275e76e commit 3ea64dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/react-is/src/ReactIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'use strict';

import {
REACT_ASYNC_MODE_TYPE,
REACT_CONCURRENT_MODE_TYPE,
REACT_CONTEXT_TYPE,
REACT_ELEMENT_TYPE,
Expand All @@ -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:
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-is/src/__tests__/ReactIs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(<React.unstable_ConcurrentMode />)).toBe(
ReactIs.ConcurrentMode,
);
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/ReactSymbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3ea64dd

Please sign in to comment.