Skip to content

refactor(ui): use default diff row memo comparison - #1017

Merged
benvinegar merged 1 commit into
mainfrom
refactor/diff-row-default-memo
Sep 7, 2026
Merged

refactor(ui): use default diff row memo comparison#1017
benvinegar merged 1 commit into
mainfrom
refactor/diff-row-default-memo

Conversation

@benvinegar

@benvinegar benvinegar commented Sep 7, 2026

Copy link
Copy Markdown
Member

Summary

  • rely on React's default shallow comparison for memoized diff rows
  • remove the manually maintained prop comparator
  • keep the callback identity contract documented beside the component

Why

The custom comparator repeated React's normal shallow comparison and could silently become incomplete whenever a prop was added. Delegating to memo keeps every prop covered automatically.

Stack

  1. This PR — default memo comparison
  2. refactor(ui): inline diff row dispatch #1018 — inline diff-row dispatch
  3. refactor(ui): require planned diff rows #1019 — require planned diff-row input

Merge bottom to top. The next PR is based on this branch.

Validation

Run on the stack tip:

  • bun run typecheck
  • bun run test
  • bun run test:integration
  • bun run test:tty-smoke

All passed. No user-visible rendering behavior changes, so no new visual evidence was captured.

Performance spot check

Eight alternating local runs of the focused DiffRowView|DiffPane add-note rendering tests:

  • rebased main: mean 0.783s, median 0.778s
  • stack tip: mean 0.782s, median 0.784s
  • delta: mean -0.1%, median +0.7%

This is within run-to-run noise; no material regression was observed.

This PR description was generated by Pi using gpt-5.6-sol

@vercel

vercel Bot commented Sep 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
hunk-web Ignored Ignored Preview Sep 7, 2026 12:43pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces DiffRowView's manually maintained memo comparator with React's default shallow comparison and updates the callback-identity documentation.

  • Removes the explicit prop-by-prop comparator.
  • Retains the existing row-resolution and rendering flow.
  • Adds an empty changeset.
  • Needs regression coverage to satisfy the repository's testing requirement for runtime changes.

Confidence Score: 4/5

The refactor appears behaviorally sound, but the repository's explicit testing requirement must be satisfied before merging.

The default React memo comparison covers all current props and no realistic comparison-semantic failure was found, but the runtime memoization change lacks the required regression test.

Files Needing Attention: packages/hunk/src/ui/diff/DiffRowView.tsx

Important Files Changed

Filename Overview
packages/hunk/src/ui/diff/DiffRowView.tsx Replaces the custom memo comparator with React's default comparison; implementation is sound, but required regression coverage is missing.
.changeset/calm-rows-compare.md Adds an empty changeset for the internal refactor.
Prompt To Fix All With AI
### Issue 1
packages/hunk/src/ui/diff/DiffRowView.tsx:109
**Memoization Change Lacks Coverage**

Removing the custom comparator changes this component's runtime memoization behavior, but the PR adds no regression coverage. The repository requires tests for every code change that modifies runtime behavior, so this requirement must be satisfied before merging. Add a test showing that a row rerenders when each rendering-relevant prop changes.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "refactor(ui): use default diff row memo ..." | Re-trigger Greptile

* The comparator checks every handler by reference, so callers (DiffSectionBody) must pass
* identity-stable callbacks — e.g. one shared onHoverRow that receives the row key — or the memo
* React's shallow comparison checks every handler by reference, so callers (DiffSectionBody) must
* pass identity-stable callbacks — e.g. one shared onHoverRow that receives the row key — or memo

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.

P2 Memoization Change Lacks Coverage

Removing the custom comparator changes this component's runtime memoization behavior, but the PR adds no regression coverage. The repository requires tests for every code change that modifies runtime behavior, so this requirement must be satisfied before merging. Add a test showing that a row rerenders when each rendering-relevant prop changes.

Context Used: guidelines.mdc Cursor rule (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hunk/src/ui/diff/DiffRowView.tsx
Line: 109

Comment:
**Memoization Change Lacks Coverage**

Removing the custom comparator changes this component's runtime memoization behavior, but the PR adds no regression coverage. The repository requires tests for every code change that modifies runtime behavior, so this requirement must be satisfied before merging. Add a test showing that a row rerenders when each rendering-relevant prop changes.

**Context Used:** guidelines.mdc Cursor rule ([source](https://github.com/modem-dev/modem/blob/main/.cursor/rules/guidelines.mdc))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I’m not adding an exhaustive per-prop rerender test here. That would duplicate React’s documented shallow-comparison contract in our test suite—the same maintenance burden this PR removes. Existing row rendering tests cover the rendering-relevant props, and a local before/after spot check of the focused DiffRowView/add-note tests showed no material timing change (8 runs: mean -0.1%, median +0.7%).

Responded by Pi using gpt-5.6-sol.

This comment was generated by Pi using gpt-5.6-sol

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.

That’s fair. An exhaustive per-prop rerender test would duplicate React’s documented memo shallow-comparison contract and recreate the maintenance burden this change removes. Given the existing row rendering coverage and the focused before/after check, I’m withdrawing the coverage request for this PR.

@benvinegar
benvinegar force-pushed the refactor/diff-row-default-memo branch from 9c3261c to a0ea2f5 Compare September 7, 2026 12:43
@benvinegar
benvinegar merged commit e6be2f5 into main Sep 7, 2026
12 checks 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