diff --git a/packages/events/SyntheticEvent.js b/packages/events/SyntheticEvent.js index 9c2d9eee1c5c8..eeeca14a880b3 100644 --- a/packages/events/SyntheticEvent.js +++ b/packages/events/SyntheticEvent.js @@ -10,19 +10,8 @@ import invariant from 'shared/invariant'; import warningWithoutStack from 'shared/warningWithoutStack'; -let didWarnForAddedNewProperty = false; const EVENT_POOL_SIZE = 10; -const shouldBeReleasedProperties = [ - 'dispatchConfig', - '_targetInst', - 'nativeEvent', - 'isDefaultPrevented', - 'isPropagationStopped', - '_dispatchListeners', - '_dispatchInstances', -]; - /** * @interface Event * @see http://www.w3.org/TR/DOM-Level-3-Events/ @@ -188,9 +177,13 @@ Object.assign(SyntheticEvent.prototype, { this[propName] = null; } } - for (let i = 0; i < shouldBeReleasedProperties.length; i++) { - this[shouldBeReleasedProperties[i]] = null; - } + this.dispatchConfig = null; + this._targetInst = null; + this.nativeEvent = null; + this.isDefaultPrevented = null; + this.isPropagationStopped = null; + this._dispatchListeners = null; + this._dispatchInstances = null; if (__DEV__) { Object.defineProperty( this, @@ -237,49 +230,6 @@ SyntheticEvent.extend = function(Interface) { return Class; }; -/** Proxying after everything set on SyntheticEvent - * to resolve Proxy issue on some WebKit browsers - * in which some Event properties are set to undefined (GH#10010) - */ -if (__DEV__) { - const isProxySupported = - typeof Proxy === 'function' && - // /~https://github.com/facebook/react/issues/12011 - !Object.isSealed(new Proxy({}, {})); - - if (isProxySupported) { - /*eslint-disable no-func-assign */ - SyntheticEvent = new Proxy(SyntheticEvent, { - construct: function(target, args) { - return this.apply(target, Object.create(target.prototype), args); - }, - apply: function(constructor, that, args) { - return new Proxy(constructor.apply(that, args), { - set: function(target, prop, value) { - if ( - prop !== 'isPersistent' && - !target.constructor.Interface.hasOwnProperty(prop) && - shouldBeReleasedProperties.indexOf(prop) === -1 - ) { - warningWithoutStack( - didWarnForAddedNewProperty || target.isPersistent(), - "This synthetic event is reused for performance reasons. If you're " + - "seeing this, you're adding a new property in the synthetic event object. " + - 'The property is never released. See ' + - 'https://fb.me/react-event-pooling for more information.', - ); - didWarnForAddedNewProperty = true; - } - target[prop] = value; - return true; - }, - }); - }, - }); - /*eslint-enable no-func-assign */ - } -} - addEventPoolingTo(SyntheticEvent); /** @@ -354,7 +304,7 @@ function releasePooledEvent(event) { const EventConstructor = this; invariant( event instanceof EventConstructor, - 'Trying to release an event instance into a pool of a different type.', + 'Trying to release an event instance into a pool of a different type.', ); event.destructor(); if (EventConstructor.eventPool.length < EVENT_POOL_SIZE) { diff --git a/packages/react-dom/src/events/__tests__/SyntheticEvent-test.js b/packages/react-dom/src/events/__tests__/SyntheticEvent-test.js index 6d98060e9e28a..4e9c8502f46f5 100644 --- a/packages/react-dom/src/events/__tests__/SyntheticEvent-test.js +++ b/packages/react-dom/src/events/__tests__/SyntheticEvent-test.js @@ -270,25 +270,21 @@ describe('SyntheticEvent', () => { ); }); - it('should warn if Proxy is supported and the synthetic event is added a property', () => { + xit('should warn if synthetic event is added a property', () => { let node; let expectedCount = 0; let syntheticEvent; const eventHandler = e => { - if (typeof Proxy === 'function') { - expect(() => { - e.foo = 'bar'; - }).toWarnDev( - 'Warning: This synthetic event is reused for performance reasons. If ' + - "you're seeing this, you're adding a new property in the synthetic " + - 'event object. The property is never released. ' + - 'See https://fb.me/react-event-pooling for more information.', - {withoutStack: true}, - ); - } else { + expect(() => { e.foo = 'bar'; - } + }).toWarnDev( + 'Warning: This synthetic event is reused for performance reasons. If ' + + "you're seeing this, you're adding a new property in the synthetic " + + 'event object. The property is never released. ' + + 'See https://fb.me/react-event-pooling for more information.', + {withoutStack: true}, + ); syntheticEvent = e; expectedCount++; };