That's been my go to the last couple cycles. It hasn't worked.
For instance, at my previous job, I wound up as essentially the only person on a team. In addition to performing the technical functions, I worked to build it back into a team. I created (and communicated) what my vision for that team was supposed to be, mapping out what we would do when it was reconstituted, and started training other people to do some of the functions.
After 6 months of what I was told was very impressive work, the reorg came. They decided to have another person lead that team, and swap somebody new in to the on paper non-lead role I had been filling. They put me in a different part of the team underneath somebody more junior who had no interest in managing as part of a general reorg.
That person also had no interest in working for the company even after the promotion, and left (part of an ongoing exoducs at that time). You'd think that would finally leave me as a team lead, but instead our team was explicitly left leaderless, with the next level (and architect of the reorg) theoretically picking up the slack.
This created a bit of a nightmare, because everyone expected me to be leading that team, but I was explicitly forbidden from doing so. I went from setting the direction for my own work to getting arbitrary tasks given to me. I wasn't looped in on or consulted about the general direction of the team, and it was far away from where I'd been so I didn't have any idea what the team (which had only recently been created) was supposed to be doing.
It was chaos and frustrating - people kept coming to me assuming I was leading, and I kept having to defer. I really don't understand what the point was of not allowing me to lead the team (and it was a very explicit choice), other than out of spite or some kind of built in bias. I really stopped caring at that point. When I left a couple months later my boss reminisced how my work had been so good but had dropped precipitously.
What's sad is the same thing happened at the previous job in a lot of ways. I did get made the team lead eventually, but at that point there literally was no team since the exodus was larger (all the non-contractor developers had left). Once again, I was the tail end of the exodus.
I keep at it. I'm always evangelizing improvements, trying to create a better environment for other employees, trying to work with the new ones, trying to find those places where there is opportunity to grow.
A lot of time, my suggestions get ignored, but I keep making them. I implement them anyway, they are well received. I get a pat on the back and told to work on something very different. I can't get excited about that something different and can only view it as an obstacle to be overcome before I can go back to pushing on the things I care about, and the loop begins.
I do only okay work on the things I don't care about, which is used to justify me staying in my position. I stop doing things that are beyond my role, because it seems pointless. I care less and less.
There's something about somebody getting promoted to the position you wanted and then using your 1 on 1s to complain about how much they hate the position that just kills me.
At some point the job starts to become entirely managing visibility, be it keeping meaningful projects under the radar so that they don't yoinked away, or promoting them mercilessly. I've been in one on ones where my boss tried to show me a list of things they wanted to see for me to get promoted, then realized they were describing exactly what I was doing, yoinked it away, and had to spend 6 months "refining" it.
If they do that enough times - if I spend enough time just playing these games trying to find some way to sneak through the cracks and do some actual refactoring or whatever it is, eventually I stop caring entirely. It starts to feel like it's all politics anyway, so why bother.
I get into an Office Space state - work my ass off, get a pat on the back, but make any mistakes and 5 people are asking why I didn't have test coverage for that case, why I copy pasted this code carelessly, whatever mistake I made when I was slacking.
I don't know how to break out of that state in any sense. I don't know how to recognize if the environment really IS discriminating against me, or I'm just letting laziness get the better of me. If I decide the latter I don't how to motivate myself to care like I used to.