-
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
Fix Link UI displaying out of sync results #57522
Conversation
Size Change: +102 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
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.
Looks good, the component should indeed call updateSuggestions
on value change, even when a request for old value is already running.
I think that #45806 merely refactored the already existing isUpdatingSuggestions
value, the bug was probably already there. But it's hard to tell after such a long time.
One thing that should be fixed is the onFocus
handler.
@@ -258,7 +250,6 @@ class URLInput extends Component { | |||
if ( | |||
value && | |||
! disableSuggestions && | |||
! this.state.isUpdatingSuggestions && |
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.
This onFocus
handler is the only place where state.isUpdatingSuggestions
does something useful: it prevents the REST request from being triggered on focus when there is another one already running.
Could be replaced with checking this.suggestionsRequest === null
. But first we need to start resetting this.suggestionsRequest
back to null
when the request is finished. That's not currently done.
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've used Promise.finally()
to reset this.suggestionsRequest
to null
and then conditionalised the focus logic based on that.
I tried everything I could think of to break this - it definitely fixes the issue for me. |
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.
This is looking good. I'm not sure if the 200ms debounce is the right number but that's outside of the scope of this PR anyway.
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.
Looks good to me now, thanks for addressing the feedback 👍
What?
Ensures requests to fetch link suggestions are kept in sync with the current value in the
<input>
used in the<URLInput>
component. Avoids value becoming out of sync with displayed results.This fixes a problem evidenced in the Link UI
<LinkControl>
component which may have been introduced in #45806.Fixes #56695
Why?
Currently it is possible to have a value in the Link Control which is out of sync with the results being displayed. This is most obvious when the "Create page" option is displayed as it's possible to have the text of the Page being offered for creation to be out of sync with the value shown in the
<input>
.We always want the search results to be reflective of whatever is typed into the input by the user, even if that means more fetch requests are dispatched overall.
How?
Removes unwanted state which has historically been used to "block" additional fetch requests being dispatched when the input value changes if a current request is in progress.
After some investigation I realised that this state is not serving the component well. Currently if you type in the input (the initial search) and a fetch request gets dispatched (note: you have to wait for the
200ms
debounce) and then you immediately type something else there is only a request for the initial search query. The updated link value never triggers a fetch for search results because it is blocked by the state conditional.By removing this state, we allow the most recent value of the input to trigger a fetch request for search results. It is then this request which fulfills the search suggestons in the UI.
Race conditions are already handled as the code of
updateSuggestions
will abort in the.then/catch
if the current request is not the same as the request stored in the instance property.Testing Instructions
First on
trunk
ensure you can replicate the Issue.Then verify the fix in this PR:
wordpress is
then as soon as you see the loading spinner display, typeso cool
(note the specific text doesn't matter - you just need to ensure you type more text when the loading spinner first shows).Create: wordpress is so cool
.trunk
.Testing Instructions for Keyboard
Screenshots or screencast
Screen.Capture.on.2024-01-04.at.09-29-33.mp4