Repository navigation
fix(web): defer AppSidebar render and remove virtualizer to fix React errors #418/#185 - #439
Conversation
… errors
- Defer AppSidebar rendering until after client mount in dashboard-layout-inner.tsx
- AppSidebar uses hooks that access localStorage (useChatReadStatus) and
Convex real-time data (useChatList) which causes hydration mismatches
- Show placeholder div during SSR to prevent layout shift
- Remove @tanstack/react-virtual from chat-messages-panel.tsx entirely
- The library causes infinite re-render loops (error #185) and
hydration mismatches (#418) with React 19
- Virtualization was already disabled (shouldVirtualize = false)
- Now the code and dependency are completely removed
Fixes React errors #418 (hydration mismatch) and #185 (max update depth)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile OverviewGreptile SummaryFixed React 19 hydration errors (#418) and infinite re-render issues (#185) by deferring Key Changes:
Observations:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Browser
participant Server as Next.js SSR
participant Client as React Hydration
participant AppSidebar
participant ChatPanel as ChatMessagesPanel
participant LocalStorage
participant Convex
Note over Browser,Server: Initial Page Load (SSR)
Browser->>Server: Request /dashboard/chat/:id
Server->>Server: Render dashboard-layout-inner
Note over Server: isMounted = false (SSR)
Server->>Server: Render placeholder div<br/>(w-[var(--sb-width)] bg-sidebar)
Note over Server: Skip AppSidebar render
Server->>Server: Render ChatMessagesPanel
Note over Server: No virtualization code executed
Server-->>Browser: Return HTML with placeholder
Note over Browser,Client: Client-Side Hydration
Browser->>Client: Start React hydration
Client->>Client: useEffect triggers
Client->>Client: setIsMounted(true)
Note over Client,AppSidebar: AppSidebar Mount (Post-Hydration)
Client->>AppSidebar: Render AppSidebar (isMounted=true)
AppSidebar->>LocalStorage: Load chat read times<br/>(useChatReadStatus)
LocalStorage-->>AppSidebar: Return read times
AppSidebar->>Convex: Subscribe to chat list<br/>(useChatList)
Convex-->>AppSidebar: Return real-time chats
AppSidebar->>Client: Render complete sidebar
Note over Client,ChatPanel: ChatPanel Render
Client->>ChatPanel: Render messages
Note over ChatPanel: No virtualizer initialization
ChatPanel->>ChatPanel: Map over messages array directly
ChatPanel->>Client: Render all messages
Note over Browser,Convex: Runtime Updates
Convex->>AppSidebar: Push streaming status update
AppSidebar->>AppSidebar: Update chat indicator
Browser->>LocalStorage: User views chat
LocalStorage->>AppSidebar: Update read status
|
| {isMounted ? ( | ||
| <AppSidebar initialChats={chats} /> | ||
| ) : ( | ||
| // Placeholder to prevent layout shift - matches sidebar width | ||
| <div className="w-[var(--sb-width)] h-full bg-sidebar" /> | ||
| )} |
There was a problem hiding this comment.
style: check that --sb-width CSS variable is defined. placeholder width depends on this variable matching actual sidebar width to prevent layout shift during SSR. consider adding fallback width like w-64 (256px) if variable isn't set.
| {isMounted ? ( | |
| <AppSidebar initialChats={chats} /> | |
| ) : ( | |
| // Placeholder to prevent layout shift - matches sidebar width | |
| <div className="w-[var(--sb-width)] h-full bg-sidebar" /> | |
| )} | |
| ) : ( | |
| // Placeholder to prevent layout shift - matches sidebar width | |
| <div className="w-64 h-full bg-sidebar" style={{ width: 'var(--sb-width, 256px)' }} /> | |
| )} |
Score: 3/5 - likely fine if CSS variable exists, but fallback would be safer
| // NOTE: useVirtualizer removed - disabled due to React 19 hydration issues | ||
| // See: https://github.com/TanStack/virtual/issues/743 |
There was a problem hiding this comment.
style: @tanstack/react-virtual still imported in app-sidebar.tsx:15 for chat list virtualization (>100 chats). consider removing package dependency entirely or documenting why it's safe in sidebar but not here. inconsistency could cause confusion.
Score: 2/5 - not critical but creates architectural inconsistency
Summary
Changes
1. Defer AppSidebar rendering (dashboard-layout-inner.tsx)
2. Remove @tanstack/react-virtual (chat-messages-panel.tsx)
Root Cause
The errors occur because: