This was causing some errors ever since we started using the ref in an event handler - I'm not entirely sure why the ref stops being valid, unless it's a lifecycle thing. But anyway, this seems to stop the error in testing.