@samitouri / QOS-React-2 / commits / 6cbf0f7fac

Fork ReactSymbols (#24484)

* Fork ReactSymbols * Fix tests * Update jest config

Ricky committed May 3, 2022 at 17:12 UTC 6cbf0f7fac772c3fd18706d73af00f3fd06a55b5
5 files changed +134 -65
packages/shared/ReactSymbols.js
+25 -64
@@ -11,72 +11,33 @@
11 // When adding new symbols to this file,
12 // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
13
14 -import {enableSymbolFallbackForWWW} from './ReactFeatureFlags';
15 -
16 -const usePolyfill =
17 - enableSymbolFallbackForWWW && (typeof Symbol !== 'function' || !Symbol.for);
18 -
14 // The Symbol used to tag the ReactElement-like types.
20 -export const REACT_ELEMENT_TYPE = usePolyfill
21 - ? 0xeac7
22 - : Symbol.for('react.element');
23 -export const REACT_PORTAL_TYPE = usePolyfill
24 - ? 0xeaca
25 - : Symbol.for('react.portal');
26 -export const REACT_FRAGMENT_TYPE = usePolyfill
27 - ? 0xeacb
28 - : Symbol.for('react.fragment');
29 -export const REACT_STRICT_MODE_TYPE = usePolyfill
30 - ? 0xeacc
31 - : Symbol.for('react.strict_mode');
32 -export const REACT_PROFILER_TYPE = usePolyfill
33 - ? 0xead2
34 - : Symbol.for('react.profiler');
35 -export const REACT_PROVIDER_TYPE = usePolyfill
36 - ? 0xeacd
37 - : Symbol.for('react.provider');
38 -export const REACT_CONTEXT_TYPE = usePolyfill
39 - ? 0xeace
40 - : Symbol.for('react.context');
41 -export const REACT_SERVER_CONTEXT_TYPE = usePolyfill
42 - ? 0xeae6
43 - : Symbol.for('react.server_context');
44 -export const REACT_FORWARD_REF_TYPE = usePolyfill
45 - ? 0xead0
46 - : Symbol.for('react.forward_ref');
47 -export const REACT_SUSPENSE_TYPE = usePolyfill
48 - ? 0xead1
49 - : Symbol.for('react.suspense');
50 -export const REACT_SUSPENSE_LIST_TYPE = usePolyfill
51 - ? 0xead8
52 - : Symbol.for('react.suspense_list');
53 -export const REACT_MEMO_TYPE = usePolyfill ? 0xead3 : Symbol.for('react.memo');
54 -export const REACT_LAZY_TYPE = usePolyfill ? 0xead4 : Symbol.for('react.lazy');
55 -export const REACT_SCOPE_TYPE = usePolyfill
56 - ? 0xead7
57 - : Symbol.for('react.scope');
58 -export const REACT_DEBUG_TRACING_MODE_TYPE = usePolyfill
59 - ? 0xeae1
60 - : Symbol.for('react.debug_trace_mode');
61 -export const REACT_OFFSCREEN_TYPE = usePolyfill
62 - ? 0xeae2
63 - : Symbol.for('react.offscreen');
64 -export const REACT_LEGACY_HIDDEN_TYPE = usePolyfill
65 - ? 0xeae3
66 - : Symbol.for('react.legacy_hidden');
67 -export const REACT_CACHE_TYPE = usePolyfill
68 - ? 0xeae4
69 - : Symbol.for('react.cache');
70 -export const REACT_TRACING_MARKER_TYPE = usePolyfill
71 - ? 0xeae5
72 - : Symbol.for('react.tracing_marker');
73 -export const REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = usePolyfill
74 - ? 0xeae7
75 - : Symbol.for('react.default_value');
76 -const MAYBE_ITERATOR_SYMBOL = usePolyfill
77 - ? typeof Symbol === 'function' && Symbol.iterator
78 - : Symbol.iterator;
15 +export const REACT_ELEMENT_TYPE = Symbol.for('react.element');
16 +export const REACT_PORTAL_TYPE = Symbol.for('react.portal');
17 +export const REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
18 +export const REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
19 +export const REACT_PROFILER_TYPE = Symbol.for('react.profiler');
20 +export const REACT_PROVIDER_TYPE = Symbol.for('react.provider');
21 +export const REACT_CONTEXT_TYPE = Symbol.for('react.context');
22 +export const REACT_SERVER_CONTEXT_TYPE = Symbol.for('react.server_context');
23 +export const REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
24 +export const REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
25 +export const REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
26 +export const REACT_MEMO_TYPE = Symbol.for('react.memo');
27 +export const REACT_LAZY_TYPE = Symbol.for('react.lazy');
28 +export const REACT_SCOPE_TYPE = Symbol.for('react.scope');
29 +export const REACT_DEBUG_TRACING_MODE_TYPE = Symbol.for(
30 + 'react.debug_trace_mode',
31 +);
32 +export const REACT_OFFSCREEN_TYPE = Symbol.for('react.offscreen');
33 +export const REACT_LEGACY_HIDDEN_TYPE = Symbol.for('react.legacy_hidden');
34 +export const REACT_CACHE_TYPE = Symbol.for('react.cache');
35 +export const REACT_TRACING_MARKER_TYPE = Symbol.for('react.tracing_marker');
36 +export const REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for(
37 + 'react.default_value',
38 +);
39
40 +const MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
41 const FAUX_ITERATOR_SYMBOL = '@@iterator';
42
43 export function getIteratorFn(maybeIterable: ?any): ?() => ?Iterator<*> {
packages/shared/ReactSymbols.www.js new
+93
@@ -0,0 +1,93 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow
8 + */
9 +
10 +// ATTENTION
11 +// When adding new symbols to this file,
12 +// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
13 +
14 +import {enableSymbolFallbackForWWW} from './ReactFeatureFlags';
15 +
16 +const usePolyfill =
17 + enableSymbolFallbackForWWW && (typeof Symbol !== 'function' || !Symbol.for);
18 +
19 +// The Symbol used to tag the ReactElement-like types.
20 +export const REACT_ELEMENT_TYPE = usePolyfill
21 + ? 0xeac7
22 + : Symbol.for('react.element');
23 +export const REACT_PORTAL_TYPE = usePolyfill
24 + ? 0xeaca
25 + : Symbol.for('react.portal');
26 +export const REACT_FRAGMENT_TYPE = usePolyfill
27 + ? 0xeacb
28 + : Symbol.for('react.fragment');
29 +export const REACT_STRICT_MODE_TYPE = usePolyfill
30 + ? 0xeacc
31 + : Symbol.for('react.strict_mode');
32 +export const REACT_PROFILER_TYPE = usePolyfill
33 + ? 0xead2
34 + : Symbol.for('react.profiler');
35 +export const REACT_PROVIDER_TYPE = usePolyfill
36 + ? 0xeacd
37 + : Symbol.for('react.provider');
38 +export const REACT_CONTEXT_TYPE = usePolyfill
39 + ? 0xeace
40 + : Symbol.for('react.context');
41 +export const REACT_SERVER_CONTEXT_TYPE = usePolyfill
42 + ? 0xeae6
43 + : Symbol.for('react.server_context');
44 +export const REACT_FORWARD_REF_TYPE = usePolyfill
45 + ? 0xead0
46 + : Symbol.for('react.forward_ref');
47 +export const REACT_SUSPENSE_TYPE = usePolyfill
48 + ? 0xead1
49 + : Symbol.for('react.suspense');
50 +export const REACT_SUSPENSE_LIST_TYPE = usePolyfill
51 + ? 0xead8
52 + : Symbol.for('react.suspense_list');
53 +export const REACT_MEMO_TYPE = usePolyfill ? 0xead3 : Symbol.for('react.memo');
54 +export const REACT_LAZY_TYPE = usePolyfill ? 0xead4 : Symbol.for('react.lazy');
55 +export const REACT_SCOPE_TYPE = usePolyfill
56 + ? 0xead7
57 + : Symbol.for('react.scope');
58 +export const REACT_DEBUG_TRACING_MODE_TYPE = usePolyfill
59 + ? 0xeae1
60 + : Symbol.for('react.debug_trace_mode');
61 +export const REACT_OFFSCREEN_TYPE = usePolyfill
62 + ? 0xeae2
63 + : Symbol.for('react.offscreen');
64 +export const REACT_LEGACY_HIDDEN_TYPE = usePolyfill
65 + ? 0xeae3
66 + : Symbol.for('react.legacy_hidden');
67 +export const REACT_CACHE_TYPE = usePolyfill
68 + ? 0xeae4
69 + : Symbol.for('react.cache');
70 +export const REACT_TRACING_MARKER_TYPE = usePolyfill
71 + ? 0xeae5
72 + : Symbol.for('react.tracing_marker');
73 +export const REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = usePolyfill
74 + ? 0xeae7
75 + : Symbol.for('react.default_value');
76 +const MAYBE_ITERATOR_SYMBOL = usePolyfill
77 + ? typeof Symbol === 'function' && Symbol.iterator
78 + : Symbol.iterator;
79 +
80 +const FAUX_ITERATOR_SYMBOL = '@@iterator';
81 +
82 +export function getIteratorFn(maybeIterable: ?any): ?() => ?Iterator<*> {
83 + if (maybeIterable === null || typeof maybeIterable !== 'object') {
84 + return null;
85 + }
86 + const maybeIterator =
87 + (MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL]) ||
88 + maybeIterable[FAUX_ITERATOR_SYMBOL];
89 + if (typeof maybeIterator === 'function') {
90 + return maybeIterator;
91 + }
92 + return null;
93 +}
packages/shared/__tests__/ReactSymbols-test.internal.js
+1 -1
@@ -32,7 +32,7 @@ describe('ReactSymbols', () => {
32 const originalSymbolFor = global.Symbol.for;
33 global.Symbol.for = null;
34 try {
35 - const entries = Object.entries(require('shared/ReactSymbols')).filter(
35 + const entries = Object.entries(require('shared/ReactSymbols.www')).filter(
36 // REACT_ASYNC_MODE_TYPE and REACT_CONCURRENT_MODE_TYPE have the same numeric value
37 // for legacy backwards compatibility
38 ([key]) => key !== 'REACT_ASYNC_MODE_TYPE',
scripts/jest/setupTests.www.js
+4
@@ -19,6 +19,10 @@ jest.mock('shared/ReactFeatureFlags', () => {
19 return wwwFlags;
20 });
21
22 +jest.mock('shared/ReactSymbols', () => {
23 + return jest.requireActual('shared/ReactSymbols.www');
24 +});
25 +
26 jest.mock('scheduler/src/SchedulerFeatureFlags', () => {
27 const schedulerSrcPath = process.cwd() + '/packages/scheduler';
28 jest.mock(
scripts/rollup/forks.js
+11
@@ -138,6 +138,17 @@ const forks = Object.freeze({
138 return null;
139 },
140
141 + './packages/shared/ReactSymbols.js': bundleType => {
142 + switch (bundleType) {
143 + case FB_WWW_DEV:
144 + case FB_WWW_PROD:
145 + case FB_WWW_PROFILING:
146 + return './packages/shared/ReactSymbols.www.js';
147 + default:
148 + return './packages/shared/ReactSymbols.js';
149 + }
150 + },
151 +
152 './packages/scheduler/index.js': (bundleType, entry, dependencies) => {
153 switch (bundleType) {
154 case UMD_DEV: