The Code Viewer component displays actual code changes from commits, similar to GitHub's interface. Users can expand files to see line-by-line changes with syntax highlighting and color coding.
- Shows all files changed in the commit
- File icons based on file type (JS, Python, Go, etc.)
- Status badges (added, removed, modified, renamed)
- Line change statistics (+additions, -deletions)
- Click on any file to expand and view changes
- Shows actual code diff with context
- Color-coded lines:
- Green - Added lines
- Red - Removed lines
- White - Context (unchanged) lines
- Gray - Diff headers
- "🔗" button to open file on GitHub
- Direct link to the exact commit version
- Opens in new tab
Automatically detects file types and shows appropriate icons:
- JavaScript/TypeScript: 📄 / ⚛️
- Python: 🐍
- Go: 🐹
- Rust: 🦀
- Ruby: 💎
- PHP: 🐘
- HTML/CSS: 🌐 / 🎨
- JSON/XML: 📋
- Markdown: 📝
- And more...
User clicks "View Changes"
↓
Fetches commit details from GitHub API
↓
Extracts patch/diff information
↓
Parses diff format (unified diff)
↓
Displays with syntax highlighting
The component parses unified diff format:
@@ -10,5 +10,6 @@ function example() {
// Context line (unchanged)
-// Removed line
+// Added line
// Another context line
- Added (
+): New code added in this commit - Removed (
-): Code deleted in this commit - Context (
): Unchanged code for reference - Header (
@@): Diff section markers
Main component that:
- Manages expanded/collapsed state for each file
- Parses diff content
- Renders diff lines with proper styling
- Handles GitHub links
- Color-coded badges for file status
- Line markers (+/-/space) for change type
- Hover effects for better UX
- File icons for quick type identification
📝 Code Changes
Click on files to view detailed changes
📄 src/utils/api.ts [MODIFIED] +15 -3 [🔗]
▼ (expanded)
@@ -10,5 +10,6 @@ export function fetchData() {
const url = 'https://api.example.com'
- const response = await fetch(url)
+ const response = await fetch(url, { timeout: 5000 })
return response.json()
+ // Added error handling
⚛️ src/components/Button.tsx [ADDED] +45 -0 [🔗]
▶ (collapsed)
🐍 tests/api.test.py [MODIFIED] +20 -5 [🔗]
▶ (collapsed)
GET /repos/{owner}/{repo}/commits/{sha}
files[].filename- File pathfiles[].status- Change typefiles[].additions- Lines addedfiles[].deletions- Lines removedfiles[].patch- Unified diff format
- Added lines: Light green background (#f0f8f0)
- Removed lines: Light red background (#f8f0f0)
- Context lines: White background
- Headers: Light gray background (#f0f0f0)
- Desktop: Full diff display with proper spacing
- Tablet: Adjusted font sizes and padding
- Mobile: Compact view with smaller fonts
- Lazy Loading: Diffs are parsed only when file is expanded
- Efficient Parsing: Simple line-by-line parsing
- Memory: Only expanded files keep parsed data
- API Calls: Single call per commit (includes all files)
- Patch Content: Requires GitHub API to return patch data
- Large Files: Very large diffs may be truncated by GitHub API
- Binary Files: Cannot display diffs for binary files
- Rate Limiting: Subject to GitHub API rate limits (60/hour)
- Syntax Highlighting: Add language-specific code highlighting
- Side-by-Side View: Show before/after code side by side
- Search: Find specific changes in large diffs
- Collapse Context: Hide unchanged lines to focus on changes
- Copy Code: Copy individual lines or entire files
- Blame View: Show who made each change
- File Tree: Hierarchical view of changed files
- Single file modification
- Multiple file changes
- File additions
- File deletions
- File renames
- Large diffs
- Binary files
torvalds/linux- Large kernel commitsfacebook/react- Feature commitsnodejs/node- Mixed changespython/cpython- Well-documented changes
- Keyboard navigation support
- Color-blind friendly (uses symbols + colors)
- Screen reader compatible
- Proper semantic HTML
- Chrome/Edge: Full support
- Firefox: Full support
- Safari: Full support
- IE11: Not supported (uses modern JavaScript)
<CodeViewer
files={commitDetails.files}
owner="facebook"
repo="react"
commitSha="abc123def456"
/>The CodeViewer is integrated into:
- CommitDiff.tsx - Main diff display component
- CommitCard.tsx - Individual commit cards
- ResultsDisplay.tsx - Analysis results view
- User selects a repository
- Commits are analyzed and displayed
- User clicks "View Changes" on a commit
- CommitDiff component loads and displays file list
- User clicks on a file to expand
- CodeViewer displays the diff
- User can click GitHub link to see on GitHub
- User can review code changes and commit message quality