Problem/Motivation

When typing in a text field that auto-generates a machine name, the server can be flooded with transliteration requests.

Quick steps to reproduce:

  • Create a new View and bring up the browser's debug console on the Network tab.
  • In the view name field, type something like "a long delay starts here" but type quickly, make a few mistakes, backspace to fix them, etc.
  • Notice the dozens of requests sent to the server
  • If you click the "Save & edit" button (or hit enter) before the final request has returned, you'll end up with an abbreviated view machine name.

Proposed resolution

Provide a minimum time (say, 250 milliseconds) between server requests and use cached values for transliteration requests that arrive during the "quiet time."

Remaining tasks

User interface changes

None.

API changes

None.

Original report by [username]

Originally raised in comment #36 of #1686174: Refactor machine-name.js.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeker’s picture

mikeker’s picture

Sorry, the previous patch builds on refactoring done in #1686174: Refactor machine-name.js. While it applies, this patch is against a clean D8 code.

nod_’s picture

Since we're adding things could you declare a Drupal.MachineName constructor and move all the extra stuff added to the behaviors object to that?

Also we have debounce and throttle available. You're reimplementing them basically, see the tableheader or the toolbar code for examples on how to use what we have.

mikeker’s picture

@nod_: And thanks for pointing me at debounce -- didn't realize that existed and it's probably a better way to handle this!

Just in case it's not, I've redone the previous patch using an object outside of Drupal.behaviors to store the data. Apologies, I saw your comment about that in the previous issue but forgot to add that. Patch and interdiff attached. (Note: also adds the ability for force the call to the server in case that's needed, sorry to clutter the interdiff).

Another issue raised while testing this is there is no ordering of the return values from the server. If one request takes longer than the next, an earlier server responses values overwrites more recent ones. But fixing that using debounce would be a more systemic change and may cause conflicts with #1686174: Refactor machine-name.js. If we go the debounce route and order the server replies, should that be part of the machine-name.js rewrite? I'm happy do the the patch in either place, but am worried about make more merge work for whichever patch goes in second.

Thoughts?

nod_’s picture

Status: Active » Closed (fixed)

It's debounced now.