There is an impassioned debate in the programming community about whether the right way to teach and learn this craft. It's probably been going on since the beginning of time. It usually boils down to whether we should teach the underlying fundamentals (data structures and algorithms) before moving onto the higher level industry abstractions (Ruby on Rails, ReactJs, etc.).
My position on the matter is that it does not matter as long as the student is engaged in the material. Sometimes it is up to the student (whether in solo learning or in a classroom setting) to make these choices, and sometimes that burden falls on the instructor.
But either way, here is what I know to be true: If you stick with it and stay curious, you will always learn what you need to learn. I can't say why that is. It just works out that way. The only way to fall off track is to lose interest, enthusiasm, or motivation. It's easy to lose interest, enthusiasm or motivation on your own. It's also easy for that to come from an outside source. For as many people as there are trying to lift you up and cheer you on, there are also the ones that want to tear you down. It's probably not a conscious effort on the part of these types. It's probably out of subconscious insecurity or projection, but those types exist.
Overcome these barriers, and you will learn what you need to learn. Programming is a never-ending series of aha moments until you look back and you realize that you're an experienced developer. The process of coding is actually quite anti-fragile in that every time you hit a major roadblock, you usually have to learn your way out of it. Your most frustrating pitfalls are also the things that propel you to the next level, unless you lose motivation. It's easy to lose momentum if you enter a downward spiral, but the only way to regain the mo' is to get back on the bicycle.
You don't need to worry if you are "specializing" too much because the deeper you go in a subject the more you need to learn about other subjects. If you are primarily trained as a front-end web developer, for example, you may feel nervous that you don't really understand what's going on under the hood. "I have no idea how any of this is happening under the hood. How am I ever going to truly become a great developer." This can be unnerving, but you don't need to go out of your way to learn the infinite things you don't know, they will come up naturally if you stay motivated and curious. There will come a time where something just isn't working right and you'll start tugging at the thread until you've unraveled the whole sweater. It's just what happens. Experienced developers can tell you this.
So focus on the task at hand, feed your curiosities and do whatever you need to do to stay motivated to put in the hours. The process takes years and you cannot rush it.