Optimize provider update pill renders#3811
Conversation
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
| const navigate = useNavigate(); | ||
| const providers = useAtomValue(primaryServerProvidersAtom); | ||
| const [dismissedKeys, setDismissedKeys] = useState<ReadonlySet<string>>(() => new Set()); | ||
| const visibleAfterIso = useMountedIsoTimestamp(); |
There was a problem hiding this comment.
🟡 Medium sidebar/SidebarProviderUpdatePill.tsx:95
On sidebar remount or page reload, recently completed provider updates (succeeded/failed/unchanged) are silently filtered out and never shown to the user. visibleAfterIso is captured at component mount time via useMountedIsoTimestamp, and isRecentTerminalProvider only keeps terminal updates whose finishedAt is after that timestamp. But the providers in the server snapshot may have a finishedAt that is already in the past relative to mount — yet still represents a newly completed update the user hasn't been notified about. The result is the pill never appears for those updates after a remount. Consider deriving the cutoff from the providers' own timestamps (e.g. the latest prior checkedAt) rather than from the component mount clock, so updates that completed before mount are still shown.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/web/src/components/sidebar/SidebarProviderUpdatePill.tsx around line 95:
On sidebar remount or page reload, recently completed provider updates (succeeded/failed/unchanged) are silently filtered out and never shown to the user. `visibleAfterIso` is captured at component mount time via `useMountedIsoTimestamp`, and `isRecentTerminalProvider` only keeps terminal updates whose `finishedAt` is after that timestamp. But the providers in the server snapshot may have a `finishedAt` that is already in the past relative to mount — yet still represents a newly completed update the user hasn't been notified about. The result is the pill never appears for those updates after a remount. Consider deriving the cutoff from the providers' own timestamps (e.g. the latest prior `checkedAt`) rather than from the component mount clock, so updates that completed before mount are still shown.
What Changed
pendingView, dismiss-after-exit key) into refs so it does not schedule additional renders.Why
react-doctorflaggedSidebarProviderUpdatePillfor redundant effect-driven state and state used only in handlers. The old mount path did extra commits to mirror provider timestamps and seed rendered state. After the fix, the targetedSidebarProviderUpdatePillfindings are gone: react-doctor issue count dropped from 162 to 158 overall, andState only used in handlersdropped from 6 to 4 with no remaining hit in this component.React Scan proof:
react_scan_provider_pill_before.mp4— 5 identical remounts ended at 10 Profiler commits.react_scan_provider_pill_after.mp4— the same 5 remounts ended at 5 Profiler commits.UI Changes
No intended visual UI change. The recordings demonstrate the render behavior change with React Scan enabled.
Checklist
Validation:
corepack pnpm --filter @t3tools/web exec tsgo --noEmitcorepack pnpm dlx react-doctor@latest . --verbose --category performance --no-telemetry(expected non-zero due to remaining unrelated findings)NODE_OPTIONS="--experimental-strip-types" corepack pnpm exec vp checkcorepack pnpm exec vp run typecheckNote
Optimize
SidebarProviderUpdatePillrenders by replacing state with refs and a mount-time timestampvisibleAfterIsostate (derived from providers'checkedAtvalues) with auseMountedIsoTimestamphook that captures a stable ISO timestamp at mount time, sogetProviderUpdateSidebarPillViewis called with a fixed reference point.pendingViewanddismissAfterExitKeystate variables withuseRef-backed equivalents, avoiding intermediate re-renders during exit transitions.useProviderUpdateRenderedViewSynchronizationanduseProviderUpdateAutoDismisscustom hooks in SidebarProviderUpdatePill.tsx.checkedAttimestamp.📊 Macroscope summarized bd8657a. 1 file reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
🗂️ Filtered Issues
No issues evaluated.