It's all matter of mindset, changing work and challenges often, learning something new and stay away from all non-core discussions, specially politics.
I think you're right. Another big aspect is the why behind getting into the industry. Myself, I ended up getting here entirely by accident. Ended up finding that I was good at it, and good at selling myself as a developer to employers.
But the reason I got into this wasn't because I had some idealistic reason behind it. I got into this because it provides a job that gives you the salary, mobility, and time to yourself that lets you do anything you want when you walk out of the office.
I love my job, I like doing software development, but for me it's never been about the ideals behind it. It's always been about what being a developer lets me do with my life.
Looking at it that way, there's really nothing to be disillusioned by.
i think at least people that learned it before 2000, they wanted to be computer scientists. Then after 2000, a lot of people just decided to be software developer because of the money. I belong to the first group. It makes me happy to stick to the bits and bytes and the hacker mentality that I had in the 90s. In another hand my wife is teacher and she has more reason to be disillusioned by her job than me :)
Ha. If money has little value to you, if you value only meaning, then there is nothing anyone can do to help you be happy in this profession. If you want to challenge yourself intellectually beyond the minutia you are out of luck. If you want respect you are out of luck. If you want power, you are out of luck. It's a dead end profession and hopefully it will be automated away soon with LLMs.
I'm 41 and been in the industry since early 20s. There is no intellectual challenge here, because there is no art to what you describe, just man hours.