Skip to content

[FIX] Perf improvements - #69

Merged
Avni2000 merged 2 commits into
copilot/fix-image-flickering-issuefrom
performance-improvements
Feb 10, 2026
Merged

Avni2000 merged 2 commits into
copilot/fix-image-flickering-issuefrom
performance-improvements

Conversation

@Avni2000

@Avni2000 Avni2000 commented Feb 10, 2026 •

Copy link
Copy Markdown
Owner

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.

Summary by CodeRabbit

  • Refactor
    • Optimized rendering performance for content cells and merge row operations through strategic memoization of expensive computations.
    • Improved callback efficiency by implementing caching strategies for frequently used event handlers.
    • Enhanced scroll performance in conflict resolution interface by streamlining position tracking mechanisms.

**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.
@coderabbitai

coderabbitai Bot commented Feb 10, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch performance-improvements

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🔴 Critical

Critical: useMemo called conditionally after early return violates Rules of Hooks.

The early return on lines 39-45 causes useMemo (line 50) to be skipped when cell is 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';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 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.tsx

Repository: 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.

@Avni2000
Avni2000 merged commit 3d1b937 into copilot/fix-image-flickering-issue Feb 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant