This repository was archived by the owner on Sep 16, 2026. It is now read-only.
Repository navigation
fix: React 19 virtualizer optimization workaround - #434
Merged
Merged
Conversation
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]>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile OverviewGreptile SummaryThis PR implements a workaround for React 19 compiler optimizations that were causing the virtualizer to malfunction, leading to infinite re-render loops and hydration errors. The main changes:
Critical Issue Found:
Confidence Score: 3/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant React as React 19 Compiler
participant Component as ChatMessagesPanel
participant Virtualizer as useVirtualizer
participant Ref as virtualizerRef
participant DOM as Virtual DOM
Note over React,Component: Component Render Phase
Component->>Virtualizer: useVirtualizer({ count, enabled })
Virtualizer-->>Component: virtualizer instance
Note over Component,Ref: React 19 Fix Applied
Component->>Ref: virtualizerRef.current = virtualizer
Note right of Ref: Store in ref to prevent<br/>compiler optimization
Note over Component,DOM: Render Virtual Items
Component->>Ref: virtualizerRef.current.getVirtualItems()
Ref->>Virtualizer: getVirtualItems()
Virtualizer-->>Ref: virtual items array
Ref-->>Component: virtual items array
Component->>Ref: virtualizerRef.current.getTotalSize()
Ref->>Virtualizer: getTotalSize()
Virtualizer-->>Ref: total size
Ref-->>Component: total size
Component->>DOM: Render virtualized messages
Note over Component,Ref: Measurement Phase
DOM->>Component: ref callback fires
Component->>Ref: virtualizerRef.current.measureElement(node)
Ref->>Virtualizer: measureElement(node)
Note right of Virtualizer: Updates internal state<br/>triggers re-render
Note over React,Virtualizer: Without Fix (Optimized Away)
React->>React: Detects unused getVirtualItems()
React->>React: Eliminates virtualizer calls
Note right of React: Causes infinite loops<br/>and hydration errors
|
Comment on lines
159
to
167
| const virtualListContainerStyle = useMemo( | ||
| () => ({ | ||
| height: `${virtualizer.getTotalSize()}px`, | ||
| height: `${virtualizerRef.current.getTotalSize()}px`, | ||
| width: "100%", | ||
| position: "relative" as const, | ||
| }), | ||
| [virtualizer] | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| [virtualizerRef.current.getTotalSize()] | ||
| ); |
Contributor
There was a problem hiding this comment.
logic: useMemo dependency array includes function call result virtualizerRef.current.getTotalSize() which defeats memoization - causes recalculation on every render. Should depend on messages.length or similar state that triggers size changes.
Suggested change
| const virtualListContainerStyle = useMemo( | |
| () => ({ | |
| height: `${virtualizer.getTotalSize()}px`, | |
| height: `${virtualizerRef.current.getTotalSize()}px`, | |
| width: "100%", | |
| position: "relative" as const, | |
| }), | |
| [virtualizer] | |
| // eslint-disable-next-line react-hooks/exhaustive-deps | |
| [virtualizerRef.current.getTotalSize()] | |
| ); | |
| const virtualListContainerStyle = useMemo( | |
| () => ({ | |
| height: `${virtualizerRef.current.getTotalSize()}px`, | |
| width: "100%", | |
| position: "relative" as const, | |
| }), | |
| [messages.length, shouldVirtualize] | |
| ); |
leoisadev1
added a commit
that referenced
this pull request
Nov 27, 2025
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]>
3 tasks
leoisadev1
added a commit
that referenced
this pull request
Nov 27, 2025
…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]>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
virtualizerRef) to prevent React 19 from optimizing away state updatesgetVirtualItems(),getTotalSize(), andmeasureElement()throughvirtualizerRef.currentRoot Cause
React 19's compiler optimizations can eliminate
virtualizer.getVirtualItems()calls when the return value appears unused (not stored in state). This causes the virtualizer to malfunction, leading to infinite re-render loops.Solution
Based on TanStack/virtual issue #743, storing the virtualizer in a ref prevents React 19 from optimizing it away:
Test plan
🤖 Generated with Claude Code