Canadian leaving US after ending H1-B visa - capital gains tax implications

Canadian living in the US (NYC) for a decade, first on F-1 visa then currently on H1-B. I’ve made some significant unrealized capital gains and I want to understand the tax implications if I were to leave the US.

My understanding is that I won’t be subject to any exit tax if my H1-B visa ends because the exit tax only applies to citizens and green card holders.

 

If I realize my capital gains after having relocated and cut all my ties to the US would the IRS still consider me liable for the capital gains in the future? What about NY state? Obviously, I would be filing US taxes for 2021. Would i also have to report capital gains post-relocation in 2021? What about 2022?

 

Thanks a lot!