This used to be an in-game option, starting in Cataclysm, in the form of a slider named "Custom Lag Tolerance". It was unfortunately removed in Legion because it was deemed "too confusing".
Spell Queuing is a feature that allows several spells to be queued up on the server - so that they can be executed immediately with no delay, regardless of how high your latency is. This is a great feature introduced in patch 2.3.0 (TBC) and put an end to all casters needing to use /stopcasting macros and cast-bar latency indicators to perform properly. An unfortunate side-effect is that if you are a character with abilities that are cast very fast back-to-back, sometimes your character will perform attacks that you didn't want to.
As an example, Feral Druids with high haste, Heroism, and so on can sometimes cast 2x Shred instead of 1x Shred, even though you changed your mind and started mashing Ferocious Bite instead. This can be pretty annoying and can mess with your rotation. This is true for many other specs as well.
In Cataclysm, a slider was added in the game options to allow players to customize this timing window, and they recommended you put the slider to slightly above your actual latency. This worked well for some, and not for others. More specifically, it worked well for melee, but not for casters, or if adjusted higher, the opposite was true. It was hard to find a setting that worked well for both. The setting was (and still is) global, not per-character, making it annoying to set every time you re-log to a different character. This is why it was removed, presumably.
This WeakAura resolves all these problems by dynamically adjusting this spell queue window each time you log in OR change specs, to a value of your choice. See the aura Custom Options.
See https://github.com/azerothcore/azerothcore-wotlk/issues/9300 for larger discussion. A version of this definitely exists pre 4.0 they just made it more customisable in that patch. Added in 2.3.0.
https://github.com/Evolvee/Spell-Delay-Research/issues/1#issuecomment-443430545