7
7
8
8
import {
9
9
registrationNameModules ,
10
- plugins ,
11
10
possibleRegistrationNames ,
12
11
} from 'events/EventPluginRegistry' ;
13
12
import { ReactDebugCurrentFrame } from 'shared/ReactGlobalSharedState' ;
@@ -30,51 +29,72 @@ function getStackAddendum() {
30
29
if ( __DEV__ ) {
31
30
var warnedProperties = { } ;
32
31
var hasOwnProperty = Object . prototype . hasOwnProperty ;
33
- var EVENT_NAME_REGEX = / ^ o n [ A - Z ] / ;
32
+ var EVENT_NAME_REGEX = / ^ o n ./ ;
33
+ var INVALID_EVENT_NAME_REGEX = / ^ o n [ ^ A - Z ] / ;
34
34
var rARIA = new RegExp ( '^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$' ) ;
35
35
var rARIACamel = new RegExp ( '^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$' ) ;
36
36
37
- var validateProperty = function ( tagName , name , value ) {
37
+ var validateProperty = function ( tagName , name , value , canUseEventSystem ) {
38
38
if ( hasOwnProperty . call ( warnedProperties , name ) && warnedProperties [ name ] ) {
39
39
return true ;
40
40
}
41
41
42
- if ( registrationNameModules . hasOwnProperty ( name ) ) {
43
- return true ;
44
- }
45
-
46
- if ( plugins . length === 0 && EVENT_NAME_REGEX . test ( name ) ) {
47
- // If no event plugins have been injected, we might be in a server environment.
48
- // Don't check events in this case.
49
- return true ;
50
- }
51
-
52
42
var lowerCasedName = name . toLowerCase ( ) ;
53
- var registrationName = possibleRegistrationNames . hasOwnProperty (
54
- lowerCasedName ,
55
- )
56
- ? possibleRegistrationNames [ lowerCasedName ]
57
- : null ;
58
-
59
- if ( registrationName != null ) {
43
+ if ( lowerCasedName === 'onfocusin' || lowerCasedName === 'onfocusout' ) {
60
44
warning (
61
45
false ,
62
- 'Invalid event handler property `%s`. Did you mean `%s`?%s' ,
63
- name ,
64
- registrationName ,
65
- getStackAddendum ( ) ,
46
+ 'React uses onFocus and onBlur instead of onFocusIn and onFocusOut. ' +
47
+ 'All React events are normalized to bubble, so onFocusIn and onFocusOut ' +
48
+ 'are not needed/supported by React.' ,
66
49
) ;
67
50
warnedProperties [ name ] = true ;
68
51
return true ;
69
52
}
70
53
71
- if ( lowerCasedName . indexOf ( 'on' ) === 0 && lowerCasedName . length > 2 ) {
72
- warning (
73
- false ,
74
- 'Unknown event handler property `%s`. It will be ignored.%s' ,
75
- name ,
76
- getStackAddendum ( ) ,
77
- ) ;
54
+ // We can't rely on the event system being injected on the server.
55
+ if ( canUseEventSystem ) {
56
+ if ( registrationNameModules . hasOwnProperty ( name ) ) {
57
+ return true ;
58
+ }
59
+ var registrationName = possibleRegistrationNames . hasOwnProperty (
60
+ lowerCasedName ,
61
+ )
62
+ ? possibleRegistrationNames [ lowerCasedName ]
63
+ : null ;
64
+ if ( registrationName != null ) {
65
+ warning (
66
+ false ,
67
+ 'Invalid event handler property `%s`. Did you mean `%s`?%s' ,
68
+ name ,
69
+ registrationName ,
70
+ getStackAddendum ( ) ,
71
+ ) ;
72
+ warnedProperties [ name ] = true ;
73
+ return true ;
74
+ }
75
+ if ( EVENT_NAME_REGEX . test ( name ) ) {
76
+ warning (
77
+ false ,
78
+ 'Unknown event handler property `%s`. It will be ignored.%s' ,
79
+ name ,
80
+ getStackAddendum ( ) ,
81
+ ) ;
82
+ warnedProperties [ name ] = true ;
83
+ return true ;
84
+ }
85
+ } else if ( EVENT_NAME_REGEX . test ( name ) ) {
86
+ // If no event plugins have been injected, we are in a server environment.
87
+ // So we can't tell if the event name is correct for sure, but we can filter
88
+ // out known bad ones like `onclick`. We can't suggest a specific replacement though.
89
+ if ( INVALID_EVENT_NAME_REGEX . test ( name ) ) {
90
+ warning (
91
+ false ,
92
+ 'Invalid event handler property `%s`. ' +
93
+ 'React events use the camelCase naming convention, for example `onClick`.%s' ,
94
+ name ,
95
+ getStackAddendum ( ) ,
96
+ ) ;
97
+ }
78
98
warnedProperties [ name ] = true ;
79
99
return true ;
80
100
}
@@ -84,17 +104,6 @@ if (__DEV__) {
84
104
return true ;
85
105
}
86
106
87
- if ( lowerCasedName === 'onfocusin' || lowerCasedName === 'onfocusout' ) {
88
- warning (
89
- false ,
90
- 'React uses onFocus and onBlur instead of onFocusIn and onFocusOut. ' +
91
- 'All React events are normalized to bubble, so onFocusIn and onFocusOut ' +
92
- 'are not needed/supported by React.' ,
93
- ) ;
94
- warnedProperties [ name ] = true ;
95
- return true ;
96
- }
97
-
98
107
if ( lowerCasedName === 'innerhtml' ) {
99
108
warning (
100
109
false ,
@@ -233,10 +242,10 @@ if (__DEV__) {
233
242
} ;
234
243
}
235
244
236
- var warnUnknownProperties = function ( type , props ) {
245
+ var warnUnknownProperties = function ( type , props , canUseEventSystem ) {
237
246
var unknownProps = [ ] ;
238
247
for ( var key in props ) {
239
- var isValid = validateProperty ( type , key , props [ key ] ) ;
248
+ var isValid = validateProperty ( type , key , props [ key ] , canUseEventSystem ) ;
240
249
if ( ! isValid ) {
241
250
unknownProps . push ( key ) ;
242
251
}
@@ -266,9 +275,9 @@ var warnUnknownProperties = function(type, props) {
266
275
}
267
276
} ;
268
277
269
- export function validateProperties ( type , props ) {
278
+ export function validateProperties ( type , props , canUseEventSystem ) {
270
279
if ( isCustomComponent ( type , props ) ) {
271
280
return ;
272
281
}
273
- warnUnknownProperties ( type , props ) ;
282
+ warnUnknownProperties ( type , props , canUseEventSystem ) ;
274
283
}
0 commit comments