Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary event whitelist in production #10802

Merged
merged 3 commits into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions scripts/rollup/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@
"gzip": 6767
},
"react-dom.development.js (UMD_DEV)": {
"size": 650284,
"gzip": 148956
"size": 650200,
"gzip": 149037
},
"react-dom.production.min.js (UMD_PROD)": {
"size": 103018,
"gzip": 32102
"size": 102429,
"gzip": 31953
},
"react-dom.development.js (NODE_DEV)": {
"size": 611085,
"gzip": 140117
"size": 611001,
"gzip": 140196
},
"react-dom.production.min.js (NODE_PROD)": {
"size": 108328,
"gzip": 33945
"size": 107766,
"gzip": 33808
},
"ReactDOMFiber-dev.js (FB_DEV)": {
"size": 607451,
"gzip": 139504
"size": 607385,
"gzip": 139587
},
"ReactDOMFiber-prod.js (FB_PROD)": {
"size": 421286,
"gzip": 94454
"size": 420318,
"gzip": 94289
},
"react-dom-test-utils.development.js (NODE_DEV)": {
"size": 43849,
Expand Down
92 changes: 51 additions & 41 deletions src/renderers/dom/shared/eventPlugins/SimpleEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var SyntheticUIEvent = require('SyntheticUIEvent');
var SyntheticWheelEvent = require('SyntheticWheelEvent');

var getEventCharCode = require('getEventCharCode');
var invariant = require('fbjs/lib/invariant');
var warning = require('fbjs/lib/warning');

import type {TopLevelTypes} from 'BrowserEventConstants';
import type {
Expand Down Expand Up @@ -138,6 +138,41 @@ var topLevelEventsToDispatchConfig: {[key: TopLevelTypes]: DispatchConfig} = {};
topLevelEventsToDispatchConfig[topEvent] = type;
});

// Only used in DEV for exhaustiveness validation.
var knownHTMLTopLevelTypes = [
'topAbort',
'topCancel',
'topCanPlay',
'topCanPlayThrough',
'topClose',
'topDurationChange',
'topEmptied',
'topEncrypted',
'topEnded',
'topError',
'topInput',
'topInvalid',
'topLoad',
'topLoadedData',
'topLoadedMetadata',
'topLoadStart',
'topPause',
'topPlay',
'topPlaying',
'topProgress',
'topRateChange',
'topReset',
'topSeeked',
'topSeeking',
'topStalled',
'topSubmit',
'topSuspend',
'topTimeUpdate',
'topToggle',
'topVolumeChange',
'topWaiting',
];

var SimpleEventPlugin: PluginModule<MouseEvent> = {
eventTypes: eventTypes,

Expand All @@ -153,41 +188,6 @@ var SimpleEventPlugin: PluginModule<MouseEvent> = {
}
var EventConstructor;
switch (topLevelType) {
case 'topAbort':
case 'topCancel':
case 'topCanPlay':
case 'topCanPlayThrough':
case 'topClose':
case 'topDurationChange':
case 'topEmptied':
case 'topEncrypted':
case 'topEnded':
case 'topError':
case 'topInput':
case 'topInvalid':
case 'topLoad':
case 'topLoadedData':
case 'topLoadedMetadata':
case 'topLoadStart':
case 'topPause':
case 'topPlay':
case 'topPlaying':
case 'topProgress':
case 'topRateChange':
case 'topReset':
case 'topSeeked':
case 'topSeeking':
case 'topStalled':
case 'topSubmit':
case 'topSuspend':
case 'topTimeUpdate':
case 'topToggle':
case 'topVolumeChange':
case 'topWaiting':
// HTML Events
// @see http://www.w3.org/TR/html5/index.html#events-0
EventConstructor = SyntheticEvent;
break;
case 'topKeyPress':
// Firefox creates a keypress event for function keys too. This removes
// the unwanted keypress events. Enter is however both printable and
Expand Down Expand Up @@ -257,12 +257,22 @@ var SimpleEventPlugin: PluginModule<MouseEvent> = {
case 'topPaste':
EventConstructor = SyntheticClipboardEvent;
break;
default:
if (__DEV__) {
if (knownHTMLTopLevelTypes.indexOf(topLevelType) === -1) {
warning(
false,
'SimpleEventPlugin: Unhandled event type, `%s`. This warning ' +
'is likely caused by a bug in React. Please file an issue.',
topLevelType,
);
}
}
// HTML Events
// @see http://www.w3.org/TR/html5/index.html#events-0
EventConstructor = SyntheticEvent;
break;
}
invariant(
EventConstructor,
'SimpleEventPlugin: Unhandled event type, `%s`.',
topLevelType,
);
var event = EventConstructor.getPooled(
dispatchConfig,
targetInst,
Expand Down