Repository navigation
fix: stabilize virtualizer ref for React 19 and allow Cloudflare Insights - #433
Conversation
…lare Insights The previous fix (#432) addressed some React 19 hydration issues but missed the root cause of the infinite loop (error #185): the virtualizer.measureElement callback creates a new function reference on every render, triggering re-measurements that cause state updates, which causes more re-renders. Changes: - Wrap virtualizer.measureElement in useCallback to create a stable ref callback - Guard measurement with isMounted check to skip during hydration - Disable virtualization entirely until after mount (isMounted && messages.length > 20) - Add Cloudflare Insights to CSP script-src to fix blocked beacon.min.js 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile OverviewGreptile SummaryFixes React 19 hydration mismatch and infinite re-render errors by stabilizing the virtualizer ref callback and deferring virtualization until after mount. Also adds Cloudflare Insights to CSP whitelist. Key Changes:
Analysis: The Note: The same virtualizer pattern is used in Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Browser
participant React
participant ChatPanel
participant Virtualizer
participant DOM
Browser->>React: Initial page load
React->>ChatPanel: Render (isMounted = false)
Note over ChatPanel: shouldVirtualize = false<br/>(prevents hydration mismatch)
ChatPanel->>DOM: Render non-virtualized list
React->>DOM: Hydrate
DOM->>ChatPanel: useEffect fires
ChatPanel->>ChatPanel: setIsMounted(true)
React->>ChatPanel: Re-render (isMounted = true)
Note over ChatPanel: shouldVirtualize = true<br/>(messages.length > 20)
ChatPanel->>Virtualizer: Initialize with enabled=true
Virtualizer->>ChatPanel: Return virtualizer instance
ChatPanel->>ChatPanel: Create stable measureElementRef<br/>via useCallback
ChatPanel->>DOM: Render virtualized items
DOM->>ChatPanel: Call measureElementRef for each item
ChatPanel->>Virtualizer: measureElement(node)
Virtualizer->>Virtualizer: Update measurements
Note over Virtualizer: Stable callback prevents<br/>infinite re-render loop
Browser->>ChatPanel: User scrolls
Virtualizer->>Virtualizer: Update scroll position
Virtualizer->>ChatPanel: Trigger re-render with new items
ChatPanel->>DOM: Render visible items
Note over ChatPanel,DOM: measureElementRef remains stable<br/>no infinite loop
|
Summary
measureElementRefcallback to prevent infinite re-renders fromvirtualizer.measureElementhttps://static.cloudflareinsights.comto CSP script-srcProblem
After Next.js 16 migration, React errors #418 (hydration mismatch) and #185 (max update depth exceeded) still occur on page reload. The root cause was the virtualizer's
measureElementcallback creating new function references on every render, which:Solution
virtualizer.measureElementinuseCallbackwithisMountedguardisMounted && messages.length > 20)Test plan
🤖 Generated with Claude Code