-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Update/refactor url list #27559
Update/refactor url list #27559
Conversation
Also collect similar value state concerns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! It's a pretty complex component :)
I have checked most of the functions but needs more checking in lifecycle components. Let's address some of the comments and review again.
This allows other components to mock when is not directly under testing
hi @ntsekouras , thanks again for all the feedback. I got pulled away from this issue but I'm hoping to get back on it this week. I've pushed updates per your comments ( which were super helpful ) and I believe this is ready for a second look. I see a few e2e tests failing but they seem unrelated to these changes, I'd re-run to verify it's just a blinking test but I don't have access to do that yet. Thanks again. |
! this.isUpdatingSuggestions && | ||
! ( suggestions && suggestions.length ) | ||
! isUpdatingSuggestions() && | ||
! suggestions.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
! suggestions.length | |
! suggestions?.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this guard is needed. suggestions
is initialized to an empty array in a useState
call. There is one call to setSuggestions
with the result from the suggestions fetch but there is an truthy check before it's called. I'll add an Array.isArray
check on the result (length won't work here since we want to update suggestions if they are empty)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Array check in d5fe5e8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's okay with the check you added, but actually Array.isArray
catches null and undefined, so you need just this check without checking the plain result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional is something like result && Array.isArray( result )
which should prevent the setSuggestions
call with null or undefined. But I thought Array.isArray
will return false for null or undefined ? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray#using_array.isarray
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understood correctly but my comment was about result && Array.isArray( result )
being equivalent to Array.isArray(result)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see, I total misread your comment @ntsekouras , my bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work here @jhnstn! Thanks for refactoring this quite complicated component. 💯
I have left some small notes but this feels to be in good place. By testing I noticed a different behavior with the master
, which also feels like it should behave like it does here :) Other than that it LGTM.
The first part of the gif is from your branch and when I clear the search term
it shows the initial results. In master as you can see it doesn't (second part of gif).
It would be great for someone more experienced in class
components and especially getDerivedStateFromProps
part to take a look as well. @ellatrix if you have some time, I know you have done tons of such refactorings. This includes my two comments about wheter a useEffect
should be used.
[] | ||
); | ||
|
||
if ( prevInstanceId !== instanceId ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in a useEffect
? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, tbh I'm not sure since this logic is from the existing getDerivedStateFromProps
. I tried following back through the commit history to see why getDerivedStateFromProps
was being used but nothing jumped out. Then after some research on how to refactor getDerivedStateFromProps
to use hooks I noticed that folks are just comparing refs to state outside of useEffect
.
componentWillUnmount() { | ||
delete this.suggestionsRequest; | ||
} | ||
if ( showInitialSuggestionsChanged ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in a useEffect as well? 🤔
Thanks again @ntsekouras !
Interesting, I had scrutinized that behavior and I was fairly confident that I was seeing the same thing on master. Regardless I'll get those to match. |
Closing due to the changes going stale. Resolving the conflicts will likely take longer than starting a new PR |
Description
Part of #22890. Refactor the
URLInput
component to a functional component using hooks.How has this been tested?
Manually tested to make sure URL input behavior is consistent with existing behavior using #24089 as a guide.
Screenshots
Types of changes
Refactoring to use hooks.
Checklist: