Skip to content

fix(sessions): Fix not copying URL from link-bubbles#2713

Open
mp-hog wants to merge 3 commits into
mainfrom
posthog-code/fix-conversation-copy-link
Open

fix(sessions): Fix not copying URL from link-bubbles#2713
mp-hog wants to merge 3 commits into
mainfrom
posthog-code/fix-conversation-copy-link

Conversation

@mp-hog

@mp-hog mp-hog commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Problem

Right-clicking a GitHub PR/issue chip in a conversation and choosing Copy did nothing, the clipboard kept its previous contents.

copy-dropdown

Two causes:

  1. The context menu's "Copy" only read window.getSelection(). Right-clicking never creates a selection, and the chip (GithubRefChip, a Chip button) never exposed its URL — so there was nothing to copy.
  2. Even with the URL captured, the write fired synchronously inside the Radix ContextMenu.Item onSelect, while the menu's focus scope is tearing down. In Electron/Chromium navigator.clipboard.writeText rejects with "Document is not focused" at that instant, leaving the old clipboard contents.

Fix

  • GithubRefChip exposes its href via a data-github-ref-url attribute on a display:contents wrapper, discoverable from any right-click target (icon, label, chip root).
  • The context menu captures that URL on right-click and copies it, falling back to the text selection, with success/error toasts.
  • The clipboard write is deferred one task (copyFromContextMenu) so it runs after the menu closes and focus returns to the document.

Tests

  • Unit tests for getGithubRefUrlFromEventTarget, resolveCopyText, and copyFromContextMenu (deferral + success/error callbacks).
  • A GithubRefChip DOM-attribute test.
  • An integration test driving the real right-click → Copy flow through a Radix ContextMenu with the real GithubRefChip.
pnpm --filter @posthog/ui exec vitest run \
  src/features/sessions/components/copyContextTarget.test.ts \
  src/features/sessions/components/copyContextMenu.integration.test.tsx \
  src/features/editor/components/GithubRefChip.test.tsx

Manual verification

  • Verified manually by running the local build

🤖 Generated with Claude Code

The conversation context menu's "Copy" only read the current text selection.
Right-clicking a GitHub PR/issue chip creates no selection, and the chip
(a Chip button) never exposed its URL — so "Copy" silently did nothing.

Even once the URL is captured, the write was fired synchronously inside the
Radix ContextMenu.Item onSelect, while the menu's focus scope is tearing down.
In Electron/Chromium navigator.clipboard.writeText rejects with "Document is
not focused" at that moment, leaving the previous clipboard contents.

- GithubRefChip now exposes its href via a data-github-ref-url attribute on a
  display:contents wrapper, discoverable from any right-click target.
- The context menu captures that URL on right-click and copies it (falling back
  to the text selection), with success/error toasts.
- The clipboard write is deferred one task (copyFromContextMenu) so it runs
  after the menu closes and focus returns to the document.

Adds helper unit tests, a GithubRefChip DOM-attribute test, and an integration
test that drives the real right-click -> Copy flow through Radix ContextMenu.

Generated-By: PostHog Code
Task-Id: 3b559453-f506-4416-af2c-fdbb86a4d654
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit c58bbe3.

@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
packages/ui/src/features/sessions/components/copyContextTarget.test.ts:54-68
**Prefer parameterised tests for table-driven cases**

The `resolveCopyText` and `getGithubRefUrlFromEventTarget` describe blocks each contain multiple `it()` calls with the same assertion shape and could be expressed more concisely as `it.each` tables. For example the three `resolveCopyText` cases are pure input → output pairs that map directly onto a data table. The same pattern applies to the four `getGithubRefUrlFromEventTarget` cases (the DOM setup can be hoisted outside the table).

Reviews (1): Last reviewed commit: "fix(sessions): copy PR/issue link from c..." | Re-trigger Greptile

mp-hog added 2 commits June 16, 2026 23:31
Convert the resolveCopyText and getGithubRefUrlFromEventTarget describe blocks
to it.each tables, as they are pure input -> output cases sharing one assertion
shape. Addresses review feedback.

Generated-By: PostHog Code
Task-Id: 3b559453-f506-4416-af2c-fdbb86a4d654
Reflow lines flagged by `biome ci` in SessionView.tsx and
copyContextTarget.test.ts. No behaviour change.

Generated-By: PostHog Code
Task-Id: 3b559453-f506-4416-af2c-fdbb86a4d654
@mp-hog mp-hog marked this pull request as ready for review June 16, 2026 21:34
@mp-hog mp-hog changed the title fix(sessions): copy PR/issue link from conversation context menu fix(sessions): Fix not copying links from chips (e.g. PRs chips) Jun 16, 2026
@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "style(sessions): apply biome formatting" | Re-trigger Greptile

@mp-hog mp-hog changed the title fix(sessions): Fix not copying links from chips (e.g. PRs chips) fix(sessions): Fix not copying URL from link-bubbles Jun 16, 2026
@mp-hog mp-hog requested a review from a team June 17, 2026 07:09
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