BUGFIX: Ensure that <DropDown/>
closes only after the current call-stack has been processed
#3322
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: #3305
The Problem
The behavior described in #3305 is a regression through #3211.
#3211 made sure that the
<Label/>
around the auto-publish checkbox is clickable. Normally, one would expect that clicking on the label would trigger a change in the corresponding checkbox input through event delegation.To illustrate that idea:
Clicking inside the
<DropDown.Contents/>
also causes the outer<DropDown/>
to close. Closing the<DropDown/>
means, that the<DropDown.Contents/>
are removed from the DOM.This update mechanism is handled by
React
in a way that is non-deterministic (at least to us it is). This means that sometimes the<DropDown.Contents/>
are removed before the Click event from the<Label/>
component reaches the corresponding checkbox input:The Solution
I lieu of
setImmediate
-support in browsers, I wrapped the toggling mechanism of the<DropDown/>
-component in asetTimeout(..., 0)
call.This makes sure that components inside the
<DropDown.Contents/>
will receive all events that are currently scheduled, before the<DropDown.Contents/>
are removed from the DOM.