Repository navigation
fix: use headers() as fallback for cookie retrieval - #418
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile OverviewGreptile SummaryAdded Critical Issues Found:
Confidence Score: 1/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant SC as Server Component
participant RS as resolveUserContext
participant NH as Next.js headers()
participant NC as Next.js cookies()
participant Cache as Session Cache
participant API as /api/auth/get-session
SC->>RS: getUserContext()
RS->>NC: cookies()
NC-->>RS: allCookies[] (may be empty)
RS->>NH: headers().get('cookie')
NH-->>RS: rawCookieHeader (may be null)
alt rawCookieHeader exists
RS->>RS: cookieHeader = rawCookieHeader
Note over RS: ⚠️ Bug: allCookies stays empty
else rawCookieHeader is null
RS->>RS: cookieHeader = join(allCookies)
end
RS->>RS: Find session cookie in allCookies
Note over RS: ⚠️ Bug: sessionCookie undefined<br/>when rawCookieHeader used
alt cacheKey exists
RS->>Cache: Check cache with sessionCookie.value
alt Cache hit
Cache-->>RS: Cached user
RS-->>SC: UserContext
else Cache miss
RS->>API: fetch with cookieHeader
API-->>RS: User data
RS->>Cache: Store with cacheKey
RS-->>SC: UserContext
end
else No cacheKey (Bug scenario)
Note over RS: Cache disabled
RS->>API: fetch with cookieHeader
API-->>RS: User data
Note over RS: Cannot cache without key
RS-->>SC: UserContext
end
|
There was a problem hiding this comment.
Additional Comments (1)
-
apps/web/src/lib/auth-server.ts, line 75-77 (link)logic: when
rawCookieHeaderhas value butcookies()returned empty (the exact scenario this PR tries to fix),allCookieswill be empty andsessionCookiewill be undefined, disabling caching entirelyScore: 5/5 - Critical logic flaw that defeats the purpose of the 30-second cache
1 file reviewed, 2 comments
| const cookieHeader = rawCookieHeader || allCookies | ||
| .map((c) => `${c.name}=${c.value}`) | ||
| .join("; "); |
There was a problem hiding this comment.
logic: logic error: when rawCookieHeader is a non-empty string, the allCookies array is never used, breaking the cache key lookup on line 75-77 which depends on allCookies
| const cookieHeader = rawCookieHeader || allCookies | |
| .map((c) => `${c.name}=${c.value}`) | |
| .join("; "); | |
| // Prefer raw cookie header if available, fall back to cookies() | |
| const cookieHeader = rawCookieHeader || allCookies | |
| .map((c) => `${c.name}=${c.value}`) | |
| .join("; "); | |
| // IMPORTANT: Parse rawCookieHeader into allCookies if it was used | |
| // so the cache key lookup below can still find session cookies | |
| if (rawCookieHeader && allCookies.length === 0) { | |
| // Parse the cookie header string back into the allCookies array | |
| const parsedCookies = rawCookieHeader.split(";").map(cookie => { | |
| const [name, ...valueParts] = cookie.trim().split("="); | |
| return { name: name.trim(), value: valueParts.join("=") }; | |
| }); | |
| allCookies.push(...parsedCookies); | |
| } |
Score: 5/5 - This will cause session cache to fail when rawCookieHeader is used, forcing repeated auth API calls every request
- Add isMounted state to defer hydration-sensitive operations - Add suppressHydrationWarning to ScrollArea components - Guard all scroll/resize effects until after hydration completes - Prevent infinite loops by debouncing ResizeObserver callbacks - Only update isAtBottom state when value actually changes - Defer scroll-to-bottom button render until after hydration Fixes React error #418 (hydration mismatch) and #185 (max update depth) that occurred when reloading the page after stream completion. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…432) - Add isMounted state to defer hydration-sensitive operations - Add suppressHydrationWarning to ScrollArea components - Guard all scroll/resize effects until after hydration completes - Prevent infinite loops by debouncing ResizeObserver callbacks - Only update isAtBottom state when value actually changes - Defer scroll-to-bottom button render until after hydration Fixes React error #418 (hydration mismatch) and #185 (max update depth) that occurred when reloading the page after stream completion. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
React 19's compiler optimizations can eliminate virtualizer.getVirtualItems() calls when the return value appears unused. This causes the virtualizer to not render items correctly, leading to infinite re-render loops (error #185) and hydration mismatches (error #418). Fix: Store virtualizer in a ref and access through virtualizerRef.current to prevent React 19 from optimizing away the virtualizer state updates. Reference: TanStack/virtual#743 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
React 19's compiler optimizations can eliminate virtualizer.getVirtualItems() calls when the return value appears unused. This causes the virtualizer to not render items correctly, leading to infinite re-render loops (error #185) and hydration mismatches (error #418). Fix: Store virtualizer in a ref and access through virtualizerRef.current to prevent React 19 from optimizing away the virtualizer state updates. Reference: TanStack/virtual#743 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
EMERGENCY FIX: The @tanstack/react-virtual library causes infinite re-render loops during hydration in React 19, even with the virtualizerRef workaround from PR #434. The error occurs INSIDE the library code, not in our wrapper. This completely disables virtualization until @tanstack/react-virtual officially supports React 19. References: - TanStack/virtual#743 - TanStack/virtual#924 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…435) EMERGENCY FIX: The @tanstack/react-virtual library causes infinite re-render loops during hydration in React 19, even with the virtualizerRef workaround from PR #434. The error occurs INSIDE the library code, not in our wrapper. This completely disables virtualization until @tanstack/react-virtual officially supports React 19. References: - TanStack/virtual#743 - TanStack/virtual#924 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
- Fix virtualListContainerStyle useMemo in chat-messages-panel.tsx and app-sidebar.tsx - Use computed totalSize value as dependency instead of function call - Prevents infinite re-renders from dependency array function calls - Fix useChatReadStatus hydration mismatch - Use requestAnimationFrame to delay localStorage access until after hydration - Add hasMountedRef to ensure localStorage operations only happen client-side - Return stable empty values during SSR to match server render
- Fix virtualListContainerStyle useMemo in chat-messages-panel.tsx and app-sidebar.tsx - Use computed totalSize value as dependency instead of function call - Prevents infinite re-renders from dependency array function calls - Fix useChatReadStatus hydration mismatch - Use requestAnimationFrame to delay localStorage access until after hydration - Add hasMountedRef to ensure localStorage operations only happen client-side - Return stable empty values during SSR to match server render
… 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)
… errors (#439) - 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)
Try headers().get('cookie') when cookies() returns empty. This helps diagnose if the issue is with the cookies() API specifically.