Skip to content

Commit ee7d76f

Browse files
ljharbjetoneza
authored andcommitted
[react-is] add back proper AsyncMode symbol, for back compat (facebook#13959)
- Partial revert of facebook#13732 - Fixes facebook#13958.
1 parent 768dd9c commit ee7d76f

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

packages/react-is/src/ReactIs.js

+5-3
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

+1-1
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

+3
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;

packages/shared/__tests__/ReactSymbols-test.internal.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ describe('ReactSymbols', () => {
3131
const originalSymbolFor = global.Symbol.for;
3232
global.Symbol.for = null;
3333
try {
34-
expectToBeUnique(Object.entries(require('shared/ReactSymbols')));
34+
const entries = Object.entries(require('shared/ReactSymbols')).filter(
35+
// REACT_ASYNC_MODE_TYPE and REACT_CONCURRENT_MODE_TYPE have the same numeric value
36+
// for legacy backwards compatibility
37+
([key]) => key !== 'REACT_ASYNC_MODE_TYPE',
38+
);
39+
expectToBeUnique(entries);
3540
} finally {
3641
global.Symbol.for = originalSymbolFor;
3742
}

0 commit comments

Comments
 (0)