Below is from Page 6 of IRS Pub 523 Selling Your Home, Does Your Home Qualify for a Partial Exclusion of Gain?:
Work-Related Move You meet the requirements for a partial exclusion if any of the following events occurred during your time of ownership and residence in the home.
•You took or were transferred to a new job in a work lo-cation at least 50 miles farther from the home than your old work location.
More explanation from Journal of Accountancy:
REDUCED EXCLUSION SAFE HARBORS
Employment . Treas. Reg. §§ 1.121- 3(c)(1) and (2) provide that a sale or exchange is by reason of a change in place of employment if (1) the change occurs during the period when the taxpayer owns and uses the property as a principal residence and (2) the taxpayer’s or other qualified individual’s new place of employment is at least 50 miles farther from the residence sold or exchanged than was the former place of employment.
Based on the above, the move for employment needs to occur while you own and use the main home to qualify for the partial exclusion.
If you sell the house in Fall 2021 and move for employment in June 2022, you main home would be in a different location.
Hope this helps.
**Mark the post that answers your question by clicking on "Mark as Best Answer"