File tree Expand file tree Collapse file tree 2 files changed +29
-7
lines changed
test/specs/modules/Transition Expand file tree Collapse file tree 2 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -87,16 +87,17 @@ export default class Transition extends Component {
8787 const durationType = TRANSITION_CALLBACK_TYPE [ nextStatus ]
8888 const durationValue = normalizeTransitionDuration ( duration , durationType )
8989
90- clearTimeout ( this . timeoutId )
91- this . timeoutId = setTimeout (
92- ( ) => this . setState ( ( state ) => ( { status : state . nextStatus } ) ) ,
93- durationValue ,
94- )
90+ this . timeoutId = setTimeout ( ( ) => this . setState ( { status : nextStatus } ) , durationValue )
9591 }
9692
9793 updateStatus = ( prevState ) => {
98- if ( this . state . status !== this . state . nextStatus && this . state . nextStatus ) {
99- this . handleStart ( this . state . nextStatus )
94+ if ( prevState . status !== this . state . status ) {
95+ // Timeout should be cleared in any case as previous can lead set to unexpected `nextStatus`
96+ clearTimeout ( this . timeoutId )
97+
98+ if ( this . state . nextStatus ) {
99+ this . handleStart ( this . state . nextStatus )
100+ }
100101 }
101102
102103 if ( ! prevState . animating && this . state . animating ) {
Original file line number Diff line number Diff line change @@ -419,6 +419,27 @@ describe('Transition', () => {
419419 </ Transition > ,
420420 )
421421 } )
422+
423+ it ( 'is called after a render with visibility changes' , ( done ) => {
424+ // This test ensures that a setTimeout will not be cleared on a simple rerender
425+ // https://github.com/Semantic-Org/Semantic-UI-React/issues/4059
426+
427+ const onComplete = sandbox . spy ( )
428+
429+ wrapperMount (
430+ < Transition duration = { 200 } onComplete = { onComplete } transitionOnMount >
431+ < p />
432+ </ Transition > ,
433+ )
434+
435+ setTimeout ( ( ) => {
436+ wrapper . setProps ( { } )
437+ } , 100 )
438+ setTimeout ( ( ) => {
439+ onComplete . should . have . been . calledOnce ( )
440+ done ( )
441+ } , 250 )
442+ } )
422443 } )
423444
424445 describe ( 'onHide' , ( ) => {
You can’t perform that action at this time.
0 commit comments