9
9
10
10
// TODO: direct imports like some-package/src/* are bad. Fix me.
11
11
import { getCurrentFiberOwnerNameInDevOrNull } from 'react-reconciler/src/ReactCurrentFiber' ;
12
- import { registrationNameModules } from 'events/EventPluginRegistry' ;
13
12
import warning from 'shared/warning' ;
14
13
import warningWithoutStack from 'shared/warningWithoutStack' ;
15
14
@@ -21,16 +20,6 @@ import * as ReactDOMFiberTextarea from './ReactDOMFiberTextarea';
21
20
import * as inputValueTracking from './inputValueTracking' ;
22
21
import setInnerHTML from './setInnerHTML' ;
23
22
import setTextContent from './setTextContent' ;
24
- import {
25
- TOP_ERROR ,
26
- TOP_INVALID ,
27
- TOP_LOAD ,
28
- TOP_RESET ,
29
- TOP_SUBMIT ,
30
- TOP_TOGGLE ,
31
- } from '../events/DOMTopLevelEventTypes' ;
32
- import { listenTo , trapBubbledEvent } from '../events/ReactBrowserEventEmitter' ;
33
- import { mediaEventTypes } from '../events/DOMTopLevelEventTypes' ;
34
23
import * as CSSPropertyOperations from '../shared/CSSPropertyOperations' ;
35
24
import { Namespaces , getIntrinsicNamespace } from '../shared/DOMNamespaces' ;
36
25
import {
@@ -39,13 +28,15 @@ import {
39
28
shouldRemoveAttribute ,
40
29
} from '../shared/DOMProperty' ;
41
30
import assertValidProps from '../shared/assertValidProps' ;
42
- import { DOCUMENT_NODE , DOCUMENT_FRAGMENT_NODE } from '../shared/HTMLNodeType' ;
31
+ import { DOCUMENT_NODE } from '../shared/HTMLNodeType' ;
43
32
import isCustomComponent from '../shared/isCustomComponent' ;
44
33
import possibleStandardNames from '../shared/possibleStandardNames' ;
45
34
import { validateProperties as validateARIAProperties } from '../shared/ReactDOMInvalidARIAHook' ;
46
35
import { validateProperties as validateInputProperties } from '../shared/ReactDOMNullInputValuePropHook' ;
47
36
import { validateProperties as validateUnknownProperties } from '../shared/ReactDOMUnknownPropertyHook' ;
48
37
38
+ import { updateListener } from '../slim-events/updateListener' ;
39
+
49
40
let didWarnInvalidHydration = false ;
50
41
let didWarnShadyDOM = false ;
51
42
@@ -204,16 +195,6 @@ if (__DEV__) {
204
195
} ;
205
196
}
206
197
207
- function ensureListeningTo ( rootContainerElement , registrationName ) {
208
- const isDocumentOrFragment =
209
- rootContainerElement . nodeType === DOCUMENT_NODE ||
210
- rootContainerElement . nodeType === DOCUMENT_FRAGMENT_NODE ;
211
- const doc = isDocumentOrFragment
212
- ? rootContainerElement
213
- : rootContainerElement . ownerDocument ;
214
- listenTo ( registrationName , doc ) ;
215
- }
216
-
217
198
function getOwnerDocumentFromRootContainer (
218
199
rootContainerElement : Element | Document ,
219
200
) : Document {
@@ -285,13 +266,11 @@ function setInitialDOMProperties(
285
266
} else if ( propKey === AUTOFOCUS ) {
286
267
// We polyfill it separately on the client during commit.
287
268
// We blacklist it here rather than in the property list because we emit it in SSR.
288
- } else if ( registrationNameModules . hasOwnProperty ( propKey ) ) {
289
- if ( nextProp != null ) {
290
- if ( __DEV__ && typeof nextProp !== 'function' ) {
291
- warnForInvalidEventListener ( propKey , nextProp ) ;
292
- }
293
- ensureListeningTo ( rootContainerElement , propKey ) ;
269
+ } else if ( propKey [ 0 ] === 'o' && propKey [ 1 ] === 'n' ) {
270
+ if ( __DEV__ && typeof nextProp !== 'function' ) {
271
+ warnForInvalidEventListener ( propKey , nextProp ) ;
294
272
}
273
+ updateListener ( domElement , propKey , nextProp ) ;
295
274
} else if ( nextProp != null ) {
296
275
DOMPropertyOperations . setValueForProperty (
297
276
domElement ,
@@ -319,6 +298,11 @@ function updateDOMProperties(
319
298
setInnerHTML ( domElement , propValue ) ;
320
299
} else if ( propKey === CHILDREN ) {
321
300
setTextContent ( domElement , propValue ) ;
301
+ } else if ( propKey [ 0 ] === 'o' && propKey [ 1 ] === 'n' ) {
302
+ if ( __DEV__ && typeof nextProp !== 'function' ) {
303
+ warnForInvalidEventListener ( propKey , propValue ) ;
304
+ }
305
+ updateListener ( domElement , propKey , propValue ) ;
322
306
} else {
323
307
DOMPropertyOperations . setValueForProperty (
324
308
domElement ,
@@ -444,44 +428,32 @@ export function setInitialProperties(
444
428
switch ( tag ) {
445
429
case 'iframe ':
446
430
case 'object ':
447
- trapBubbledEvent ( TOP_LOAD , domElement ) ;
448
431
props = rawProps ;
449
432
break ;
450
433
case 'video ':
451
434
case 'audio ':
452
435
// Create listener for each media event
453
- for ( let i = 0 ; i < mediaEventTypes . length ; i ++ ) {
454
- trapBubbledEvent ( mediaEventTypes [ i ] , domElement ) ;
455
- }
456
436
props = rawProps ;
457
437
break ;
458
438
case 'source ':
459
- trapBubbledEvent ( TOP_ERROR , domElement ) ;
460
439
props = rawProps ;
461
440
break ;
462
441
case 'img ':
463
442
case 'image ':
464
443
case 'link ':
465
- trapBubbledEvent ( TOP_ERROR , domElement ) ;
466
- trapBubbledEvent ( TOP_LOAD , domElement ) ;
467
444
props = rawProps ;
468
445
break ;
469
446
case 'form ':
470
- trapBubbledEvent ( TOP_RESET , domElement ) ;
471
- trapBubbledEvent ( TOP_SUBMIT , domElement ) ;
472
447
props = rawProps ;
473
448
break ;
474
449
case 'details ':
475
- trapBubbledEvent ( TOP_TOGGLE , domElement ) ;
476
450
props = rawProps ;
477
451
break ;
478
452
case 'input ':
479
453
ReactDOMFiberInput . initWrapperState ( domElement , rawProps ) ;
480
454
props = ReactDOMFiberInput . getHostProps ( domElement , rawProps ) ;
481
- trapBubbledEvent ( TOP_INVALID , domElement ) ;
482
455
// For controlled components we always need to ensure we're listening
483
456
// to onChange. Even if there is no listener.
484
- ensureListeningTo ( rootContainerElement , 'onChange' ) ;
485
457
break ;
486
458
case 'option' :
487
459
ReactDOMFiberOption . validateProps ( domElement , rawProps ) ;
@@ -490,18 +462,14 @@ export function setInitialProperties(
490
462
case 'select' :
491
463
ReactDOMFiberSelect . initWrapperState ( domElement , rawProps ) ;
492
464
props = ReactDOMFiberSelect . getHostProps ( domElement , rawProps ) ;
493
- trapBubbledEvent ( TOP_INVALID , domElement ) ;
494
465
// For controlled components we always need to ensure we're listening
495
466
// to onChange. Even if there is no listener.
496
- ensureListeningTo ( rootContainerElement , 'onChange' ) ;
497
467
break ;
498
468
case 'textarea' :
499
469
ReactDOMFiberTextarea . initWrapperState ( domElement , rawProps ) ;
500
470
props = ReactDOMFiberTextarea . getHostProps ( domElement , rawProps ) ;
501
- trapBubbledEvent ( TOP_INVALID , domElement ) ;
502
471
// For controlled components we always need to ensure we're listening
503
472
// to onChange. Even if there is no listener.
504
- ensureListeningTo ( rootContainerElement , 'onChange' ) ;
505
473
break ;
506
474
default :
507
475
props = rawProps ;
@@ -539,7 +507,6 @@ export function setInitialProperties(
539
507
default :
540
508
if ( typeof props . onClick === 'function ') {
541
509
// TODO: This cast may not be sound for SVG, MathML or custom elements.
542
- trapClickOnNonInteractiveElement ( ( ( domElement : any ) : HTMLElement ) ) ;
543
510
}
544
511
break ;
545
512
}
@@ -590,7 +557,6 @@ export function diffProperties(
590
557
typeof nextProps . onClick === 'function'
591
558
) {
592
559
// TODO: This cast may not be sound for SVG, MathML or custom elements.
593
- trapClickOnNonInteractiveElement ( ( ( domElement : any ) : HTMLElement ) ) ;
594
560
}
595
561
break ;
596
562
}
@@ -627,13 +593,6 @@ export function diffProperties(
627
593
// Noop
628
594
} else if ( propKey === AUTOFOCUS ) {
629
595
// Noop. It doesn't work on updates anyway.
630
- } else if ( registrationNameModules . hasOwnProperty ( propKey ) ) {
631
- // This is a special case. If any listener updates we need to ensure
632
- // that the "current" fiber pointer gets updated so we need a commit
633
- // to update this element.
634
- if ( ! updatePayload ) {
635
- updatePayload = [ ] ;
636
- }
637
596
} else {
638
597
// For all other deleted properties we add it to the queue. We use
639
598
// the whitelist in the commit phase instead.
@@ -711,29 +670,15 @@ export function diffProperties(
711
670
) {
712
671
( updatePayload = updatePayload || [ ] ) . push ( propKey , '' + nextProp ) ;
713
672
}
673
+ } else if ( propKey [ 0 ] === 'o' && propKey [ 1 ] === 'n' ) {
674
+ // @TODO (philipp): Find out why this is not handled by default. How are
675
+ // regular prop updates handled?
676
+ ( updatePayload = updatePayload || [ ] ) . push ( propKey , nextProp ) ;
714
677
} else if (
715
678
propKey === SUPPRESS_CONTENT_EDITABLE_WARNING ||
716
679
propKey === SUPPRESS_HYDRATION_WARNING
717
680
) {
718
681
// Noop
719
- } else if ( registrationNameModules . hasOwnProperty ( propKey ) ) {
720
- if ( nextProp != null ) {
721
- // We eagerly listen to this even though we haven't committed yet.
722
- if ( __DEV__ && typeof nextProp !== 'function' ) {
723
- warnForInvalidEventListener ( propKey , nextProp ) ;
724
- }
725
- ensureListeningTo ( rootContainerElement , propKey ) ;
726
- }
727
- if ( ! updatePayload && lastProp !== nextProp ) {
728
- // This is a special case. If any listener updates we need to ensure
729
- // that the "current" props pointer gets updated so we need a commit
730
- // to update this element.
731
- updatePayload = [ ] ;
732
- }
733
- } else {
734
- // For any other property we always add it to the queue and then we
735
- // filter it out using the whitelist during the commit.
736
- ( updatePayload = updatePayload || [ ] ) . push ( propKey , nextProp ) ;
737
682
}
738
683
}
739
684
if ( styleUpdates ) {
@@ -835,54 +780,38 @@ export function diffHydratedProperties(
835
780
switch ( tag ) {
836
781
case 'iframe ':
837
782
case 'object ':
838
- trapBubbledEvent ( TOP_LOAD , domElement ) ;
839
783
break ;
840
784
case 'video ':
841
785
case 'audio ':
842
786
// Create listener for each media event
843
- for ( let i = 0 ; i < mediaEventTypes . length ; i ++ ) {
844
- trapBubbledEvent ( mediaEventTypes [ i ] , domElement ) ;
845
- }
846
787
break ;
847
788
case 'source ':
848
- trapBubbledEvent ( TOP_ERROR , domElement ) ;
849
789
break ;
850
790
case 'img ':
851
791
case 'image ':
852
792
case 'link ':
853
- trapBubbledEvent ( TOP_ERROR , domElement ) ;
854
- trapBubbledEvent ( TOP_LOAD , domElement ) ;
855
793
break ;
856
794
case 'form ':
857
- trapBubbledEvent ( TOP_RESET , domElement ) ;
858
- trapBubbledEvent ( TOP_SUBMIT , domElement ) ;
859
795
break ;
860
796
case 'details ':
861
- trapBubbledEvent ( TOP_TOGGLE , domElement ) ;
862
797
break ;
863
798
case 'input ':
864
799
ReactDOMFiberInput . initWrapperState ( domElement , rawProps ) ;
865
- trapBubbledEvent ( TOP_INVALID , domElement ) ;
866
800
// For controlled components we always need to ensure we're listening
867
801
// to onChange. Even if there is no listener.
868
- ensureListeningTo ( rootContainerElement , 'onChange' ) ;
869
802
break ;
870
803
case 'option ':
871
804
ReactDOMFiberOption . validateProps ( domElement , rawProps ) ;
872
805
break ;
873
806
case 'select ':
874
807
ReactDOMFiberSelect . initWrapperState ( domElement , rawProps ) ;
875
- trapBubbledEvent ( TOP_INVALID , domElement ) ;
876
808
// For controlled components we always need to ensure we're listening
877
809
// to onChange. Even if there is no listener.
878
- ensureListeningTo ( rootContainerElement , 'onChange' ) ;
879
810
break ;
880
811
case 'textarea ':
881
812
ReactDOMFiberTextarea . initWrapperState ( domElement , rawProps ) ;
882
- trapBubbledEvent ( TOP_INVALID , domElement ) ;
883
813
// For controlled components we always need to ensure we're listening
884
814
// to onChange. Even if there is no listener.
885
- ensureListeningTo ( rootContainerElement , 'onChange' ) ;
886
815
break ;
887
816
}
888
817
@@ -944,13 +873,6 @@ export function diffHydratedProperties(
944
873
updatePayload = [ CHILDREN , '' + nextProp ] ;
945
874
}
946
875
}
947
- } else if ( registrationNameModules . hasOwnProperty ( propKey ) ) {
948
- if ( nextProp != null ) {
949
- if ( __DEV__ && typeof nextProp !== 'function' ) {
950
- warnForInvalidEventListener ( propKey , nextProp ) ;
951
- }
952
- ensureListeningTo ( rootContainerElement , propKey ) ;
953
- }
954
876
} else if (
955
877
__DEV__ &&
956
878
// Convince Flow we've calculated it (it's DEV-only in this method.)
0 commit comments