Skip to content

fix: Improve fast-click behavior#12966

Merged
tommoor merged 2 commits into
mainfrom
tommoor/navlink-fast-click-active
Jul 11, 2026
Merged

fix: Improve fast-click behavior#12966
tommoor merged 2 commits into
mainfrom
tommoor/navlink-fast-click-active

Conversation

@tommoor

@tommoor tommoor commented Jul 11, 2026

Copy link
Copy Markdown
Member

Subtle details in fast click behavior that prevent single frame flashes

  • Only one sidebar link can appear active during fast-click navigation. Previously each NavLink tracked its optimistic “pre-active” state locally
  • Removed the key={isActive ? "active" : "inactive"} remount hack and replaced it with an explicit guard on onActiveClick

Copilot AI review requested due to automatic review settings July 11, 2026 13:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves sidebar “fast-click” navigation behavior to avoid single-frame active-state flashes by deriving active matching from the pending navigation target before React Router’s location updates.

Changes:

  • Replaces per-link preActive state with a shared pending-navigation location used for active matching across all sidebar NavLinks.
  • Tracks whether the link was already active at mousedown to prevent onActiveClick from firing on fast-click navigations.
  • Removes forced remounting via key and wraps NavLink with mobx-react observer to react to pending-navigation state.
Comments suppressed due to low confidence (1)

app/components/Sidebar/components/NavLink.tsx:98

  • toLocation is recomputed on every render (and for string to it creates a fresh Location via createLocation). With the new handleMouseDown dependency list including toLocation, this can cause the callback to be recreated on unrelated re-renders and adds extra createLocation churn across many sidebar links.
  const toLocation = normalizeToLocation(
    resolveToLocation(to, currentLocation),
    currentLocation
  );

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +32 to +38
// The target of a fast-click navigation, shared between all NavLinks so that
// only links matching it can render as active before the location changes.
const pendingLocation = observable.box<Location | null>(null, { deep: false });

const setPendingLocation = action((location: Location | null) => {
pendingLocation.set(location);
});
@tommoor tommoor merged commit 3524427 into main Jul 11, 2026
12 checks passed
@tommoor tommoor deleted the tommoor/navlink-fast-click-active branch July 11, 2026 14:09
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