Skip to content

fix(message-editor): preserve comment anchors in pasted GitHub links - #3795

Merged
trunk-io[bot] merged 1 commit into
mainfrom
posthog-code/github-comment-link-anchor
Jul 24, 2026
Merged

fix(message-editor): preserve comment anchors in pasted GitHub links#3795
trunk-io[bot] merged 1 commit into
mainfrom
posthog-code/github-comment-link-anchor

Conversation

@cvolzer3

Copy link
Copy Markdown
Contributor

Problem

Pasting a GitHub comment link into the composer — e.g.

https://github.com/PostHog/posthog/pull/72409#discussion_r3647131256

auto-converts it into a PR chip, but parseGithubIssueUrl rebuilt the chip URL from owner/repo/number only, silently dropping the #discussion_r… anchor. The chip's click-through and the url="…" attribute sent to the agent both ended up pointing at the PR itself instead of the specific comment.

Fix

parseGithubIssueUrl now keeps the URL suffix on normalizedUrl whenever it contains a non-empty fragment. The whole suffix is preserved (path tail + query + fragment), not just the fragment, because anchors like #r123 only resolve on the /files subpage they were copied from — /pull/123#r123 would land nowhere.

Behavior without a fragment is unchanged: tab suffixes (/files), query strings, and trailing junk are still stripped, and http:// is still normalized to https://.

apps/mobile/src/lib/githubIssueUrl.ts is a verbatim copy of the helper (used for PR badges and markdown link chips) and gets the identical fix to stay in sync.

Testing

  • Flipped the old "fragment is stripped" unit test to assert preservation, and added cases for the reported #discussion_r… link, a /files#r… link, and an empty # (still stripped).
  • pnpm --filter @posthog/core exec vitest run src/message-editor/githubIssueUrl.test.ts src/message-editor/content.test.ts — 42 tests pass.
  • pnpm typecheck and Biome pass (also enforced by the pre-commit hook).

Pasting a GitHub comment link like .../pull/72409#discussion_r3647131256
into the composer converted it into a PR chip whose URL was rebuilt from
owner/repo/number, silently dropping the comment anchor. The agent and
the chip's click-through then pointed at the PR instead of the specific
comment.

parseGithubIssueUrl now keeps the suffix on normalizedUrl whenever it
contains a non-empty fragment. The whole suffix is kept (not just the
fragment) because anchors like #r123 only resolve on the /files subpage
they were copied from. Fragment-less suffixes (/files, ?foo=bar) are
still stripped as before. The mobile copy of the helper gets the same
fix to stay in sync.
@trunk-io

trunk-io Bot commented Jul 24, 2026

Copy link
Copy Markdown

😎 Merged directly without going through the merge queue, as the queue was empty and the PR was up to date with the target branch - details.

@github-actions

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit c7d655d.

@greptile-apps

greptile-apps Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(message-editor): preserve comment an..." | Re-trigger Greptile

@cvolzer3
cvolzer3 requested a review from a team July 24, 2026 18:47

@tatoalo tatoalo left a comment

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.

Thanks!

@trunk-io
trunk-io Bot merged commit f4c0f07 into main Jul 24, 2026
28 checks passed
@trunk-io
trunk-io Bot deleted the posthog-code/github-comment-link-anchor branch July 24, 2026 18:52
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.

2 participants