@@ -29,6 +29,7 @@ const noOpResponder = {
29
29
function createReactEventComponent ( ) {
30
30
return {
31
31
$$typeof : ReactSymbols . REACT_EVENT_COMPONENT_TYPE ,
32
+ displayName : 'TestEventComponent' ,
32
33
props : null ,
33
34
responder : noOpResponder ,
34
35
} ;
@@ -37,6 +38,7 @@ function createReactEventComponent() {
37
38
function createReactEventTarget ( ) {
38
39
return {
39
40
$$typeof : ReactSymbols . REACT_EVENT_TARGET_TYPE ,
41
+ displayName : 'TestEventTarget' ,
40
42
type : Symbol . for ( 'react.event_target.test' ) ,
41
43
} ;
42
44
}
@@ -392,6 +394,54 @@ describe('ReactFiberEvents', () => {
392
394
'Warning: validateDOMNesting: React event targets must not have event components as children.' ,
393
395
) ;
394
396
} ) ;
397
+
398
+ it ( 'should error with a component stack contains the names of the event components and event targets' , ( ) => {
399
+ let componentStackMessage ;
400
+
401
+ function ErrorComponent ( ) {
402
+ throw new Error ( 'Failed!' ) ;
403
+ }
404
+
405
+ const Test = ( ) => (
406
+ < EventComponent >
407
+ < EventTarget >
408
+ < span >
409
+ < ErrorComponent />
410
+ </ span >
411
+ </ EventTarget >
412
+ </ EventComponent >
413
+ ) ;
414
+
415
+ class Wrapper extends React . Component {
416
+ state = {
417
+ error : null ,
418
+ } ;
419
+
420
+ componentDidCatch ( error , errMessage ) {
421
+ componentStackMessage = errMessage . componentStack ;
422
+ this . setState ( {
423
+ error,
424
+ } ) ;
425
+ }
426
+
427
+ render ( ) {
428
+ if ( this . state . error ) {
429
+ return null ;
430
+ }
431
+ return < Test /> ;
432
+ }
433
+ }
434
+
435
+ ReactNoop . render ( < Wrapper /> ) ;
436
+ expect ( Scheduler ) . toFlushWithoutYielding ( ) ;
437
+
438
+ expect ( componentStackMessage . includes ( 'ErrorComponent' ) ) . toBe ( true ) ;
439
+ expect ( componentStackMessage . includes ( 'span' ) ) . toBe ( true ) ;
440
+ expect ( componentStackMessage . includes ( 'TestEventTarget' ) ) . toBe ( true ) ;
441
+ expect ( componentStackMessage . includes ( 'TestEventComponent' ) ) . toBe ( true ) ;
442
+ expect ( componentStackMessage . includes ( 'Test' ) ) . toBe ( true ) ;
443
+ expect ( componentStackMessage . includes ( 'Wrapper' ) ) . toBe ( true ) ;
444
+ } ) ;
395
445
} ) ;
396
446
397
447
describe ( 'TestRenderer' , ( ) => {
@@ -570,7 +620,7 @@ describe('ReactFiberEvents', () => {
570
620
error : null ,
571
621
} ;
572
622
573
- componentDidCatch ( error ) {
623
+ componentDidCatch ( error , errStack ) {
574
624
this . setState ( {
575
625
error,
576
626
} ) ;
@@ -734,6 +784,55 @@ describe('ReactFiberEvents', () => {
734
784
'Warning: validateDOMNesting: React event targets must not have event components as children.' ,
735
785
) ;
736
786
} ) ;
787
+
788
+ it ( 'should error with a component stack contains the names of the event components and event targets' , ( ) => {
789
+ let componentStackMessage ;
790
+
791
+ function ErrorComponent ( ) {
792
+ throw new Error ( 'Failed!' ) ;
793
+ }
794
+
795
+ const Test = ( ) => (
796
+ < EventComponent >
797
+ < EventTarget >
798
+ < span >
799
+ < ErrorComponent />
800
+ </ span >
801
+ </ EventTarget >
802
+ </ EventComponent >
803
+ ) ;
804
+
805
+ class Wrapper extends React . Component {
806
+ state = {
807
+ error : null ,
808
+ } ;
809
+
810
+ componentDidCatch ( error , errMessage ) {
811
+ componentStackMessage = errMessage . componentStack ;
812
+ this . setState ( {
813
+ error,
814
+ } ) ;
815
+ }
816
+
817
+ render ( ) {
818
+ if ( this . state . error ) {
819
+ return null ;
820
+ }
821
+ return < Test /> ;
822
+ }
823
+ }
824
+
825
+ const root = ReactTestRenderer . create ( null ) ;
826
+ root . update ( < Wrapper /> ) ;
827
+ expect ( Scheduler ) . toFlushWithoutYielding ( ) ;
828
+
829
+ expect ( componentStackMessage . includes ( 'ErrorComponent' ) ) . toBe ( true ) ;
830
+ expect ( componentStackMessage . includes ( 'span' ) ) . toBe ( true ) ;
831
+ expect ( componentStackMessage . includes ( 'TestEventTarget' ) ) . toBe ( true ) ;
832
+ expect ( componentStackMessage . includes ( 'TestEventComponent' ) ) . toBe ( true ) ;
833
+ expect ( componentStackMessage . includes ( 'Test' ) ) . toBe ( true ) ;
834
+ expect ( componentStackMessage . includes ( 'Wrapper' ) ) . toBe ( true ) ;
835
+ } ) ;
737
836
} ) ;
738
837
739
838
describe ( 'ReactDOM' , ( ) => {
@@ -1053,6 +1152,54 @@ describe('ReactFiberEvents', () => {
1053
1152
'Warning: validateDOMNesting: React event targets must not have event components as children.' ,
1054
1153
) ;
1055
1154
} ) ;
1155
+
1156
+ it ( 'should error with a component stack contains the names of the event components and event targets' , ( ) => {
1157
+ let componentStackMessage ;
1158
+
1159
+ function ErrorComponent ( ) {
1160
+ throw new Error ( 'Failed!' ) ;
1161
+ }
1162
+
1163
+ const Test = ( ) => (
1164
+ < EventComponent >
1165
+ < EventTarget >
1166
+ < span >
1167
+ < ErrorComponent />
1168
+ </ span >
1169
+ </ EventTarget >
1170
+ </ EventComponent >
1171
+ ) ;
1172
+
1173
+ class Wrapper extends React . Component {
1174
+ state = {
1175
+ error : null ,
1176
+ } ;
1177
+
1178
+ componentDidCatch ( error , errMessage ) {
1179
+ componentStackMessage = errMessage . componentStack ;
1180
+ this . setState ( {
1181
+ error,
1182
+ } ) ;
1183
+ }
1184
+
1185
+ render ( ) {
1186
+ if ( this . state . error ) {
1187
+ return null ;
1188
+ }
1189
+ return < Test /> ;
1190
+ }
1191
+ }
1192
+
1193
+ const container = document . createElement ( 'div' ) ;
1194
+ ReactDOM . render ( < Wrapper /> , container ) ;
1195
+
1196
+ expect ( componentStackMessage . includes ( 'ErrorComponent' ) ) . toBe ( true ) ;
1197
+ expect ( componentStackMessage . includes ( 'span' ) ) . toBe ( true ) ;
1198
+ expect ( componentStackMessage . includes ( 'TestEventTarget' ) ) . toBe ( true ) ;
1199
+ expect ( componentStackMessage . includes ( 'TestEventComponent' ) ) . toBe ( true ) ;
1200
+ expect ( componentStackMessage . includes ( 'Test' ) ) . toBe ( true ) ;
1201
+ expect ( componentStackMessage . includes ( 'Wrapper' ) ) . toBe ( true ) ;
1202
+ } ) ;
1056
1203
} ) ;
1057
1204
1058
1205
describe ( 'ReactDOMServer' , ( ) => {
0 commit comments