Exactly how do you stop not losing interest because you suddenly realise you are just reinventing the wheel? On the contrary, how exactly do you generate interest in yak shaving because you know a solution is already out there and you should not waste your time?
For the specific topic of building a game engine, which I think fits the defintion of "yak shaving", it's fun because it relatively easy to do, there's a know set of things you need, each one is well known, each one can be done in steps, and each step shows progress, so it feels super productive, even if all you're doing is just reinventing the wheel. There might be 1000 steps but each one is small, well known, and doesn't require being all that novel. Conversely, game design is an open book and much much harder to feel like you made progress on each step.