Skip to content

Commit

Permalink
Reset current request after completion and don’t fetch on focus
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Jan 4, 2024
1 parent 399163b commit 55bb1ef
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/block-editor/src/components/url-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ class URLInput extends Component {
this.setState( {
loading: false,
} );
} )
.finally( () => {
// If this is the current promise then reset the reference
// to allow for checking if a new request is made.
if ( this.suggestionsRequest === request ) {
this.suggestionsRequest = null;
}
} );

// Note that this assignment is handled *before* the async search request
Expand All @@ -247,10 +254,12 @@ class URLInput extends Component {

// When opening the link editor, if there's a value present, we want to load the suggestions pane with the results for this input search value
// Don't re-run the suggestions on focus if there are already suggestions present (prevents searching again when tabbing between the input and buttons)
// or there is already a request in progress.
if (
value &&
! disableSuggestions &&
! ( suggestions && suggestions.length )
! ( suggestions && suggestions.length ) &&
this.suggestionsRequest === null
) {
// Ensure the suggestions are updated with the current input value.
this.updateSuggestions( value );
Expand Down

0 comments on commit 55bb1ef

Please sign in to comment.