Entity reference widget only works if you type slowly

Created on 3 June 2024, 5 months ago
Updated 5 July 2024, 3 months ago

Problem/Motivation

There seems to be an issue with the debounce logic. When I quickly type something, I get no results. Additionally, multiple console errors appear:

Error fetching data: DOMException: The operation was aborted.
handleAutocomplete https://whathappens.test/modules/contrib/tagify/js/tagify.js?v=1.0.11:273
onInput https://whathappens.test/modules/contrib/tagify/js/tagify.js?v=1.0.11:326
later https://whathappens.test/core/misc/debounce.js?v=10.2.4:37
setTimeout handler*Drupal.debounce/< https://whathappens.test/core/misc/debounce.js?v=10.2.4:42
trigger https://cdnjs.cloudflare.com/ajax/libs/tagify/4.26.0/tagify.min.js:1

Steps to reproduce

I made a screen recording to illustrate the issue. The first time around it doesn't happen, but the second time it does. I'm able to work around the issue by removing one character, waiting for the spinner to disappear, and re-entering the last character again. In that case results appear.

🐛 Bug report
Status

Needs work

Version

1.2

Component

Code

Created by

🇧🇪Belgium dieterholvoet Brussels

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @dieterholvoet
  • First commit to issue fork.
  • 🇪🇸Spain gxleano Cáceres

    Hi Dieter,

    I've been testing the issue, and everything works fine on my end. The browser console shows the AbortError when a request is aborted (e.g., when the input value doesn't match any suggestion and it has been typed quickly), but this error does not affect the behavior of the Tagify element.

    I will test this more carefully, but it should not be a big issue.

  • Status changed to Postponed: needs info 4 months ago
  • 🇧🇪Belgium dieterholvoet Brussels

    This one might also have been fixed in Add support for custom form-element supporting entity_reference Needs review . I applied that one as patch to my project and I'm running it on production now, will report back if this happens again.

  • Status changed to Active 4 months ago
  • 🇧🇪Belgium dieterholvoet Brussels

    Just tested and it's definitely still happening. Not all the time though, the problem is that it sometimes doesn't show results even though it should. Not sure if it matters, but I should probably note that I'm using Firefox.

  • 🇪🇸Spain gxleano Cáceres

    On Firefox with the Gin theme, the AbortError occurs every time I type at a normal speed—not too fast, not too slow.

    On Chrome is more difficult to reproduce it, but it is also reproducible using Claro as default theme.

    In both cases, the suggestion dropdown correctly shows all relevant content without any issues.

    See evidences:

    Claro - Chrome

    Gin - Firefox

  • 🇪🇸Spain gxleano Cáceres

    I've been checking between versions and 1.2.11 doesn't have the "bug", so the "bug" was definitely introduced here: https://www.drupal.org/project/tagify/releases/1.2.12 , but I need some time to debug it in depth.

  • 🇪🇸Spain gxleano Cáceres

    I've found the problem, seems like this is related with the wait time in the Drupal.debounce.

    @param {number} wait
      The time period within which the callback function should only be
      invoked once. For example if the wait period is 250ms, then the callback
      will only be called at most 4 times per second.

    We removed the wait parameter from the input in 1.2.12

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 4 months ago
    2 fail
  • Status changed to Needs review 4 months ago
  • 🇪🇸Spain gxleano Cáceres
  • Status changed to Needs work 4 months ago
  • 🇪🇸Spain gxleano Cáceres
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 4 months ago
    1 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 4 months ago
    2 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 4 months ago
    1 fail
  • Status changed to Needs review 4 months ago
  • 🇪🇸Spain gxleano Cáceres
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 4 months ago
    1 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 4 months ago
    1 fail
  • 🇧🇪Belgium dieterholvoet Brussels

    I tested all commits you did separately. A 250 wait time works, but honestly 50 feels a lot snappier/more fluent to me. Why did you change to 250?

  • 🇪🇸Spain gxleano Cáceres

    Hi Dieter,

    Thanks to take a look on this.

    If we set the wait time to 50ms in the debounce function, it is making the tests fail.

    See:

    @param {number} wait
      The time period within which the callback function should only be
      invoked once. For example if the wait period is 250ms, then the callback
      will only be called at most 4 times per second.

    I need to find some time to figure out how we can fix this in the best way.

  • 🇧🇪Belgium dieterholvoet Brussels

    Okay, I noticed 50 works great on my local environment, but it doesn't work on production. 250 works on both. This is probably a performance thing, depending on how long page loads take. In that case 250 is probably a safer bet - or maybe something in between. I'll try out some different values on production.

  • 🇧🇪Belgium dieterholvoet Brussels

    150 seems to work on both as well. I'll go for that value on my website right now, but maybe it would be best to make this configurable (or at least alterable through some hook) in order to improve responsiveness on faster sites.

  • 🇧🇪Belgium dieterholvoet Brussels

    Never mind, 150 still fails sometimes. 250 seems to be a good default.

  • Status changed to Needs work 3 months ago
  • 🇧🇪Belgium dieterholvoet Brussels

    It still fails randomly, depending on how fast you type, and the Error fetching data: DOMException: The operation was aborted errors still appear in the console. I feel like there's still something else going wrong, other than the configured timeout.

Production build 0.71.5 2024