Skip to content

Commit 3ea64dd

Browse files
committed
[react-is] add back proper AsyncMode symbol, for back compat
- Partial revert of facebook#13732 - Fixes facebook#13958.
1 parent 275e76e commit 3ea64dd

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

packages/react-is/src/ReactIs.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'use strict';
1111

1212
import {
13+
REACT_ASYNC_MODE_TYPE,
1314
REACT_CONCURRENT_MODE_TYPE,
1415
REACT_CONTEXT_TYPE,
1516
REACT_ELEMENT_TYPE,
@@ -32,6 +33,7 @@ export function typeOf(object: any) {
3233
const type = object.type;
3334

3435
switch (type) {
36+
case REACT_ASYNC_MODE_TYPE:
3537
case REACT_CONCURRENT_MODE_TYPE:
3638
case REACT_FRAGMENT_TYPE:
3739
case REACT_PROFILER_TYPE:
@@ -57,8 +59,8 @@ export function typeOf(object: any) {
5759
return undefined;
5860
}
5961

60-
// AsyncMode alias is deprecated along with isAsyncMode
61-
export const AsyncMode = REACT_CONCURRENT_MODE_TYPE;
62+
// AsyncMode is deprecated along with isAsyncMode
63+
export const AsyncMode = REACT_ASYNC_MODE_TYPE;
6264
export const ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
6365
export const ContextConsumer = REACT_CONTEXT_TYPE;
6466
export const ContextProvider = REACT_PROVIDER_TYPE;
@@ -86,7 +88,7 @@ export function isAsyncMode(object: any) {
8688
);
8789
}
8890
}
89-
return isConcurrentMode(object);
91+
return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
9092
}
9193
export function isConcurrentMode(object: any) {
9294
return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;

packages/react-is/src/__tests__/ReactIs-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('ReactIs', () => {
6969
expect(ReactIs.isValidElementType({type: 'div', props: {}})).toEqual(false);
7070
});
7171

72-
it('should identify async mode', () => {
72+
it('should identify concurrent mode', () => {
7373
expect(ReactIs.typeOf(<React.unstable_ConcurrentMode />)).toBe(
7474
ReactIs.ConcurrentMode,
7575
);

packages/shared/ReactSymbols.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export const REACT_PROVIDER_TYPE = hasSymbol
3232
export const REACT_CONTEXT_TYPE = hasSymbol
3333
? Symbol.for('react.context')
3434
: 0xeace;
35+
export const REACT_ASYNC_MODE_TYPE = hasSymbol
36+
? Symbol.for('react.async_mode')
37+
: 0xeacf;
3538
export const REACT_CONCURRENT_MODE_TYPE = hasSymbol
3639
? Symbol.for('react.concurrent_mode')
3740
: 0xeacf;

0 commit comments

Comments
 (0)