diff --git a/packages/events/SyntheticEvent.js b/packages/events/SyntheticEvent.js index beaaa5947e6ca..cb14a7962479c 100644 --- a/packages/events/SyntheticEvent.js +++ b/packages/events/SyntheticEvent.js @@ -228,49 +228,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 - ) { - warning( - 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); /** @@ -324,6 +281,26 @@ function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) { const EventConstructor = this; if (EventConstructor.eventPool.length) { const instance = EventConstructor.eventPool.pop(); + + if (__DEV__) { + for (let prop in instance) { + if ( + instance.hasOwnProperty(prop) && + !EventConstructor.Interface.hasOwnProperty(prop) && + shouldBeReleasedProperties.indexOf(prop) === -1 + ) { + warning( + didWarnForAddedNewProperty, + "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; + } + } + } + EventConstructor.call( instance, dispatchConfig, diff --git a/packages/react-dom/src/events/__tests__/SyntheticEvent-test.js b/packages/react-dom/src/events/__tests__/SyntheticEvent-test.js index c0609e5fe2234..d3bfa82b0cbc8 100644 --- a/packages/react-dom/src/events/__tests__/SyntheticEvent-test.js +++ b/packages/react-dom/src/events/__tests__/SyntheticEvent-test.js @@ -11,7 +11,6 @@ let React; let ReactDOM; -let ReactTestUtils; describe('SyntheticEvent', () => { let container; @@ -19,7 +18,6 @@ describe('SyntheticEvent', () => { beforeEach(() => { React = require('react'); ReactDOM = require('react-dom'); - ReactTestUtils = require('react-dom/test-utils'); container = document.createElement('div'); document.body.appendChild(container); @@ -247,59 +245,57 @@ describe('SyntheticEvent', () => { expect(expectedCount).toBe(1); }); - // TODO: reenable this test. We are currently silencing these warnings when - // using TestUtils.Simulate to avoid spurious warnings that result from the - // way we simulate events. - xit('should properly log warnings when events simulated with rendered components', () => { - let event; - const element = document.createElement('div'); - function assignEvent(e) { - event = e; - } - const node = ReactDOM.render(
, element); - ReactTestUtils.Simulate.click(ReactDOM.findDOMNode(node)); - - // access a property to cause the warning + it('should warn when the pooled event has extra properties', () => { + let node; + let lastEvent; + ReactDOM.render( +