Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Transition): schedule changes only on status change #4060

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/modules/Transition/Transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,17 @@ export default class Transition extends Component {
const durationType = TRANSITION_CALLBACK_TYPE[nextStatus]
const durationValue = normalizeTransitionDuration(duration, durationType)

clearTimeout(this.timeoutId)
this.timeoutId = setTimeout(
() => this.setState((state) => ({ status: state.nextStatus })),
durationValue,
)
this.timeoutId = setTimeout(() => this.setState({ status: nextStatus }), durationValue)
}

updateStatus = (prevState) => {
if (this.state.status !== this.state.nextStatus && this.state.nextStatus) {
Copy link
Member Author

@layershifter layershifter Sep 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous check does not have sense as we should trigger a timer on status change

this.handleStart(this.state.nextStatus)
if (prevState.status !== this.state.status) {
// Timeout should be cleared in any case as previous can lead set to unexpected `nextStatus`
clearTimeout(this.timeoutId)

if (this.state.nextStatus) {
this.handleStart(this.state.nextStatus)
}
}

if (!prevState.animating && this.state.animating) {
Expand Down
21 changes: 21 additions & 0 deletions test/specs/modules/Transition/Transition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,27 @@ describe('Transition', () => {
</Transition>,
)
})

it('is called after a render with visibility changes', (done) => {
// This test ensures that a setTimeout will not be cleared on a simple rerender
// /~https://github.com/Semantic-Org/Semantic-UI-React/issues/4059

const onComplete = sandbox.spy()

wrapperMount(
<Transition duration={200} onComplete={onComplete} transitionOnMount>
<p />
</Transition>,
)

setTimeout(() => {
wrapper.setProps({})
}, 100)
setTimeout(() => {
onComplete.should.have.been.calledOnce()
done()
}, 250)
})
})

describe('onHide', () => {
Expand Down