Fix timer callback triggering after timer is cleared #865
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes elastic/kibana#19285
We could get fancy and fix this specific situation through more coordination, or we can be defensive and just not trigger the callback if it's been removed. I opted for the second because of its simplicity and it addresses any related bugs that may occur in the future.
This also fixes a second bug where the toast's countdown is not restarted for the correct amount of time after the second hover.
what causes the error
When a toast managed by `EuiGlobalToastList` reaches the end of its timer, the timer self-clears and triggers the callback, beginning the process of fading out the element. The toast fade-and-remove can be laid out astimeout X
timeout X
happensThe bug as described in the kibana issue can happen by a 3rd event triggering between the timer's timeout and
timeout X
:EuiGlobalToastList
'sonMouseLeave
handler cycles through the known timers and callsresume
, re-creating their setTimeouts. The list of known timers at this point includes elements that are fading out, which have already completed their timers, and their callbacks have been removed.