Problem/Motivation
When typing search terms, a new internal request is made for every character that is being typed, so searching for "Salesforce" will trigger 10 internal requests, only to use the last one.
Steps to reproduce
Open the developer tools and start typing terms in the search bar, you will see that each character typed triggers a new search.
Proposed resolution
Wait until the user has finished typing. Something like this: https://typeofnan.dev/how-to-execute-a-function-after-the-user-stops-typ... but I'm not sure if there is a svelte-recommended or drupal-recommended approach.
Remaining tasks
- ✅ File an issue about this project
- ☐ Manual Testing
- ☐ Code Review
- ☐ Accessibility Review
- ☐ Automated tests needed/written?
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | Screen Recording 2022-06-09 at 12.58.53 PM.mov | 4.61 MB | hooroomoo |
| #2 | Screen Recording 2022-06-08 at 12.24.40.mov | 2.05 MB | fjgarlin |
Issue fork project_browser-3284631
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
fjgarlin commentedUploaded recording showing the issue.
Comment #3
bnjmnmThere's a debouncer built into Drupal. I didn't spot any docs but this article and this other article + referencing other uses of debounce in core should provide guidance in figuring out how to incorporate this in the Svelte app.
I'm tagging "Project Browser MVP" - while it's not critical it get into the MVP, it sounds like something the group working on the MVP would have bandwidth to address and this will make it more visible to them.
Comment #4
hooroomooComment #6
hooroomooVideo with debouncer
Comment #7
hooroomoodebounce video with 250 wait
Comment #8
hooroomooComment #9
hooroomooComment #10
fjgarlin commentedCode is really clean and it improves the background calls firing without compromising the user experience. I tested and it all works well. I could type a whole world and it only made one request.
Marking RTBC, thanks!
Comment #11
narendrarI think we can use something like
and then
on:keyup={debouncedSearch()}This will avoid use of
core/drupal.debouncelibrary. Thoughts?Comment #12
bnjmnmI don't see any reason we'd need to avoid the use of
core/drupal.debouncelibrary. If the library was deprecated or we were using a tiny part of a large library, it might be worth looking for ways to not use it. In this case, its use seems appropriate as code>core/drupal.debounce does exactly what we need and nothing more + it is code that has been in core for several years and proven to perform solidly.Comment #13
fjgarlin commentedTotally agree with ^^. It's using a core component, which I think it's even desired, and the code is really clean and neat. Should it be back to RTBC or should we discuss it further? I'm not sure it needs more work.
Comment #14
bnjmnmWith a +1 in #13 I think it's OK to switch back to RTBC, and we'll let the committer make the final call.
There's been some other PB issues where we've actively avoided bringing in a core library because we'd only be using a small part of a rather large library, so I understand where @narendraR was likely coming from.
Comment #17
chrisfromredfinI think this is the right thing. Let's not reinvent the wheel if we have it in Drupal. I see Ben's point about bringing in a giant library for one piece of it, but especially in this case where the library is lightweight, it's the right thing.
Tested with it working, 250 feels good, confirmed the request happening. Much more of what I'd actually expect here.
(Thanks for the counterpoint narendraR!)
Comment #18
chrisfromredfin