Skip to content

[diffshub] Comment Support - #1046

Draft
amadeus wants to merge 5 commits into
mainfrom
amadeus/diffshub-comments
Draft

[diffshub] Comment Support#1046
amadeus wants to merge 5 commits into
mainfrom
amadeus/diffshub-comments

Conversation

@amadeus

@amadeus amadeus commented Aug 3, 2026

Copy link
Copy Markdown
Member

WIP

amadeus added 3 commits August 2, 2026 17:06
Saving a GitHub token now asks what the token is allowed to do: read
private diffs only, or also post PR comments. The form's create-token
link opens GitHub with the matching permissions preselected, and the
active state shows which kind of token is saved.

The app previously stored the bare token string and never knew what it
was allowed to do, which blocks the upcoming GitHub comments work.
Tokens are now saved in localStorage as a versioned JSON envelope
recording the declared capability; existing bare-string tokens keep
working and load as read-only. The two token forms (home page and viewer
settings) also stay in sync, sharing changes via a same-tab broadcast
and the cross-tab storage event.
Open a GitHub PR or commit in DiffsHub: the comments sidebar now lists
the source's actual review comments — grouped into threads, ordered by
file and line, with each row showing the author's real GitHub avatar and
a two-line snippet of the comment. Private repos use the saved PAT;
public ones work without a token.

The browser talks only to a new same-origin /api/github-comments proxy,
which pages through GitHub's review/commit comment APIs (up to 1,000
comments), normalizes them into a small wire model, and includes the PR
head sha for the upcoming posting work. A client hook fetches alongside
the patch, waits for the viewer to finish streaming, then anchors each
thread root onto viewer items via the file-tree path map. Outdated,
file-level, and out-of-diff comments are held back until they get
dedicated UI. Locally drafted comments still work and survive refetches.

Also folds the duplicate DiffsHubSavedCommentEvent type into
DiffsHubSavedCommentEntry, and constrains the sidebar rows (min-w-0 +
line clamp) so long unbreakable comment content can no longer force the
list into horizontal overflow.
Open a GitHub PR with review comments: each thread now renders as a card
directly on its line in the diff — root comment plus replies, with real
avatars, relative timestamps, and a link back to GitHub. Clicking a card
highlights the commented lines. File-level comments render above the
file's first line. Outdated comments, whose lines no longer exist in the
head diff, stay in the sidebar with an "Outdated" badge and expand in
place to show their full thread, since there is nowhere honest to anchor
them inline. Sidebar rows also show each thread's reply count.

Adds a third CommentMetadata variant (kind: 'github') carrying the whole
thread, a GitHubAnnotation card component, and annotation injection in
useGitHubComments — GitHub annotations are re-applied idempotently on
refetches without touching locally drafted comments. Renames
ExampleAnnotation to LocalCommentAnnotation now that real comments
render beside it.
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffshub Ready Ready Preview Aug 3, 2026 4:52am
pierre-docs-trees Ready Ready Preview Aug 3, 2026 4:52am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
pierre-docs-diffs Skipped Skipped Aug 3, 2026 4:52am
pierrejs-diff-demo Skipped Skipped Aug 3, 2026 4:52am

Request Review

amadeus added 2 commits August 2, 2026 21:45
On a pull request with a write-capable token saved, the draft comment
form now posts straight to GitHub: the form shows your GitHub avatar and
a posting state, then the draft becomes a real thread card with the
author and timestamp from GitHub's response. Thread cards gain a
GitHub-style reply form. Failures keep the draft text and surface the
error as a toast; with a read-only token the local demo flow remains,
labeled as saved-locally with a hint to add a write token.

The new POST /api/github-comments handler proxies both shapes with the
caller's token only — the server env token never authors comments — and
passes through actionable upstream statuses (rate limits remapped to 429
so 403 always means missing write access). A new /api/github-user route
resolves the token owner's identity for the compose forms. The token
control explains fine-grained PAT resource-owner scoping and preselects
the viewed repo's owner in the creation link via target_name.

Both compose forms are restyled after GitHub's comment box: bordered
input, avatar beside the field, Cancel/Comment actions bottom-right. The
comment wire model renames author to user to match GitHub's payload
field names.
Open a diff with a saved non-default theme: any freshly created worker
pool (a cold load, or an HMR that recreates the provider mid-session)
booted on the library's default theme pair, so the first themed surface
to mount committed a real theme change one tick after the viewer queued
its highlight tasks — invalidating and canceling all of them, which
surfaced as WorkerPoolTaskCanceledError console errors in dev.

Construct the pool from the theme controller's persisted selection
instead (read synchronously on the client; catalog defaults on the
server and for first-time visitors), so the mount-time setRenderOptions
call matches the pool's options and bails without invalidating.
// Whether saved drafts post to the pull request on GitHub; only changes
// the empty-state copy.
canPostToGitHub?: boolean;
commentSections: readonly DiffsHubSavedCommentItem[];

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you really should figure out how to get good

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oki

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