Skip to content

slot: avoid Overview flash on uncached slot navigation#709

Open
barnabasbusa wants to merge 4 commits into
masterfrom
bbusa/preserve-slot-tab-flicker-fix
Open

slot: avoid Overview flash on uncached slot navigation#709
barnabasbusa wants to merge 4 commits into
masterfrom
bbusa/preserve-slot-tab-flicker-fix

Conversation

@barnabasbusa
Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #708. With just that PR, navigating /slot/35#ptcVotes → next chevron → /slot/36#ptcVotes lands on the right tab, but on uncached page loads the browser briefly paints Overview before Bootstrap's .tab('show') fades over to the target — about 100ms of "flinch". Cached navigations don't show this.

The fix is in two parts:

  • Suppress the wrong pane during parse. A tiny inline <script> placed before the tab markup reads location.hash, sanitizes it, and injects a <style> rule into <head> that hides every #tabContent > .tab-pane and unhides only the target. Because the style is present while the parser is reading the panes, the browser's first paint already shows the right tab.
  • Keep Bootstrap state in sync, then clean up. The synchronous block after tabContent now also moves the nav-link.active / aria-selected state onto the target tab so Bootstrap's tab plugin agrees with what the user sees. On DOM-ready the override <style> is removed so subsequent tab clicks animate normally.

Stacked on top of #708. Merge that first.

Note: the diff is intentionally larger than the original fix; the bulk is the early CSS injection plus the expanded synchronous activation block needed to keep Bootstrap, the nav-link highlight, and the panes in agreement when the override style is removed.

Test plan

  • Hard-reload /slot/<N>#ptcVotes (or open from an incognito window) — PTC Votes is visible from the first paint, no Overview flash.
  • Click between several slots via the chevrons with #ptcVotes active — no flicker on any of them.
  • Click tabs after the page loads — Bootstrap's fade animation still works (not blocked by the injected style).
  • Browser back/forward across hash changes still activates the right tab.
  • Navigate to a slot where the previously-open tab doesn't exist (e.g. #ptcVotes on a slot without PTC votes) — brief blank then Overview, no stuck blank state.
  • JS disabled — page still renders (all panes visible, same as before).

Inject a <style> rule into <head> from a tiny early script that hides
every #tabContent > .tab-pane except the one matching location.hash, so
the browser's first paint already shows the correct tab. The synchronous
block after tabContent moves Bootstrap's active/show and aria-selected
state onto the target pane, and DOM-ready strips the override style so
subsequent tab clicks animate normally.
Base automatically changed from bbusa/preserve-slot-tab-on-nav to master May 21, 2026 09:40
@barnabasbusa barnabasbusa enabled auto-merge May 21, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants