The main catalyst for leaving is pay. If i could find another company that would pay me more I'd present that to my current employer and if they couldnt match it then off I go. Usually I wait a while to start looking.
I saw one comment hear talking about maintenance and consequences and that's interesting! For myself, I gravitate to greenfield work. Startups and the like. Your code doesnt always live a long life in those environments and prehaps this shields me from the worst of the maintainability issues. Ive actually grown distasteful for to much "maintenance programming efforts" as I've seen months of such work disappear after a pivot (replaced a series of sequential forms with a table view once after the team spent months getting the forms right. Sad.) I believe that 'bad code' that takes you from 0 to 1 is a good headache to have. I've also seen people call code bad when i saw no issues with it (terria.js) and went on a months long run to rewrite a frontend months from release. Went about as well as expected. Code got written to replace already working code. No comment on whether it was better or not but my opinion is a likely no. There's a level of subjectivity to code quality that i think gets lost on people sometimes.