This can happen at particular resolutions when Vector legacy tabs have a custom CSS border/margin:
Switching from width() to outerWidth(true) will output the same value for the default Vector legacy CSS. But for wikis which have customized their CSS to give the tabs a border and/or margin, this will fix the issue where the tab is expanded and collapsed forever at particular resolutions.