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?
Command icon 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

fjgarlin created an issue. See original summary.

fjgarlin’s picture

Uploaded recording showing the issue.

bnjmnm’s picture

Issue tags: +Project Browser MVP

There'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.

hooroomoo’s picture

Assigned: Unassigned » hooroomoo

hooroomoo’s picture

StatusFileSize
new11.13 MB

Video with debouncer

hooroomoo’s picture

StatusFileSize
new4.61 MB

debounce video with 250 wait

hooroomoo’s picture

Status: Active » Needs review
hooroomoo’s picture

Assigned: hooroomoo » Unassigned
fjgarlin’s picture

Status: Needs review » Reviewed & tested by the community

Code 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!

narendrar’s picture

Status: Reviewed & tested by the community » Needs work

I think we can use something like

  let timer
  $: text && debouncedSearch()
  function debouncedSearch() {
    clearTimeout(timer)
    timer = setTimeout(onSearch, 500)
  }

and then
on:keyup={debouncedSearch()}
This will avoid use of core/drupal.debounce library. Thoughts?

bnjmnm’s picture

I don't see any reason we'd need to avoid the use of core/drupal.debounce library. 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.

fjgarlin’s picture

Totally 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.

bnjmnm’s picture

Status: Needs work » Reviewed & tested by the community

With 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.

chrisfromredfin made their first commit to this issue’s fork.

chrisfromredfin’s picture

I 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!)

chrisfromredfin’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.