I'm afraid, I don't really have the perfect answer. I think it really comes with practice and.. careful.. don't be scared.. discipline. ;) But that's way easier said than done, of course.
I wrote some articles that may cover this topic:
Personally, side projects helped me a lot to don't lose focus. When I find something, just one little thing, a tiny spark, that might interest me, I need to think of a side project I want to create totally by myself. That way I can learn on my own pace, dive deep or just scratch the surface, and stop whenever I want. To gain a deeper knowledge of the topic, of course, discipline comes to my mind again. But there is no boss telling you, you have to do this or learn that. You can manage your time all by yourself.
Hope this helps!
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.