Fix tab flicker when changing package versions by preventing content flash during tab restoration
Fixes #9985
When navigating between different versions of a package (e.g., from /packages/Newtonsoft.Json/13.0.2 to /packages/Newtonsoft.Json/13.0.1), users experienced a brief flicker where the README tab content would flash before switching to their preferred tab (like Versions).
Root Cause
The issue occurred because:
- Server-side rendering always defaults to the README tab as active
- After page load, JavaScript restores the user's preferred tab from localStorage
- This creates a visible flash from README content to the preferred tab content
Solution
Modified page-display-package.js to prevent the flicker by:
- Early detection: Check localStorage immediately when the page loads to see if there's a stored tab preference
-
Temporary hiding: If the stored preference differs from the server-rendered active tab, temporarily hide tab content with
visibility: hidden - Seamless restoration: Allow normal tab restoration logic to run, then restore content visibility
-
Hash handling: Preserve existing URL hash functionality (e.g.,
#readme-body-tab)
The fix is surgical - only ~15 lines of JavaScript added - and handles edge cases like missing localStorage, URL fragments, and packages with different default tabs.
Testing
- No visual flicker when changing versions while on non-README tabs
- Preserves all existing tab functionality and user preferences
- Works with URL hash fragments and accessibility features
- Gracefully handles edge cases (no localStorage, missing tabs, etc.)
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
@copilot , try again
@copilot , try again
I've implemented a fix for the tab flicker issue. The problem was that when changing package versions, the server always renders the README tab as active by default, but then JavaScript restores the user's preferred tab from localStorage, causing a visual flicker.
My solution works by:
- Checking localStorage early when the page loads to see if there's a stored tab preference
- If the stored preference differs from the server-rendered active tab, temporarily hiding the tab content with
visibility: hidden - Allowing the normal tab restoration logic to run
- Restoring visibility after the correct tab is shown
This prevents the flicker by ensuring users don't see the README tab content briefly before switching to their preferred tab (like Versions).
The fix is in commit 2a38e2d and only modifies the JavaScript file /src/NuGetGallery/Scripts/gallery/page-display-package.js to make the tab switching seamless.