-
Notifications
You must be signed in to change notification settings - Fork 509
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
enable lazy auto-complete search and fallback to input while loading #3813
enable lazy auto-complete search and fallback to input while loading #3813
Conversation
Okay now I made it a little more controversial: I added some localStorage caching for the flex index as it was quite slow for me, and given that we don't do client-side navigation I'd expected users would have to reindex quite a lot. I'm not super happy yet with that async function inside of the persisting effect, so maybe that would benefit from another think. |
For the record, I think what you have here, apart from the My early measurements with Lighthouse clearly indicates a 7% decrease to the Lighthouse Performance score (when having the auto-complete part of the main JS bundle). So it's definitely ripe for more experimentation and tuning. |
Also, for the record, can you push your branch to |
Peter and I chatted about trying I've also pushed the branch onto this repo so we can deploy it. A TODO I still have on this is maintaining the correct selection when switching out the search widget. Currently it would just jump to the end of the inputValue when the components get switched out. |
…back # Conflicts: # client/src/ui/molecules/search/index.tsx
Here goes the build: https://github.com/mdn/yari/actions/runs/856570307 |
Alrighty, I added selection-retaining, though I have to admit that I could race-condition it into being a bit flaky. Have not found out yet why that is. I also made two other changes:
|
turns out I only got the prefix right there, not the branch. Rerunning it now! |
You were right @peterbe, it is a downshift bug. Maybe more of a "bug" than a bug, because it's the good old issue of semi-controlled inputs again, where the same state lives in multiple places. I won't bore you with details, but in the thread I found a workaround which seems to work. So there should be no more cases of mis-selection on this branch. |
(I just added a commit that does only load it onFocus but I'm only 65% convinced it's the right thing) |
I haven't actually looked at your code but I thought we kinda concluded that it's not worth doing. If you wait for |
Do you think you can look to delete whatever was typed after a I think the screencast is clear. BUT, I quite like that it stays if I don't pick a title but instead hit Enter to (full site-)search: |
By the way, I've tested it a bunch in BrowserStack. Works in Edge and Opera. |
@Gregoor This is getting soooooo close. Two things I just noticed. When you type something that the title search does not find a result for, you get this UI Unlike with the results list, there is no way to get to that link using the keyboard arrow keys for example. When you press the tab key, it moves focus to the submit button but, pressing enter(or clicking the button) does not actually trigger a site search either. |
Also, we need to add this little piece of SCSS for the input button’s active state: .search-button {
...
&:active {
background-color: transparent;
}
} Thank you! |
Updated to main and all the points addressed, except for....
Interesting! I thought this was a bug in the previous implementation, that the search term got deleted. But now that I think it more maybe the correct behavior is: delete when an item is clicked, but keep when it's a navigation to the |
That way previous searches are cleared
RIght. Agreed. Leave it on |
I think you switched from |
Bah. It's actually plenty fast as is even without |
Yeah I don't actually know why I went ahead with replacing |
We chatted about this at great length and we've concluded that the iOS Safari bug is real and it's blocking. Here are some interesting mentions of solutions:
Unfortunately, we have not been able to simulate the bug in any other way other than to test on an actual iPhone which is complicating things because you need to use desktop Safari to get access to web console logging from within the phone. One curious thing we discovered was that: useEffect(() => {
if (isFocused && inputRef.current) {
console.log("FORCING FOCUS");
inputRef.current.focus();
}
}, [isFocused]); Did not work, but: useEffect(() => {
if (isFocused && inputRef.current) {
console.log("FORCING FOCUS");
inputRef.current.focus();
alert("FORCED FOCUS"); // THIS silly debugging hack
}
}, [isFocused]); Perhaps the next action is to go through some of the hacks mentioned on that stack overflow post and see if it can be made to work with confidence. |
Because there's no other great place to discuss this; we should still consider to rewrite the whole thing. The reason we're doing these lazy on-demand loading is because |
Thanks for the summary Peter! I also want to mention the dirty-quick-fix: For mobile Safari we could start immediately loading the FancySearchWidget thereby making the chance of encountering this as small as you network is fast (and your fingers, you have to open a hamburger menu first). Imo this is not a terrible option, since TTI is still better than not lazy-loading it and data-restricted users tend not to be on iPhones. |
I like this a lot. It's less of a hack and more of a smart solution. Would you mind taking a quick look at the merge conflict we have now, before you leave, so the team after you (Florian, Schalk, myself) can give that one a shot in the next couple of weeks? |
Agreed, sounds like a reasonable assumption and solution. Could we merge this behind a flag and then work on the change in main? |
It's already behind a feature flag. In a sense. But this PR would change that a bit. I'd rather make the PR "good" before we consider merging it. |
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.
Let's do it!!
Inspired by #3719
Motivation
Every kb in the main bundle slows down every kind of interaction (due to added fetching, parsing, evaluation delay). We can lazy-load the autocomplete component and render a static input as a fallback. Users can already start typing into it or even press enter to submit a full-search.
If the auto-complete loads while they were typing, their input and focus state gets used inside of it so that it gets seemlessly swapped out.
Demo
Screen.Recording.2021-05-17.at.11.41.49.mov
What it does
It moves the input and focus state setting out of the auto-complete and into the root search component, that way it can share that state either with the dumb-input or the autocomplete, whichever is available.
How to test
Make the search lazy load slow and start typing in the search field before it has loaded.
a patch for slowing down lazy load