Page MenuHomePhabricator

MediaSearch: Autocomplete is delayed - does not reflect user input
Closed, ResolvedPublic

Description

Split from @Etonkovidova comment on T256673

Note: The delay issue in displaying autocomplete happens only when search term are deleted with backspacing not with 'X' (the clear search button).

Steps to reproduce:

  • start typing 'Foun' - the autocomplete will be correctly present

Screen Shot 2020-09-02 at 9.16.33 AM.png (507×784 px, 46 KB)

  • then delete the entrywith the backspace button and type 'Lion' - the suggestions won't change.
    Screen Shot 2020-08-28 at 1.05.12 PM.png (455×746 px, 36 KB)
  • when 'Lion' is deleted, the autocomplete changes to show the autocomplete for 'L':

Screen Shot 2020-08-28 at 1.05.36 PM.png (492×763 px, 42 KB)

(the animated gif - click to open)
autocomplete1.gif (590×1 px, 203 KB)

Event Timeline

I've noticed this behavior as well. It happens not just when you type and delete, but if you type part of a word and wait for the suggestions, and then continue typing. The expected behavior here would be for the suggestions to be narrowed down as the user adds more characters.

If you click out of the input and then click back in, you will see suggestions that correctly reflect the full entered text.

This makes me think that the API requests are being made correctly, but we just aren't updating the UI at the correct moment. I'll take a look.

Change 624260 had a related patch set uploaded (by Eric Gardner; owner: Eric Gardner):
[mediawiki/extensions/WikibaseMediaInfo@master] Treat selectMenu's formattedItems as a computed property

https://gerrit.wikimedia.org/r/624260

I think I found the culprit:

This bug came from the fact that the SelectMenu component only generated a set of formattedItems (which control what the user sees in this dropdown) once, on first initialization. The results were stashed in component state. Afterwards, the component was still receiving new items props with new lookup results, but the "formattedItems" were never updated. Correct results would only be displayed after the component re-rendered due to focus changes.

The solution is to simply treat the formattedItems as a computed property rather than state. This way changes to the items prop will always result in a new set of formattedItems.

Change 624260 merged by jenkins-bot:
[mediawiki/extensions/WikibaseMediaInfo@master] Treat SelectMenu's formattedItems as a computed property

https://gerrit.wikimedia.org/r/624260