The valid class is only applied during the connection(when the mouse is down and the connection is successful). Once I release my mouse and the edge is created, the class goes away. Do you want the valid class applied during the connection or after its successful?
Also if you want the former and its not happening, can you check if removing the Custom Handle and replacing it with the default Handle component fixes the issue?