Skip to content

fix: PDF horizontal scroll overflow in desktop view#21

Open
PoshanP wants to merge 1 commit into
vercel_deploymentfrom
SCRUM-13/fix-pdf-horizontal-scroll-overflow-in-desktop-view
Open

fix: PDF horizontal scroll overflow in desktop view#21
PoshanP wants to merge 1 commit into
vercel_deploymentfrom
SCRUM-13/fix-pdf-horizontal-scroll-overflow-in-desktop-view

Conversation

@PoshanP

@PoshanP PoshanP commented Jan 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixed incorrect width calculation (100px → 32px) to match actual p-4 padding
  • Added conditional overflow-x-hidden at default zoom (≤100%) to prevent horizontal scrollbar
  • Constrained canvas max-width to container width when not zoomed above 100%

Test plan

  • Open a PDF in desktop view at default zoom (100%) - no horizontal scrollbar should appear
  • Zoom in above 100% - horizontal scroll should be available if needed
  • Verify PDF renders correctly within container bounds

🤖 Generated with Claude Code

Correct width calculation to use actual p-4 padding (32px) instead of
100px. Add overflow-x-hidden at default zoom and constrain canvas
max-width to prevent horizontal scrollbar when not zoomed above 100%.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jan 12, 2026

Copy link
Copy Markdown

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

Project Deployment Review Updated (UTC)
thinkfolio Ready Ready Preview, Comment Jan 12, 2026 7:20pm

@PoshanP PoshanP left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

frontend/components/PdfViewer.tsx:331 and frontend/components/
PdfViewer.tsx:341 hide horizontal overflow and apply maxWidth: '100%' when scale <= 1,
but baseWidthRef is computed once and clamped to a minimum of 300px (frontend/
components/PdfViewer.tsx:145, frontend/components/PdfViewer.tsx:159). If the container
shrinks after initial render (chat panel toggle, responsive resize, narrow viewport),
the canvas width can be clamped without re-rendering; height stays fixed
(canvas.style.height), causing non‑uniform scaling or clipped content with no
horizontal scroll.


const containerHeight = containerRef.current!.clientHeight - 80; // Leave space for controls
const containerWidth = containerRef.current!.clientWidth - 100;
const containerWidth = containerRef.current!.clientWidth - 32; // Account for p-4 padding (16px × 2)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Aspect Ratio Distortion on Chat Panel Open/Close

The PdfViewer calculates baseWidthRef only once when the PDF loads. When the chat panel opens/closes, the container width changes but the PDF is NOT resized.

With this PR's changes:

  • maxWidth: '100%' constrains the canvas width to fit
  • But canvas.style.height remains unchanged (based on original width)
  • Result: PDF appears horizontally squished/distorted

Scenario:

  1. PDF loads with chat closed → container ~900px, baseWidth ~700px
  2. User opens chat (550px default) → container shrinks to ~350px
  3. Canvas width (700px) constrained to ~320px by maxWidth: 100%
  4. Canvas height still based on 700px width → aspect ratio broken

Old behavior: Horizontal scrollbar appeared (not ideal but content was undistorted)
New behavior: Content is distorted


🟡 Minor: Mobile/Tablet Not Affected

Mobile and tablet use MobilePdfView (a separate component), which:

  • Has a ResizeObserver that recalculates width on container resize
  • Doesn't cache baseWidthRef - calculates inline each render

The desktop PdfViewer lacks this resize handling.


🟡 Minor: Unused containerKey Prop

The interface defines containerKey (line 25) with comment "Changes when container size changes", but:

  • It's never used in the component
  • It's never passed by the parent (chat-new/page.tsx)

This was presumably intended to handle the resize case but was never implemented.

@PoshanP PoshanP left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Aspect Ratio Distortion on Chat Panel Open/Close

The PdfViewer calculates baseWidthRef only once when the PDF loads. When the chat panel opens/closes, the container width changes but the PDF is NOT resized.

With this PR's changes:

  • maxWidth: '100%' constrains the canvas width to fit
  • But canvas.style.height remains unchanged (based on original width)
  • Result: PDF appears horizontally squished/distorted

Scenario:

  1. PDF loads with chat closed → container ~900px, baseWidth ~700px
  2. User opens chat (550px default) → container shrinks to ~350px
  3. Canvas width (700px) constrained to ~320px by maxWidth: 100%
  4. Canvas height still based on 700px width → aspect ratio broken

Old behavior: Horizontal scrollbar appeared (not ideal but content was undistorted)
New behavior: Content is distorted


🟡 Minor: Mobile/Tablet Not Affected

Mobile and tablet use MobilePdfView (a separate component), which:

  • Has a ResizeObserver that recalculates width on container resize
  • Doesn't cache baseWidthRef - calculates inline each render

The desktop PdfViewer lacks this resize handling.


🟡 Minor: Unused containerKey Prop

The interface defines containerKey (line 25) with comment "Changes when container size changes", but:

  • It's never used in the component
  • It's never passed by the parent (chat-new/page.tsx)

This was presumably intended to handle the resize case but was never implemented.

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