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

Specify fallback value for post visibility password #1923

Closed
wants to merge 1 commit into from

Conversation

aduth
Copy link
Member

@aduth aduth commented Jul 17, 2017

This pull request resolve a warning which occurs when setting the post visibility to "Password protected".

Warning: A component is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://fb.me/react-controlled-components

Implementation notes:

The issue occurs because when a post does not have a password, the getEditedPostAttribute selector returns undefined. React treats an undefined input value as an "uncontrolled" input, meaning it should never thereafter have a value explicitly assigned. Since the behavior of the input is otherwise controlled (has onChange specified to assign value into state) we should instead treat the input as controlled.

An alternate solution is to change the behavior of getEditedPostAttribute to return null if the value is not assigned. This may be preferable, as null is a more accurate representation of "explicitly no value" vs. "not assigned" (https://stackoverflow.com/a/5076962).

Testing instructions:

Verify that no warning is shown in the developer tools console when changing to Password Protected visibility:

  1. Navigate to Gutenberg > New Post
  2. In the sidebar, click Public (Visibility)
  3. Select Password Protected
  4. Note that no warning is logged in the developer tools console

@aduth aduth added the General Interface Parts of the UI which don't fall neatly under other labels. label Jul 17, 2017
@jasmussen
Copy link
Contributor

Your testing instructions pass for me! 👍 👍

@aduth
Copy link
Member Author

aduth commented Jul 26, 2017

This was incidentally fixed by #1967, because new drafts have all fields defined for the post, including password (an empty string).

@aduth aduth closed this Jul 26, 2017
@aduth aduth deleted the fix/password-controlled branch July 26, 2017 20:39
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants