The limits are based on how much you earn in the entire tax year, not necessarily your salary at that time. If you get a substantial raise and find out that you've already over-contributed based on how much you'll earn for the year, you can either:
- withdraw the money (including any earnings attributable to it),
- recharacterize the excess contributions and move them to a traditional IRA, or
- apply your excess contribution to next year's Roth (you might still incur a 6% penalty for the current year)
If you haven't over-contributed yet, you can pause or slow down your contributions to make sure you don't go over the max for the year. It's common to leave a "buffer" at the end of the year and make a contribution to hit the max after you've gotten all of your income calculated for the prior year. You have until April 15th to make contributions fore the prior year.