Skip to content

Add <CodeDiff> component for embedding rendered diffs - #8

Merged
mjsz merged 1 commit into
mainfrom
matts/code-diff-component
Jul 8, 2026
Merged

mjsz merged 1 commit into
mainfrom
matts/code-diff-component

Conversation

@mjsz

@mjsz mjsz commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Context — what "code view" is for

These changes support two workflows:

  1. Code walkthroughs — an author assembles a share that interleaves prose, callouts, and inline rendered diffs to highlight specific areas/changes and request targeted feedback (a reviewable narrative around a PR, not a raw diff).
  2. Sharing example code externally — when a client or interviewer asks for "example code," we can send a specific PR (or curated parts of one) as a self-contained, public-linkable page, without granting access to the full private repo.

What

A <CodeDiff> component that wraps a ```diff fence (a real unified patch, e.g. gh pr diff) and emits a `data-slot="code-diff"` marker around it:

<CodeDiff>

```diff
diff --git a/server.go b/server.go
@@ -1,3 +1,4 @@
 func main() {
-	serve()
+	serveTLS()
 }
```

→ <div data-slot="code-diff"><pre><code class="language-diff">…patch…</code></pre></div>

Why this shape

The component does no diff rendering itself — it only marks the region. The host (pin) replaces the marker with a full, syntax-highlighted diff view server-side. That keeps the heavy lifting (and a Shiki/chroma-sized highlighter) out of the bundle, and the rendered output stays static. A plain ```diff fence without the wrapper is left as ordinary highlighted text.

Distinct from the existing prose <Diff before=… after=…> comparison (which keeps data-slot="diff").

Scope

  • src/components/ui/code-diff.tsx — the component
  • src/components/index.tsx — export
  • src/components/manifest.ts — regenerated (now 30 components)
  • tests — compile test (emits the marker + preserves the patch) and manifest count/category

pnpm test (16) and pnpm typecheck pass; bundle builds.

Companion

Host side: bitcomplete/pin matts/diff-embed adds the post-process that renders data-slot="code-diff" regions. After this releases, bump pin's bundle.version to pick up the component.

🤖 Generated with Claude Code

<CodeDiff> wraps a ```diff fence (a real unified patch) and emits a
data-slot="code-diff" marker around it. The component does no diff
rendering itself — it only marks the region so the host (pin) can replace
it with a full, syntax-highlighted diff view server-side, keeping the
heavy lifting (and Shiki/chroma) out of the bundle and the output static.

Distinct from the existing prose <Diff before/after> comparison.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mjsz
mjsz requested a review from terraboops June 30, 2026 01:46

@terraboops terraboops left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified against the host contract, not just in isolation: built this branch and compiled MDX through it — the emitted marker (<div data-slot="code-diff"><pre><code class="language-diff">…) matches pin's codeDiffRe (embed.go#L22-L25) in all three shapes I tested: bare, className passthrough, and mid-document. Patch content survives round-trip. pnpm test 16/16 green. After this merges + releases, pin just bumps bundle.version and embeds go live.

@mjsz
mjsz merged commit bb6b74c into main Jul 8, 2026
1 check passed
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