Skip to content

[Bug]: Picked element screenshot is dropped when the page re-renders before Attach #38355

Closed

Description

@jndegens

Before submitting

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

Area

apps/desktop

Steps to reproduce

  1. Open a page in the desktop preview that re-renders its DOM on a timer (for example a dashboard that polls data every few seconds and lets React replace the nodes).
  2. Start the annotation picker and click an element.
  3. Type or dictate a comment for ~10 seconds or longer, so a refresh happens while the editor is open.
  4. Click Attach or Send.

Expected behavior

The annotation is attached with a cropped screenshot of the area that was picked.

Actual behavior

The toast "Could not capture the picked element — The annotation was kept without the screenshot" appears. This happens often on pages that refresh while you write the comment, and rarely on static pages.

Desktop trace shows PreviewManager.capturePageWithRetry and PreviewManager.captureAnnotationScreenshot both exit with Success in 5–15 ms. So capturePage() works. The screenshot is dropped afterwards because cropAnnotationScreenshot returns null.

Cause, as far as I can see on main (009966d):

  • PickPreload.ts reads the element rect only at submit time: rect: rectFromDomRect(target.element.getBoundingClientRect()) (around line 1726). It does not keep the rect from the moment of picking.
  • If the page replaced the node in the meantime, target.element is detached. A detached element returns a 0×0 rect at (0,0).
  • cropAnnotationScreenshot in Manager.ts (around line 300) then finds no target with rect.width > 0 || rect.height > 0 and returns null. The caller maps null to screenshotFailed: true.

In my session the time between pick and submit was 8–48 seconds (desktop.ipc.preview.pickElement durations), which is enough for several refreshes.

Possible fix: store the last measured rect on SelectedElement when it is picked and whenever updateSelectedVisual runs, and use it at submit when !target.element.isConnected. Optionally try to re-resolve the element via its captured selector first.

Possibly related: #29664 (page panels close on Attach, which can also detach the picked element).

Impact

Minor bug or occasional failure

Version or commit

T3 Code (Beta) desktop 0.1.9. The same code is still on main at 009966d.

Environment

macOS, Apple Silicon, desktop app with a remote (SSH) server environment. Preview pages are local dev servers forwarded from the remote machine.

Logs or stack traces

PreviewManager.capturePageWithRetry      Success  6 ms
PreviewManager.captureAnnotationScreenshot Success  7 ms
# no "preview annotation screenshot failed" warning is logged, because the failure is the null crop, not an Effect failure

Workaround

Drag a region instead of clicking an element. Region rects are stored at pick time, so the crop works.

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