@@ -478,4 +478,69 @@ describe('refs', () => {
478
478
render ( < App /> , scratch ) ;
479
479
expect ( el ) . to . not . be . equal ( null ) ;
480
480
} ) ;
481
+
482
+ it ( 'should not remove refs for memoized components keyed' , ( ) => {
483
+ const ref = createRef ( ) ;
484
+ const element = < div ref = { ref } > hey</ div > ;
485
+ function App ( props ) {
486
+ return < div key = { props . count } > { element } </ div > ;
487
+ }
488
+
489
+ render ( < App count = { 0 } /> , scratch ) ;
490
+ expect ( ref . current ) . to . equal ( scratch . firstChild . firstChild ) ;
491
+ render ( < App count = { 1 } /> , scratch ) ;
492
+ expect ( ref . current ) . to . equal ( scratch . firstChild . firstChild ) ;
493
+ render ( < App count = { 2 } /> , scratch ) ;
494
+ expect ( ref . current ) . to . equal ( scratch . firstChild . firstChild ) ;
495
+ } ) ;
496
+
497
+ it ( 'should not remove refs for memoized components unkeyed' , ( ) => {
498
+ const ref = createRef ( ) ;
499
+ const element = < div ref = { ref } > hey</ div > ;
500
+ function App ( props ) {
501
+ return < div > { element } </ div > ;
502
+ }
503
+
504
+ render ( < App count = { 0 } /> , scratch ) ;
505
+ expect ( ref . current ) . to . equal ( scratch . firstChild . firstChild ) ;
506
+ render ( < App count = { 1 } /> , scratch ) ;
507
+ expect ( ref . current ) . to . equal ( scratch . firstChild . firstChild ) ;
508
+ render ( < App count = { 2 } /> , scratch ) ;
509
+ expect ( ref . current ) . to . equal ( scratch . firstChild . firstChild ) ;
510
+ } ) ;
511
+
512
+ // TODO
513
+ it . skip ( 'should properly call null for memoized components keyed' , ( ) => {
514
+ const calls = [ ] ;
515
+ const element = < div ref = { x => calls . push ( x ) } > hey</ div > ;
516
+ function App ( props ) {
517
+ return < div key = { props . count } > { element } </ div > ;
518
+ }
519
+
520
+ render ( < App count = { 0 } /> , scratch ) ;
521
+ render ( < App count = { 1 } /> , scratch ) ;
522
+ render ( < App count = { 2 } /> , scratch ) ;
523
+ expect ( calls . length ) . to . equal ( 5 ) ;
524
+ expect ( calls ) . to . deep . equal ( [
525
+ scratch . firstChild . firstChild ,
526
+ null ,
527
+ scratch . firstChild . firstChild ,
528
+ null ,
529
+ scratch . firstChild . firstChild
530
+ ] ) ;
531
+ } ) ;
532
+
533
+ it ( 'should properly call null for memoized components unkeyed' , ( ) => {
534
+ const calls = [ ] ;
535
+ const element = < div ref = { x => calls . push ( x ) } > hey</ div > ;
536
+ function App ( props ) {
537
+ return < div > { element } </ div > ;
538
+ }
539
+
540
+ render ( < App count = { 0 } /> , scratch ) ;
541
+ render ( < App count = { 1 } /> , scratch ) ;
542
+ render ( < App count = { 2 } /> , scratch ) ;
543
+ expect ( calls . length ) . to . equal ( 1 ) ;
544
+ expect ( calls [ 0 ] ) . to . equal ( scratch . firstChild . firstChild ) ;
545
+ } ) ;
481
546
} ) ;
0 commit comments