If you just move everything into the if (!pinned) block…

then it gets rid of the visual errors, but doesn’t let you re-order pinned tabs.
The next step would be to write an else clause that handled the pinned tabs.
Still, it seems like an improvement.  ;)