[Flare] Fix ES6 issues with IE11 (#15834)
Dominic Gannaway committed
Jun 6, 2019 at 18:38 UTC
8cfcfe0fcb4cea285750cf33c0302f80e5f2c358
5 files changed
+38
-15
packages/react-dom/src/events/DOMEventResponderSystem.js
+8
-7
@@ -79,17 +79,17 @@ type PartialEventObject = {
79
80
type ResponderTimeout = {|
81
id: TimeoutID,
82
- timers: Map<Symbol, ResponderTimer>,
82
+ timers: Map<number, ResponderTimer>,
83
|};
84
85
type ResponderTimer = {|
86
instance: ReactEventComponentInstance,
87
func: () => void,
88
- id: Symbol,
88
+ id: number,
89
timeStamp: number,
90
|};
91
92
-const activeTimeouts: Map<Symbol, ResponderTimeout> = new Map();
92
+const activeTimeouts: Map<number, ResponderTimeout> = new Map();
93
const rootEventTypesToEventComponentInstances: Map<
94
DOMTopLevelEventType | string,
95
Set<ReactEventComponentInstance>,
@@ -117,6 +117,7 @@ let currentTimeStamp = 0;
117
let currentTimers = new Map();
118
let currentInstance: null | ReactEventComponentInstance = null;
119
let currentEventQueue: null | EventQueue = null;
120
+let currentTimerIDCounter = 0;
121
122
const eventResponderContext: ReactResponderContext = {
123
dispatchEvent(
@@ -340,14 +341,14 @@ const eventResponderContext: ReactResponderContext = {
341
((currentInstance: any): ReactEventComponentInstance),
342
);
343
},
343
- setTimeout(func: () => void, delay): Symbol {
344
+ setTimeout(func: () => void, delay): number {
345
validateResponderContext();
346
if (currentTimers === null) {
347
currentTimers = new Map();
348
}
349
let timeout = currentTimers.get(delay);
350
350
- const timerId = Symbol();
351
+ const timerId = currentTimerIDCounter++;
352
if (timeout === undefined) {
353
const timers = new Map();
354
const id = setTimeout(() => {
@@ -368,7 +369,7 @@ const eventResponderContext: ReactResponderContext = {
369
activeTimeouts.set(timerId, timeout);
370
return timerId;
371
},
371
- clearTimeout(timerId: Symbol): void {
372
+ clearTimeout(timerId: number): void {
373
validateResponderContext();
374
const timeout = activeTimeouts.get(timerId);
375
@@ -550,7 +551,7 @@ function isFiberHostComponentFocusable(fiber: Fiber): boolean {
551
}
552
553
function processTimers(
553
- timers: Map<Symbol, ResponderTimer>,
554
+ timers: Map<number, ResponderTimer>,
555
delay: number,
556
): void {
557
const timersArr = Array.from(timers.values());
packages/react-events/src/Hover.js
+2
-2
@@ -33,8 +33,8 @@ type HoverState = {
33
isHovered: boolean,
34
isOverTouchHitTarget: boolean,
35
isTouched: boolean,
36
- hoverStartTimeout: null | Symbol,
37
- hoverEndTimeout: null | Symbol,
36
+ hoverStartTimeout: null | number,
37
+ hoverEndTimeout: null | number,
38
ignoreEmulatedMouseEvents: boolean,
39
};
40
packages/react-events/src/Press.js
+3
-3
@@ -53,11 +53,11 @@ type PressState = {
53
isLongPressed: boolean,
54
isPressed: boolean,
55
isPressWithinResponderRegion: boolean,
56
- longPressTimeout: null | Symbol,
56
+ longPressTimeout: null | number,
57
pointerType: PointerType,
58
pressTarget: null | Element,
59
- pressEndTimeout: null | Symbol,
60
- pressStartTimeout: null | Symbol,
59
+ pressEndTimeout: null | number,
60
+ pressStartTimeout: null | number,
61
responderRegionOnActivation: null | $ReadOnly<{|
62
bottom: number,
63
left: number,
packages/react/src/ReactCreateEventComponent.js
+23
-1
@@ -11,12 +11,34 @@ import {enableEventAPI} from 'shared/ReactFeatureFlags';
11
12
import {REACT_EVENT_COMPONENT_TYPE} from 'shared/ReactSymbols';
13
14
+let hasBadMapPolyfill;
15
+
16
+if (__DEV__) {
17
+ hasBadMapPolyfill = false;
18
+ try {
19
+ const frozenObject = Object.freeze({});
20
+ const testMap = new Map([[frozenObject, null]]);
21
+ const testSet = new Set([frozenObject]);
22
+ // This is necessary for Rollup to not consider these unused.
23
+ // https://github.com/rollup/rollup/issues/1771
24
+ // TODO: we can remove these if Rollup fixes the bug.
25
+ testMap.set(0, 0);
26
+ testSet.add(0);
27
+ } catch (e) {
28
+ // TODO: Consider warning about bad polyfills
29
+ hasBadMapPolyfill = true;
30
+ }
31
+}
32
+
33
export function createEventComponent(
34
responder: ReactEventResponder,
35
displayName: string,
36
): ?ReactEventComponent {
37
if (enableEventAPI) {
19
- if (__DEV__) {
38
+ // We use responder as a Map key later on. When we have a bad
39
+ // polyfill, then we can't use it as a key as the polyfill tries
40
+ // to add a property to the object.
41
+ if (__DEV__ && !hasBadMapPolyfill) {
42
Object.freeze(responder);
43
}
44
const eventComponent = {
packages/shared/ReactTypes.js
+2
-2
@@ -187,8 +187,8 @@ export type ReactResponderContext = {
187
requestResponderOwnership: () => boolean,
188
requestGlobalOwnership: () => boolean,
189
releaseOwnership: () => boolean,
190
- setTimeout: (func: () => void, timeout: number) => Symbol,
191
- clearTimeout: (timerId: Symbol) => void,
190
+ setTimeout: (func: () => void, timeout: number) => number,
191
+ clearTimeout: (timerId: number) => void,
192
getFocusableElementsInScope(): Array<HTMLElement>,
193
getActiveDocument(): Document,
194
objectAssign: Function,