NuGetGallery icon indicating copy to clipboard operation
NuGetGallery copied to clipboard

Fix tab flicker when changing package versions by preventing content flash during tab restoration

Open Copilot opened this issue 7 months ago • 2 comments

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:

  1. Server-side rendering always defaults to the README tab as active
  2. After page load, JavaScript restores the user's preferred tab from localStorage
  3. This creates a visible flash from README content to the preferred tab content

Solution

Modified page-display-package.js to prevent the flicker by:

  1. Early detection: Check localStorage immediately when the page loads to see if there's a stored tab preference
  2. Temporary hiding: If the stored preference differs from the server-rendered active tab, temporarily hide tab content with visibility: hidden
  3. Seamless restoration: Allow normal tab restoration logic to run, then restore content visibility
  4. 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 avatar Sep 04 '25 23:09 Copilot

@copilot , try again

skofman1 avatar Sep 05 '25 00:09 skofman1

@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:

  1. Checking localStorage early when the page loads to see if there's a stored tab preference
  2. If the stored preference differs from the server-rendered active tab, temporarily hiding the tab content with visibility: hidden
  3. Allowing the normal tab restoration logic to run
  4. 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.

Copilot avatar Sep 05 '25 00:09 Copilot