Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Prevent race conditions in focus management code #1631
The root cause of #1490 and other related uncaught TypeError bugs is a set of somewhat rare race conditions triggered by focus management methods (
I'm resolving this by consistently using RefHolders to store refs in the GitTabItem component tree. RefHolders force us to always explicitly handle the case when a ref is unavailable.
Note that there's still the risk of a focus event being ignored because of this. I thought about catching focus calls and playing them back later when refs do become available but I feel like that would cause a bunch of weird cases where we yank focus in undesirably because it's already moved elsewhere. The risk there is that you might have to click twice sometimes, I suppose?
I'm also very carefully not taking this opportunity to tackle reworking focus management holistically in a fancier, more React-friendly declarative style. Now is the time for band-aids!