Fixed it
Now that I’m on the team, I was able to finally fix it. I added an AbortController to the debounced search function, so that it aborts any previous queries when a new one is made. This means that the search results are always relevant to what the user is currently typing.The
AbortController pattern is a lightweight way to cancel in-flight fetch requests. When a new keystroke fires before the previous request completes, the old request gets aborted and only the latest query’s results ever render.Open source
I prefer building and using open source software whenever possible, and this whole situation is a great example of why. With open source — when you encounter a bug or pain point, you can actually fix it yourself. Had this been an open source project during the year I was frustrated with the search race condition, I could have submitted a pull request with theAbortController fix and saved myself (and thousands of other users) the daily annoyance.
Instead, it remained a persistent irritation until I happened to join the company and gain access to the codebase. There’s something to be said for the immediate empowerment that comes with open source — though I understand why many companies choose different models for various business reasons.