{
- e.persist();
leaveEvents.push(e);
}}
/>,
@@ -77,7 +76,6 @@ describe('EnterLeaveEventPlugin', () => {
const node = ReactDOM.render(
{
- e.persist();
enterEvents.push(e);
}}
/>,
diff --git a/packages/react-dom/src/events/__tests__/SyntheticClipboardEvent-test.js b/packages/react-dom/src/events/__tests__/SyntheticClipboardEvent-test.js
index 6bff9d7f40d..4bc4d570197 100644
--- a/packages/react-dom/src/events/__tests__/SyntheticClipboardEvent-test.js
+++ b/packages/react-dom/src/events/__tests__/SyntheticClipboardEvent-test.js
@@ -116,42 +116,5 @@ describe('SyntheticClipboardEvent', () => {
expect(expectedCount).toBe(3);
});
-
- it('is able to `persist`', () => {
- const persistentEvents = [];
- const eventHandler = event => {
- expect(event.isPersistent()).toBe(false);
- event.persist();
- expect(event.isPersistent()).toBe(true);
- persistentEvents.push(event);
- };
-
- const div = ReactDOM.render(
-
,
- container,
- );
-
- let event;
- event = document.createEvent('Event');
- event.initEvent('copy', true, true);
- div.dispatchEvent(event);
-
- event = document.createEvent('Event');
- event.initEvent('cut', true, true);
- div.dispatchEvent(event);
-
- event = document.createEvent('Event');
- event.initEvent('paste', true, true);
- div.dispatchEvent(event);
-
- expect(persistentEvents.length).toBe(3);
- expect(persistentEvents[0].type).toBe('copy');
- expect(persistentEvents[1].type).toBe('cut');
- expect(persistentEvents[2].type).toBe('paste');
- });
});
});
diff --git a/packages/react-dom/src/events/__tests__/SyntheticEvent-test.js b/packages/react-dom/src/events/__tests__/SyntheticEvent-test.js
index 906ae127cf4..a6575fe2844 100644
--- a/packages/react-dom/src/events/__tests__/SyntheticEvent-test.js
+++ b/packages/react-dom/src/events/__tests__/SyntheticEvent-test.js
@@ -102,18 +102,18 @@ describe('SyntheticEvent', () => {
expect(expectedCount).toBe(1);
});
- it('should be able to `persist`', () => {
+ it('should indicate that it is persisted and warn when calling `persist`', () => {
let node;
- let expectedCount = 0;
let syntheticEvent;
const eventHandler = e => {
- expect(e.isPersistent()).toBe(false);
- e.persist();
+ expect(e.isPersistent()).toBe(true);
+ expect(() => e.persist()).toWarnDev(
+ 'Deprecated SyntheticEvent.persist called for click event',
+ {withoutStack: true},
+ );
syntheticEvent = e;
expect(e.isPersistent()).toBe(true);
-
- expectedCount++;
};
node = ReactDOM.render(
, container);
@@ -122,208 +122,6 @@ describe('SyntheticEvent', () => {
node.dispatchEvent(event);
expect(syntheticEvent.type).toBe('click');
- expect(syntheticEvent.bubbles).toBe(true);
- expect(syntheticEvent.cancelable).toBe(true);
- expect(expectedCount).toBe(1);
- });
-
- it('should be nullified and log warnings if the synthetic event has not been persisted', () => {
- let node;
- let expectedCount = 0;
- let syntheticEvent;
-
- const eventHandler = e => {
- syntheticEvent = e;
-
- expectedCount++;
- };
- node = ReactDOM.render(
, container);
-
- const event = document.createEvent('Event');
- event.initEvent('click', true, true);
- node.dispatchEvent(event);
-
- const getExpectedWarning = property =>
- 'Warning: This synthetic event is reused for performance reasons. If ' +
- `you're seeing this, you're accessing the property \`${property}\` on a ` +
- 'released/nullified synthetic event. This is set to null. If you must ' +
- 'keep the original synthetic event around, use event.persist(). ' +
- 'See https://fb.me/react-event-pooling for more information.';
-
- // once for each property accessed
- expect(() => expect(syntheticEvent.type).toBe(null)).toWarnDev(
- getExpectedWarning('type'),
- {withoutStack: true},
- );
- expect(() => expect(syntheticEvent.nativeEvent).toBe(null)).toWarnDev(
- getExpectedWarning('nativeEvent'),
- {withoutStack: true},
- );
- expect(() => expect(syntheticEvent.target).toBe(null)).toWarnDev(
- getExpectedWarning('target'),
- {withoutStack: true},
- );
-
- expect(expectedCount).toBe(1);
- });
-
- it('should warn when setting properties of a synthetic event that has not been persisted', () => {
- let node;
- let expectedCount = 0;
- let syntheticEvent;
-
- const eventHandler = e => {
- syntheticEvent = e;
-
- expectedCount++;
- };
- node = ReactDOM.render(
, container);
-
- const event = document.createEvent('Event');
- event.initEvent('click', true, true);
- node.dispatchEvent(event);
-
- expect(() => {
- syntheticEvent.type = 'MouseEvent';
- }).toWarnDev(
- 'Warning: This synthetic event is reused for performance reasons. If ' +
- "you're seeing this, you're setting the property `type` on a " +
- 'released/nullified synthetic event. This is effectively a no-op. If you must ' +
- 'keep the original synthetic event around, use event.persist(). ' +
- 'See https://fb.me/react-event-pooling for more information.',
- {withoutStack: true},
- );
- expect(expectedCount).toBe(1);
- });
-
- it('should warn when calling `preventDefault` if the synthetic event has not been persisted', () => {
- let node;
- let expectedCount = 0;
- let syntheticEvent;
-
- const eventHandler = e => {
- syntheticEvent = e;
- expectedCount++;
- };
- node = ReactDOM.render(
, container);
-
- const event = document.createEvent('Event');
- event.initEvent('click', true, true);
- node.dispatchEvent(event);
-
- expect(() => syntheticEvent.preventDefault()).toWarnDev(
- 'Warning: This synthetic event is reused for performance reasons. If ' +
- "you're seeing this, you're accessing the method `preventDefault` on a " +
- 'released/nullified synthetic event. This is a no-op function. If you must ' +
- 'keep the original synthetic event around, use event.persist(). ' +
- 'See https://fb.me/react-event-pooling for more information.',
- {withoutStack: true},
- );
- expect(expectedCount).toBe(1);
- });
-
- it('should warn when calling `stopPropagation` if the synthetic event has not been persisted', () => {
- let node;
- let expectedCount = 0;
- let syntheticEvent;
-
- const eventHandler = e => {
- syntheticEvent = e;
- expectedCount++;
- };
- node = ReactDOM.render(
, container);
-
- const event = document.createEvent('Event');
- event.initEvent('click', true, true);
-
- node.dispatchEvent(event);
-
- expect(() => syntheticEvent.stopPropagation()).toWarnDev(
- 'Warning: This synthetic event is reused for performance reasons. If ' +
- "you're seeing this, you're accessing the method `stopPropagation` on a " +
- 'released/nullified synthetic event. This is a no-op function. If you must ' +
- 'keep the original synthetic event around, use event.persist(). ' +
- 'See https://fb.me/react-event-pooling for more information.',
- {withoutStack: true},
- );
- expect(expectedCount).toBe(1);
- });
-
- it('should warn when calling `isPropagationStopped` if the synthetic event has not been persisted', () => {
- let node;
- let expectedCount = 0;
- let syntheticEvent;
-
- const eventHandler = e => {
- syntheticEvent = e;
- expectedCount++;
- };
- node = ReactDOM.render(
, container);
-
- const event = document.createEvent('Event');
- event.initEvent('click', true, true);
- node.dispatchEvent(event);
-
- expect(() =>
- expect(syntheticEvent.isPropagationStopped()).toBe(false),
- ).toWarnDev(
- 'Warning: This synthetic event is reused for performance reasons. If ' +
- "you're seeing this, you're accessing the method `isPropagationStopped` on a " +
- 'released/nullified synthetic event. This is a no-op function. If you must ' +
- 'keep the original synthetic event around, use event.persist(). ' +
- 'See https://fb.me/react-event-pooling for more information.',
- {withoutStack: true},
- );
- expect(expectedCount).toBe(1);
- });
-
- it('should warn when calling `isDefaultPrevented` if the synthetic event has not been persisted', () => {
- let node;
- let expectedCount = 0;
- let syntheticEvent;
-
- const eventHandler = e => {
- syntheticEvent = e;
- expectedCount++;
- };
- node = ReactDOM.render(
, container);
-
- const event = document.createEvent('Event');
- event.initEvent('click', true, true);
- node.dispatchEvent(event);
-
- expect(() =>
- expect(syntheticEvent.isDefaultPrevented()).toBe(false),
- ).toWarnDev(
- 'Warning: This synthetic event is reused for performance reasons. If ' +
- "you're seeing this, you're accessing the method `isDefaultPrevented` on a " +
- 'released/nullified synthetic event. This is a no-op function. If you must ' +
- 'keep the original synthetic event around, use event.persist(). ' +
- 'See https://fb.me/react-event-pooling for more information.',
- {withoutStack: true},
- );
- expect(expectedCount).toBe(1);
- });
-
- it('should properly log warnings when events simulated with rendered components', () => {
- let event;
- function assignEvent(e) {
- event = e;
- }
- const node = ReactDOM.render(
, container);
- node.click();
-
- // access a property to cause the warning
- expect(() => {
- event.nativeEvent; // eslint-disable-line no-unused-expressions
- }).toWarnDev(
- 'Warning: This synthetic event is reused for performance reasons. If ' +
- "you're seeing this, you're accessing the property `nativeEvent` on a " +
- 'released/nullified synthetic event. This is set to null. If you must ' +
- 'keep the original synthetic event around, use event.persist(). ' +
- 'See https://fb.me/react-event-pooling for more information.',
- {withoutStack: true},
- );
});
// TODO: we might want to re-add a warning like this in the future,
diff --git a/packages/react-dom/src/events/__tests__/SyntheticKeyboardEvent-test.js b/packages/react-dom/src/events/__tests__/SyntheticKeyboardEvent-test.js
index 06673f0fbe0..8af4eb02553 100644
--- a/packages/react-dom/src/events/__tests__/SyntheticKeyboardEvent-test.js
+++ b/packages/react-dom/src/events/__tests__/SyntheticKeyboardEvent-test.js
@@ -499,50 +499,5 @@ describe('SyntheticKeyboardEvent', () => {
);
expect(expectedCount).toBe(3);
});
-
- it('is able to `persist`', () => {
- const persistentEvents = [];
- const eventHandler = event => {
- expect(event.isPersistent()).toBe(false);
- event.persist();
- expect(event.isPersistent()).toBe(true);
- persistentEvents.push(event);
- };
- let div = ReactDOM.render(
-
,
- container,
- );
-
- div.dispatchEvent(
- new KeyboardEvent('keydown', {
- keyCode: 40,
- bubbles: true,
- cancelable: true,
- }),
- );
- div.dispatchEvent(
- new KeyboardEvent('keyup', {
- keyCode: 40,
- bubbles: true,
- cancelable: true,
- }),
- );
- div.dispatchEvent(
- new KeyboardEvent('keypress', {
- charCode: 40,
- keyCode: 40,
- bubbles: true,
- cancelable: true,
- }),
- );
- expect(persistentEvents.length).toBe(3);
- expect(persistentEvents[0].type).toBe('keydown');
- expect(persistentEvents[1].type).toBe('keyup');
- expect(persistentEvents[2].type).toBe('keypress');
- });
});
});
diff --git a/packages/react-dom/src/events/__tests__/SyntheticWheelEvent-test.js b/packages/react-dom/src/events/__tests__/SyntheticWheelEvent-test.js
index 924a7f37628..4892d27fcd9 100644
--- a/packages/react-dom/src/events/__tests__/SyntheticWheelEvent-test.js
+++ b/packages/react-dom/src/events/__tests__/SyntheticWheelEvent-test.js
@@ -32,7 +32,6 @@ describe('SyntheticWheelEvent', () => {
it('should normalize properties from the MouseEvent interface', () => {
const events = [];
const onWheel = event => {
- event.persist();
events.push(event);
};
ReactDOM.render(
, container);
@@ -51,7 +50,6 @@ describe('SyntheticWheelEvent', () => {
it('should normalize properties from the WheelEvent interface', () => {
const events = [];
const onWheel = event => {
- event.persist();
events.push(event);
};
ReactDOM.render(
, container);
@@ -89,7 +87,6 @@ describe('SyntheticWheelEvent', () => {
expect(event.isDefaultPrevented()).toBe(false);
event.preventDefault();
expect(event.isDefaultPrevented()).toBe(true);
- event.persist();
events.push(event);
};
ReactDOM.render(
, container);
@@ -112,24 +109,4 @@ describe('SyntheticWheelEvent', () => {
expect(events.length).toBe(2);
});
-
- it('should be able to `persist`', () => {
- const events = [];
- const onWheel = event => {
- expect(event.isPersistent()).toBe(false);
- event.persist();
- expect(event.isPersistent()).toBe(true);
- events.push(event);
- };
- ReactDOM.render(
, container);
-
- container.firstChild.dispatchEvent(
- new MouseEvent('wheel', {
- bubbles: true,
- }),
- );
-
- expect(events.length).toBe(1);
- expect(events[0].type).toBe('wheel');
- });
});
diff --git a/packages/react-dom/src/test-utils/ReactTestUtils.js b/packages/react-dom/src/test-utils/ReactTestUtils.js
index dad3d0f14e2..fa64d392841 100644
--- a/packages/react-dom/src/test-utils/ReactTestUtils.js
+++ b/packages/react-dom/src/test-utils/ReactTestUtils.js
@@ -424,9 +424,6 @@ function makeSimulator(eventType) {
domNode,
);
- // Since we aren't using pooling, always persist the event. This will make
- // sure it's marked and won't warn when setting additional properties.
- event.persist();
Object.assign(event, eventData);
if (dispatchConfig.phasedRegistrationNames) {
diff --git a/packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js b/packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js
index 127d7b14635..068902ce674 100644
--- a/packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js
+++ b/packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js
@@ -46,7 +46,7 @@ const ReactNativeBridgeEventPlugin = {
'Unsupported top level event type "%s" dispatched',
topLevelType,
);
- const event = SyntheticEvent.getPooled(
+ const event = new SyntheticEvent(
bubbleDispatchConfig || directDispatchConfig,
targetInst,
nativeEvent,