File tree 2 files changed +38
-2
lines changed
src/renderers/dom/client/syntheticEvents
2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ var assign = require('Object.assign');
17
17
var emptyFunction = require ( 'emptyFunction' ) ;
18
18
var warning = require ( 'warning' ) ;
19
19
20
+ var didWarnAddedProperty = false ;
21
+
20
22
/**
21
23
* @interface Event
22
24
* @see http://www.w3.org/TR/DOM-Level-3-Events/
@@ -157,14 +159,33 @@ assign(SyntheticEvent.prototype, {
157
159
*/
158
160
destructor : function ( ) {
159
161
var Interface = this . constructor . Interface ;
160
- for ( var propName in Interface ) {
162
+ var propName ;
163
+ for ( propName in Interface ) {
161
164
this [ propName ] = null ;
162
165
}
163
166
this . dispatchConfig = null ;
164
167
this . _targetInst = null ;
165
168
this . nativeEvent = null ;
166
- } ,
169
+ this . isDefaultPrevented = null ;
170
+ this . isPropagationStopped = null ;
167
171
172
+ if ( __DEV__ ) {
173
+ if ( ! didWarnAddedProperty ) {
174
+ for ( propName in this ) {
175
+ if ( this . hasOwnProperty ( propName ) && this [ propName ] != null ) {
176
+ warning (
177
+ didWarnAddedProperty ,
178
+ 'This synthetic event is reused for performance reasons. If you\'re ' +
179
+ 'seeing this, you\'re adding a property in the synthetic event object.' +
180
+ 'The property is never released. See ' +
181
+ 'https://fb.me/react-event-pooling for more information.'
182
+ ) ;
183
+ didWarnAddedProperty = true ;
184
+ }
185
+ }
186
+ }
187
+ }
188
+ } ,
168
189
} ) ;
169
190
170
191
SyntheticEvent . Interface = EventInterface ;
Original file line number Diff line number Diff line change @@ -108,4 +108,19 @@ describe('SyntheticEvent', function() {
108
108
'https://fb.me/react-event-pooling for more information.'
109
109
) ;
110
110
} ) ;
111
+
112
+ it ( 'should warn if the synthetic event is added a property' , function ( ) {
113
+ spyOn ( console , 'error' ) ;
114
+ var syntheticEvent = createEvent ( { } ) ;
115
+ syntheticEvent . foo = 'foo' ;
116
+ SyntheticEvent . release ( syntheticEvent ) ;
117
+ expect ( syntheticEvent . foo ) . toBe ( 'foo' ) ;
118
+ expect ( console . error . calls . length ) . toBe ( 1 ) ;
119
+ expect ( console . error . argsForCall [ 0 ] [ 0 ] ) . toBe (
120
+ 'Warning: This synthetic event is reused for performance reasons. If you\'re ' +
121
+ 'seeing this, you\'re adding a property in the synthetic event object.' +
122
+ 'The property is never released. See ' +
123
+ 'https://fb.me/react-event-pooling for more information.'
124
+ ) ;
125
+ } ) ;
111
126
} ) ;
You can’t perform that action at this time.
0 commit comments