Skip to content

Commit

Permalink
Revert facebook#5947 and disable the test
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Jul 17, 2018
1 parent 171e0b7 commit ac71c29
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 71 deletions.
66 changes: 8 additions & 58 deletions packages/events/SyntheticEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

/**
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 9 additions & 13 deletions packages/react-dom/src/events/__tests__/SyntheticEvent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
};
Expand Down

0 comments on commit ac71c29

Please sign in to comment.