Tarana, thank you for sharing your story. Organisations are losing valuable talent for precisely the reason you mentioned.
Those who go above and beyond need to be recognized and rewarded. Most managers fail in doing so.
I think one way to avoid it is to make your work visible by talking about it. It’s not boasting but ensuring others recognize your strengths and the value you bring to the table. If your manager isn’t doing it, probably worth a shot doing it yourself.