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

FlatTermSelector: Set Correct Loading State #13758

Merged
merged 2 commits into from
Feb 13, 2019

Conversation

tfrommen
Copy link
Member

@tfrommen tfrommen commented Feb 8, 2019

Description

If the FlatTermSelector component mounts with one or more terms provided, it does not correctly set the internal loading state.

How has this been tested?

Edit a post that has no tags assigned, and edit one that does have one tag assigned (see Screenshots).

Screenshots

Showing a post with one tag assigned.

Before:
flattermselector_before

After:
flattermselector_after

Types of changes

This change correctly sets the internal loading state when mounting.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@gziolo gziolo added this to the 5.1 (Gutenberg) milestone Feb 8, 2019
@gziolo gziolo added General Interface Parts of the UI which don't fall neatly under other labels. [Type] Bug An existing feature does not function as intended Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code labels Feb 8, 2019
@@ -78,7 +78,7 @@ class FlatTermSelector extends Component {

componentDidMount() {
if ( ! isEmpty( this.props.terms ) ) {
this.setState( { loading: false } );
this.setState( { loading: true } );
Copy link
Member

Choose a reason for hiding this comment

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

Hi @tfrommen thank you for your PR. Would it work if we set the loading state true when ! isEmpty( this.props.terms ) on the constructor instead of on componentDidMount? The reason being we would avoid an unnecessary rerender that happens when setting state via componentDidMount.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @jorgefilipecosta - hm, sure, I could do that. And I understand your reasoning.

On the other hand, it somehow feels a bit strange to split the actual loading logic (including the subsequent loading: false) from the part where we set the loading state to be true (in the constructor). 🤔 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

Hi @tfrommen,
On the constructor, we are initializing the state to false loading: false,. I don't think it is wrong to initialize to true or false depending on if this.props.terms is empty or not. If terms exist we know that the component will start the loading process.
Basically, we would set the loading on the constructor and unset the loading when the request is finished, I agree the code would look better if this logical parts were together but given the performance reason I think the separation is ok.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jorgefilipecosta updated as per your feedback.

Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thank you for iteracting on this @tfrommen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
General Interface Parts of the UI which don't fall neatly under other labels. Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants