Repository navigation
[FIX] Perf improvements - #69
Conversation
**1. `scrollTop` state is tracked but never used in JSX** — every scroll event calls `setScrollTop()`, which forces a full `ConflictResolver` re-render. This is pure waste. **2. No `React.memo` on `MergeRow`** — every state change in the parent (scroll, typing, ResizeObserver, drag) re-renders ALL `MergeRow` components. With 100+ rows, each keystroke triggers 100+ component renders. **3. No `React.memo` on `CellContent`** — even within a single MergeRow re-render, all 3 `CellContent` children fully re-render, including expensive diff computations and markdown rendering. **4. `getRefCallback(i)` creates a new closure on every render** — React sees a different `ref` function, triggers ResizeObserver unobserve/observe on every render for every row. **5. `DiffContent` runs `computeLineDiff` without `useMemo`** — expensive LCS computation runs on every render even when inputs haven't changed. **6. Inline drag handlers in MergeRow** — `onDragStart` closures are recreated each render, defeating any memoization on `CellContent`. The cascade on each keystroke: type → `setChoices` → ConflictResolver renders → ALL MergeRows render → ALL CellContent children render → ALL diffs recompute → ResizeObserver fires → `setRowHeights` → ANOTHER full render cycle.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/web/client/CellContent.tsx (1)
39-50:⚠️ Potential issue | 🔴 CriticalCritical:
useMemocalled conditionally after early return violates Rules of Hooks.The early return on lines 39-45 causes
useMemo(line 50) to be skipped whencellis undefined. This violates React's hook ordering rules and will cause runtime errors or state corruption.Move the memoization before the early return and handle the undefined case:
🐛 Proposed fix
export function CellContentInner({ cell, cellIndex, side, isConflict = false, compareCell, showOutputs = true, onDragStart, onDragEnd, isVisible = true, }: CellContentProps): React.ReactElement { + // Memoize expensive JSON serialization (must be called unconditionally) + const encodedCell = useMemo( + () => cell ? encodeURIComponent(JSON.stringify(cell)) : '', + [cell] + ); + if (!cell) { return ( <div className="cell-placeholder"> <span className="placeholder-text">(not present)</span> </div> ); } const source = normalizeCellSource(cell.source); const cellType = cell.cell_type; - // Memoize expensive JSON serialization - const encodedCell = useMemo(() => encodeURIComponent(JSON.stringify(cell)), [cell]);
🤖 Fix all issues with AI agents
In `@src/web/client/MergeRow.tsx`:
- Line 12: Remove the unused hooks from the import list: edit the import
statement that currently imports React, useState, useCallback, useEffect,
useMemo, useRef and delete useMemo and useRef so only the used hooks (useState,
useCallback, useEffect) remain; update the import line where React is imported
at the top of MergeRow.tsx to eliminate the unused symbols.
| */ | ||
|
|
||
| import React, { useState, useCallback, useEffect, useMemo } from 'react'; | ||
| import React, { useState, useCallback, useEffect, useMemo, useRef } from 'react'; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check if useMemo and useRef are actually used in MergeRow.tsx
echo "=== Checking useMemo usage ==="
rg -n 'useMemo' src/web/client/MergeRow.tsx
echo "=== Checking useRef usage ==="
rg -n 'useRef' src/web/client/MergeRow.tsxRepository: Avni2000/MergeNB
Length of output: 290
Remove unused imports useMemo and useRef from line 12.
These hooks are imported but never used in the file. Clean up the import statement by removing them.
🤖 Prompt for AI Agents
In `@src/web/client/MergeRow.tsx` at line 12, Remove the unused hooks from the
import list: edit the import statement that currently imports React, useState,
useCallback, useEffect, useMemo, useRef and delete useMemo and useRef so only
the used hooks (useState, useCallback, useEffect) remain; update the import line
where React is imported at the top of MergeRow.tsx to eliminate the unused
symbols.
1.
scrollTopstate is tracked but never used in JSX — every scroll event callssetScrollTop(), which forces a fullConflictResolverre-render. This is pure waste.2. No
React.memoonMergeRow— every state change in the parent (scroll, typing, ResizeObserver, drag) re-renders ALLMergeRowcomponents. With 100+ rows, each keystroke triggers 100+ component renders.3. No
React.memoonCellContent— even within a single MergeRow re-render, all 3CellContentchildren fully re-render, including expensive diff computations and markdown rendering.4.
getRefCallback(i)creates a new closure on every render — React sees a differentreffunction, triggers ResizeObserver unobserve/observe on every render for every row.5.
DiffContentrunscomputeLineDiffwithoutuseMemo— expensive LCS computation runs on every render even when inputs haven't changed.6. Inline drag handlers in MergeRow —
onDragStartclosures are recreated each render, defeating any memoization onCellContent.The cascade on each keystroke: type →
setChoices→ ConflictResolver renders → ALL MergeRows render → ALL CellContent children render → ALL diffs recompute → ResizeObserver fires →setRowHeights→ ANOTHER full render cycle.Summary by CodeRabbit