Skip to content

Commit 73fa26a

Browse files
gaearonnhunzaker
authored andcommitted
Drop some top-level events from the list (#11912)
* Drop some top-level events from the list * Put both whitelists in one file
1 parent bb0bcc0 commit 73fa26a

File tree

4 files changed

+42
-70
lines changed

4 files changed

+42
-70
lines changed

packages/react-dom/src/client/ReactDOMFiberComponent.js

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as inputValueTracking from './inputValueTracking';
2222
import setInnerHTML from './setInnerHTML';
2323
import setTextContent from './setTextContent';
2424
import {listenTo, trapBubbledEvent} from '../events/ReactBrowserEventEmitter';
25+
import {mediaEventTypes} from '../events/BrowserEventConstants';
2526
import * as CSSPropertyOperations from '../shared/CSSPropertyOperations';
2627
import {Namespaces, getIntrinsicNamespace} from '../shared/DOMNamespaces';
2728
import {
@@ -223,34 +224,6 @@ function getOwnerDocumentFromRootContainer(
223224
: rootContainerElement.ownerDocument;
224225
}
225226

226-
// There are so many media events, it makes sense to just
227-
// maintain a list rather than create a `trapBubbledEvent` for each
228-
const mediaEvents = {
229-
topAbort: 'abort',
230-
topCanPlay: 'canplay',
231-
topCanPlayThrough: 'canplaythrough',
232-
topDurationChange: 'durationchange',
233-
topEmptied: 'emptied',
234-
topEncrypted: 'encrypted',
235-
topEnded: 'ended',
236-
topError: 'error',
237-
topLoadedData: 'loadeddata',
238-
topLoadedMetadata: 'loadedmetadata',
239-
topLoadStart: 'loadstart',
240-
topPause: 'pause',
241-
topPlay: 'play',
242-
topPlaying: 'playing',
243-
topProgress: 'progress',
244-
topRateChange: 'ratechange',
245-
topSeeked: 'seeked',
246-
topSeeking: 'seeking',
247-
topStalled: 'stalled',
248-
topSuspend: 'suspend',
249-
topTimeUpdate: 'timeupdate',
250-
topVolumeChange: 'volumechange',
251-
topWaiting: 'waiting',
252-
};
253-
254227
function trapClickOnNonInteractiveElement(node: HTMLElement) {
255228
// Mobile Safari does not fire properly bubble click events on
256229
// non-interactive elements, which means delegated click listeners do not
@@ -472,9 +445,9 @@ export function setInitialProperties(
472445
case 'video':
473446
case 'audio':
474447
// Create listener for each media event
475-
for (const event in mediaEvents) {
476-
if (mediaEvents.hasOwnProperty(event)) {
477-
trapBubbledEvent(event, mediaEvents[event], domElement);
448+
for (const event in mediaEventTypes) {
449+
if (mediaEventTypes.hasOwnProperty(event)) {
450+
trapBubbledEvent(event, mediaEventTypes[event], domElement);
478451
}
479452
}
480453
props = rawProps;
@@ -860,9 +833,9 @@ export function diffHydratedProperties(
860833
case 'video':
861834
case 'audio':
862835
// Create listener for each media event
863-
for (const event in mediaEvents) {
864-
if (mediaEvents.hasOwnProperty(event)) {
865-
trapBubbledEvent(event, mediaEvents[event], domElement);
836+
for (const event in mediaEventTypes) {
837+
if (mediaEventTypes.hasOwnProperty(event)) {
838+
trapBubbledEvent(event, mediaEventTypes[event], domElement);
866839
}
867840
}
868841
break;

packages/react-dom/src/events/BrowserEventConstants.js

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,16 @@ import getVendorPrefixedEventName from './getVendorPrefixedEventName';
1010
/**
1111
* Types of raw signals from the browser caught at the top level.
1212
*
13-
* For events like 'submit' which don't consistently bubble (which we
14-
* trap at a lower node than `document`), binding at `document` would
15-
* cause duplicate events so we don't include them here.
13+
* For events like 'submit' or audio/video events which don't consistently
14+
* bubble (which we trap at a lower node than `document`), binding
15+
* at `document` would cause duplicate events so we don't include them here.
1616
*/
17-
const topLevelTypes = {
18-
topAbort: 'abort',
17+
export const topLevelTypes = {
1918
topAnimationEnd: getVendorPrefixedEventName('animationend'),
2019
topAnimationIteration: getVendorPrefixedEventName('animationiteration'),
2120
topAnimationStart: getVendorPrefixedEventName('animationstart'),
2221
topBlur: 'blur',
2322
topCancel: 'cancel',
24-
topCanPlay: 'canplay',
25-
topCanPlayThrough: 'canplaythrough',
2623
topChange: 'change',
2724
topClick: 'click',
2825
topClose: 'close',
@@ -41,54 +38,60 @@ const topLevelTypes = {
4138
topDragOver: 'dragover',
4239
topDragStart: 'dragstart',
4340
topDrop: 'drop',
44-
topDurationChange: 'durationchange',
45-
topEmptied: 'emptied',
46-
topEncrypted: 'encrypted',
47-
topEnded: 'ended',
48-
topError: 'error',
4941
topFocus: 'focus',
5042
topInput: 'input',
5143
topKeyDown: 'keydown',
5244
topKeyPress: 'keypress',
5345
topKeyUp: 'keyup',
54-
topLoadedData: 'loadeddata',
5546
topLoad: 'load',
56-
topLoadedMetadata: 'loadedmetadata',
5747
topLoadStart: 'loadstart',
5848
topMouseDown: 'mousedown',
5949
topMouseMove: 'mousemove',
6050
topMouseOut: 'mouseout',
6151
topMouseOver: 'mouseover',
6252
topMouseUp: 'mouseup',
6353
topPaste: 'paste',
54+
topScroll: 'scroll',
55+
topSelectionChange: 'selectionchange',
56+
topTextInput: 'textInput',
57+
topToggle: 'toggle',
58+
topTouchCancel: 'touchcancel',
59+
topTouchEnd: 'touchend',
60+
topTouchMove: 'touchmove',
61+
topTouchStart: 'touchstart',
62+
topTransitionEnd: getVendorPrefixedEventName('transitionend'),
63+
topWheel: 'wheel',
64+
};
65+
66+
// There are so many media events, it makes sense to just
67+
// maintain a list of them. Note these aren't technically
68+
// "top-level" since they don't bubble. We should come up
69+
// with a better naming convention if we come to refactoring
70+
// the event system.
71+
export const mediaEventTypes = {
72+
topAbort: 'abort',
73+
topCanPlay: 'canplay',
74+
topCanPlayThrough: 'canplaythrough',
75+
topDurationChange: 'durationchange',
76+
topEmptied: 'emptied',
77+
topEncrypted: 'encrypted',
78+
topEnded: 'ended',
79+
topError: 'error',
80+
topLoadedData: 'loadeddata',
81+
topLoadedMetadata: 'loadedmetadata',
82+
topLoadStart: 'loadstart',
6483
topPause: 'pause',
6584
topPlay: 'play',
6685
topPlaying: 'playing',
6786
topProgress: 'progress',
6887
topRateChange: 'ratechange',
69-
topScroll: 'scroll',
7088
topSeeked: 'seeked',
7189
topSeeking: 'seeking',
72-
topSelectionChange: 'selectionchange',
7390
topStalled: 'stalled',
7491
topSuspend: 'suspend',
75-
topTextInput: 'textInput',
7692
topTimeUpdate: 'timeupdate',
77-
topToggle: 'toggle',
78-
topTouchCancel: 'touchcancel',
79-
topTouchEnd: 'touchend',
80-
topTouchMove: 'touchmove',
81-
topTouchStart: 'touchstart',
82-
topTransitionEnd: getVendorPrefixedEventName('transitionend'),
8393
topVolumeChange: 'volumechange',
8494
topWaiting: 'waiting',
85-
topWheel: 'wheel',
8695
};
8796

8897
export type TopLevelTypes = $Enum<typeof topLevelTypes>;
89-
90-
const BrowserEventConstants = {
91-
topLevelTypes,
92-
};
93-
94-
export default BrowserEventConstants;

packages/react-dom/src/events/ReactBrowserEventEmitter.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import {
1313
trapCapturedEvent,
1414
} from './ReactDOMEventListener';
1515
import isEventSupported from './isEventSupported';
16-
import BrowserEventConstants from './BrowserEventConstants';
17-
18-
const {topLevelTypes} = BrowserEventConstants;
16+
import {topLevelTypes} from './BrowserEventConstants';
1917

2018
/**
2119
* Summary of `ReactBrowserEventEmitter` event handling:

packages/react-dom/src/test-utils/ReactTestUtils.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import SyntheticEvent from 'events/SyntheticEvent';
1919
import invariant from 'fbjs/lib/invariant';
2020

21-
import BrowserEventConstants from '../events/BrowserEventConstants';
21+
import {topLevelTypes} from '../events/BrowserEventConstants';
2222

2323
const {findDOMNode} = ReactDOM;
2424
const {
@@ -30,8 +30,6 @@ const {
3030
ReactDOMEventListener,
3131
} = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
3232

33-
const topLevelTypes = BrowserEventConstants.topLevelTypes;
34-
3533
function Event(suffix) {}
3634

3735
/**

0 commit comments

Comments
 (0)