Skip to content

fix(pr-review-canvas): number diffs from raw hunks, never silently drop import lines - #482

Open
zichen0116 wants to merge 1 commit into
cursor:mainfrom
zichen0116:fix/pr-review-canvas-line-numbers
Open

zichen0116 wants to merge 1 commit into
cursor:mainfrom
zichen0116:fix/pr-review-canvas-line-numbers

Conversation

@zichen0116

@zichen0116 zichen0116 commented Oct 2, 2026 •

Copy link
Copy Markdown

Closes #472

Problem

renderDiff in cursor-team-kit/skills/pr-review-canvas/renderer.js dropped
import lines and rewrote whitespace-only del/add pairs before line numbers
were computed from the @@ hunk headers, so the rendered review was neither
the diff nor correctly numbered:

  1. Import filtering shifted line numbers. Every added/removed/context line
    matching isImport — including side-effect imports like
    import './polyfill' — was deleted up front. Counters oL/nL are only
    reset by hunk headers, so every line after a dropped import within the same
    hunk was numbered too low. Issue repro:
    @@ -1,3 +1,3 @@
     import a from 'a'
    -import b from 'b'
    +import c from 'c'
     const x = 1
    
    Both changed import lines vanished and const x = 1 displayed as line 1/1
    instead of 3/3.
  2. Whitespace collapsing hid real changes. isWhitespaceOnly compared
    both sides with all whitespace stripped (replace(/\s/g, '')), so
    - return "a b" / + return "ab" was rewritten into an unchanged context
    line — likewise for string-literal spacing and Python/YAML/Make
    indentation changes.

Fix

  • Parse and number the full raw diff first; import lines are now tagged
    hidden instead of deleted, so line numbers always follow the original
    hunk headers.
  • Hidden import lines are grouped into a visibly-marked, expandable
    "N import lines hidden" row (toggleHidden) — collapsed by default but
    never silent, and they keep their correct line numbers when expanded.
  • isWhitespaceOnly now compares after trimming leading/trailing
    whitespace only
    , so internal whitespace differences are preserved as real
    del/add rows.
  • SKILL.md and styles.css updated to document/style the new behavior.

Moved-code detection and the rest of the render pipeline are unchanged.

Verification

  • node --check renderer.js — syntax clean.
  • Repro harness (Node + DOM stub driving renderDiff on the issue's exact
    repro diffs): all 8 assertions pass —
    • issue repro Website design system extraction #1: const x = 1 renders as 3/3, changed import lines present
      under the "3 import lines hidden" row;
    • issue repro Audit plugin prompt capture #2: "a b" → "ab" renders as del+add, not context;
    • genuine leading/trailing-whitespace-only change still collapses to a
      context row, with following lines correctly numbered;
    • side-effect import (import './polyfill') preserved, line numbers after
      it correct;
    • multi-hunk numbering, a real 3-line move (moved-code tint), and the
      singular/plural hidden-row labels all verified.

Note

Low Risk
Localized changes to the PR review canvas skill’s client-side diff renderer and docs; no auth, data, or production service impact.

Overview
Fixes incorrect diff line numbers and over-aggressive collapsing in the pr-review-canvas renderDiff pipeline (#472).

renderDiff now parses and numbers the full raw patch first, then applies display transforms. Import lines are marked hidden instead of stripped before counting, so old/new line numbers always match the @@ hunk headers. Consecutive hidden imports render as a clickable "N import lines hidden" summary (toggleHidden); expanding shows the real import rows with correct line numbers.

Whitespace-only collapsing is tightened: isWhitespaceOnly compares lines after trimming leading/trailing whitespace only, so internal spacing changes (e.g. "a b" → "ab") stay visible as del/add instead of fake context rows.

SKILL.md documents the new behavior; styles.css adds styling for the hidden-import summary and detail rows. Moved-code detection is unchanged aside from indexing cleanup.

Reviewed by Cursor Bugbot for commit c4520aa. Bugbot is set up for automated code reviews on this repo. Configure here.

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.

pr-review-canvas renderer.js: import filtering and whitespace collapsing happen before line numbering

1 participant