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

[bugfix] Hide stale suggestions #2150

Merged
merged 18 commits into from
Feb 21, 2020
Merged

[bugfix] Hide stale suggestions #2150

merged 18 commits into from
Feb 21, 2020

Conversation

jimbo
Copy link
Contributor

@jimbo jimbo commented Feb 7, 2020

Description

Fix a bug with Suggestions wherein stale results would continue to be displayed when the field had been cleared. The proper fix would entail resetting the query, such that called would be false and data would be undefined, but Apollo does not yet offer that functionality. Instead, this fix recognizes when the field has been cleared and incorporates that into the conditional rendering logic of Autocomplete and Suggestions.

This fix involves changes to the talon APIs, so it's probably a major. As a result, I've also taken the opportunity to have SearchBar obtain history and location from hook calls rather than render props.

Related Issue

PWA-361

Acceptance

Verification Stakeholders

@dpatil-magento

Specification

Verification Steps

  1. Enter athena in the search input.
  2. Verify that suggested categories and products appear.
  3. Click the button to clear the search input.
  4. Verify that suggestions are no longer displayed, but a prompt is.

Screenshots / Screen Captures (if appropriate)

Checklist

  • I have updated the documentation accordingly, if necessary.
  • I have not yet added tests to cover my changes, if necessary.

@m2-community-project m2-community-project bot added this to Ready for Review in Pull Request Progress Feb 7, 2020
@jimbo jimbo added the version: Major This changeset includes incompatible API changes and its release necessitates a Major version bump. label Feb 7, 2020
@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Feb 7, 2020

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).
📖

Associated JIRA tickets: PWA-361.

Generated by 🚫 dangerJS against 229aa40

@sirugh sirugh changed the title Hide stale suggestions [bugfix] Hide stale suggestions Feb 7, 2020
Copy link
Contributor

@tjwiebell tjwiebell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good improvement, always thought that was just want UX wanted 😂 A few tiny things to clean up and this is good to go.

packages/peregrine/lib/talons/SearchBar/useAutocomplete.js Outdated Show resolved Hide resolved
packages/peregrine/lib/talons/SearchBar/useAutocomplete.js Outdated Show resolved Hide resolved
packages/peregrine/lib/talons/SearchBar/useSearchBar.js Outdated Show resolved Hide resolved
tjwiebell
tjwiebell previously approved these changes Feb 13, 2020
Copy link
Contributor

@tjwiebell tjwiebell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@dpatil-magento
Copy link
Contributor

dpatil-magento commented Feb 13, 2020

@jimbo I can still reproduce the issue in one case - Enter "Tops Dress" > Wait for suggestions and delete the entire input via delete key. Now click outside the textfield and click back in. Search suggestions are shown for "Tops"

https://i.gyazo.com/d2bffcb93e3404881ba00ca584570ad6.gif

@tjwiebell
Copy link
Contributor

tjwiebell commented Feb 13, 2020

@jimbo I can still reproduce the issue in one case - Enter "Tops Dress" > Wait for suggestions and delete the entire input via delete key. Now click outside the textfield and click back in. Search suggestions are shown for "Tops"

Looked at this with Dev; looks like its easiest to reproduce by holding down backspace to remove the search value.

@jimbo
Copy link
Contributor Author

jimbo commented Feb 14, 2020

@jimbo I can still reproduce the issue in one case - Enter "Tops Dress" > Wait for suggestions and delete the entire input via delete key. Now click outside the textfield and click back in. Search suggestions are shown for "Tops"

Looked at this with Dev; looks like its easiest to reproduce by holding down backspace to remove the search value.

This is so bizarre. I can replicate this with tops dresses but not with athena. I'll have to look into it.


// run the query once on mount, and again whenever state changes
useEffect(() => {
if (visible && valid) {
debouncedRunQuery({ variables: { inputText: value } });
} else if (called && !value && !visible) {
setCleared(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's happening is that as you delete the text of tops dresses the last "valid" search text is top which is used as the debounced query. That explains why you see product suggestions for top which are based on the last search data, but you don't see any text in the <input> in <Category> suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this by moving the setCleared logic into the debounced run query. The last call that executes should control the UI. In this case, we don't need to validate input before the debounce, we can do that inside the debounce, and if it is invalid we just clear the view.

Signed-off-by: Stephen Rugh <rugh@adobe.com>
@jimbo
Copy link
Contributor Author

jimbo commented Feb 19, 2020

@dpatil-magento I think this is fixed.

dpatil-magento
dpatil-magento previously approved these changes Feb 19, 2020
@m2-community-project m2-community-project bot moved this from Review in Progress to Reviewer Approved in Pull Request Progress Feb 19, 2020
@dpatil-magento
Copy link
Contributor

After clearing if I click back > stale results display for fraction of second and goes away.
https://gyazo.com/4d31b77f18f0c7f07b6b6c126b3dff4c

@dpatil-magento
Copy link
Contributor

Now the valid search suggestions also not displaying.

Image from Gyazo

@jimbo
Copy link
Contributor Author

jimbo commented Feb 20, 2020

@dpatil-magento I've fixed that issue. Please give it another test.

Important: we had logic that was reading the value of query from the URL and writing it to the search field. This logic was flawed and had a negative effect on the UX anyway, so after discussing it with @soumya-ashok, I removed this logic. As a result, if you navigate directly to the search page, it will no longer prepopulate the search field.

const debouncedRunQuery = useMemo(
() =>
debounce(inputText => {
runQuery({ variables: { inputText } });
Copy link
Contributor

@sirugh sirugh Feb 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now runs with the last 3 characters in the input when you start deleting some text value. For example "top shirt" will search "top shirt" but when you delete that character by character it'll query for "top" since it is the last valid value on the way to an empty string. Note that unlike the earlier bug it won't display the results because the display state of the results is based on the validity of the current input, not the last searched input.

I would prefer we don't make an extra call for text that may never be searched but it's also a minor optimization so 🤷

Copy link
Contributor

@sirugh sirugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1+1+1+1

@dpatil-magento
Copy link
Contributor

dpatil-magento commented Feb 21, 2020

@jimbo Looks good but still there is minor issue. Input dress wait for search suggestion to show, now clear the search field and enter Top > For fraction of seconds old search suggestions display and then new search suggestions.

Image from Gyazo

@jimbo
Copy link
Contributor Author

jimbo commented Feb 21, 2020

@jimbo Looks good but still there is minor issue. Input dress wait for search suggestion to show, now clear the search field and enter Top > For fraction of seconds old search suggestions display and then new search suggestions.

That's fine. We don't have any defined loading behavior yet, so it's going to show stale results while the next query is resolving.

@supernova-at supernova-at merged commit 6d9df6e into develop Feb 21, 2020
@m2-community-project m2-community-project bot moved this from Reviewer Approved to Done in Pull Request Progress Feb 21, 2020
@supernova-at supernova-at deleted the jimbo/talon-demo branch February 21, 2020 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:peregrine pkg:venia-ui version: Major This changeset includes incompatible API changes and its release necessitates a Major version bump.
Development

Successfully merging this pull request may close these issues.

None yet

6 participants