Skip to content

[Bug]: Copying from the Diff panel returns only the rows currently mounted by the virtualizer #30825

Description

@leo-stuart

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/web

Steps to reproduce

  1. In a project, make a change that adds a long file (I used an untracked 300-line big.sql, one SELECT NNN …; -- fixture line NNN per line).
  2. Open the Diff surface and expand the file with its chevron. Do not click the file name, because that opens the editable Files preview instead.
  3. Drag selection: select a range of lines, then scroll (or drag past the edge so the panel autoscrolls) until the first selected lines leave the viewport. Press Cmd+C and paste somewhere.
  4. Select all: click a code line, press Cmd+A, then Cmd+C, and paste somewhere.

Expected behavior

Copying from the diff returns every selected line, including lines that have scrolled out of view. Cmd+A followed by Cmd+C inside a file's diff gives that file's lines.

Actual behavior

The copied text contains only the rows the virtualizer has mounted at that moment.

Measured on main @ 8b44f42 in the web dev app (Chrome, 1280×800, 540px Diff panel):

  • With the 300-line file expanded, only 45 [data-line] rows exist in the file's shadow root (lines 1–45).
  • Drag: I selected lines 1–31 (1,363 selected characters), then scrolled the diff so lines 189–245 were mounted. The selection collapsed to a caret (0 characters), so the start of the drag was lost. A drag from the top of the file to the bottom therefore copies only the end of the range that is still mounted.
  • Cmd+A: this selects the whole app, including the sidebar and chat. The pasted text contains only lines 1–45 of the diff.

Cause: the Diff surface renders through @pierre/diffs CodeView, which virtualizes rows inside each file's shadow root. The browser serializes only the DOM nodes that exist, and nothing on the diff surface handles copy to rebuild the text from the loaded FileDiffMetadata. When a selection endpoint's row is unmounted, the selection collapses.

The editable Files preview does not have this problem, because Pierre's editor writes the clipboard from its text model (#writeSelectionClipboardData). The read-only diff has no equivalent.

Related: #15927 is the same virtualizer root cause in the read-only Files preview. Its draft fix (#23244) covers only that panel. #20207 reports copying failing in the PR Code tab, which renders through the same diff component.

Impact

Major degradation or frequent failure

Version or commit

main @ 8b44f42

Environment

macOS, web dev app (vp run dev) in the built-in browser. First noticed in T3 Code Desktop on a 131-line new migration file.

Logs or stack traces

n/a

Screenshots, recordings, or supporting files

Measurements above. I can attach a recording.

Workaround

Open the file in the Files panel (click its name in the diff header) and copy from there, or open it in an external editor.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions