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.

Still, it seems like an improvement.  ;)