This has a lot to do with a simplistic (and wrong) projection of the modern concept of patriotism/nationalism to medieval history.
Jogaila did what was good for his dynasty and himself personally, that's it. As an aristocrate he couldn't get a better deal.
Back then there was no concept of nations and nation-states, which only evolved a couple of centuries later. An aristrocrate inherited lands and a relatively week tie to his patron. No "nation" in the power equation. They could and did switch sides a lot, especially if that meant extra subordinates and a higher aristocracy rank.
Sadly, state-sponsored school textbooks always kind of skip this simple fact.
Jogaila did what was good for his dynasty and himself personally, that's it. As an aristocrate he couldn't get a better deal.
Back then there was no concept of nations and nation-states, which only evolved a couple of centuries later. An aristrocrate inherited lands and a relatively week tie to his patron. No "nation" in the power equation. They could and did switch sides a lot, especially if that meant extra subordinates and a higher aristocracy rank.
Sadly, state-sponsored school textbooks always kind of skip this simple fact.