This is partly because I live in a dense urban area with lots of tall buildings, my default action when I start having a loss of connectivity problem is to immediately command UP and stop everything else.
Keep in mind that the remote control has a “stronger” transmitter than the drone itself, (technically, more directional) so a loss of communication means that you were losing the signal from the drone first, but you should still have enough signal at that instant to command something with the joystick, and going up, you should regain contact fairly quickly.
Going straight up, is “usually” going to be a best practice.
The caveats are of course, if you’re flying around a lot of powerlines, going up might not be advisable, but flying around powerlines, and also not having line of sight is itself not advisable.
The other thing, is a matter of keeping situational awareness. Lack of situational awareness is one of the key factors that has led to many fatal accidents in general and commercial aviation. Situational awareness is not only where you are, and what is surrounding you, but the current state of your aircraft and control and so forth.