What if he's not actually the pope because of invalid ordination? Or heresy and apostasy?
Yes St. Anthony, this question is as old as sedeism itself and the answer is the same. It's almost like asking what if you are praying for a soul who is in hell. But for a more complete answer, I will quote Fr. Wathen...
Snip from Who Shall Ascend? (PDF Attached)
Here, one of the faithful is talking to a sede priest.....
"....I can see that it is not necessary for you or for me to know whether Pope John Paul (Francis) is the legitimate successor of St. Peter. It doesn't hurt anything to pray for him in the Mass; it surely could not be wrong to do so, even if it is an honest mistake. Pope or not, God knows that he who is called John Paul II (Francis) needs our prayers, as all of us need God's mercy. But to attack the office of the papacy, and to separate oneself from it, is a serious thing to be wrong about. But to attack the office of the papacy, and to separate oneself from it, is a serious thing to be wrong about.
This Sedevacantism is your opinion. But the Mass not yours, and I know you do not have the right to change a word of it. I have heard you say the same thing about those who brought in the New Mass. And now this is what you have done! You are not being fair, and, it seems to me, you are not being wise..."