Invalidate selectedTabs only when necessary

(cherry picked from commit 95d31f07df9316685a04bde674e442fcd8a0f0df)