Skip to content

fix(url-preview): show scroll arrows only when content overflows#301

Merged
Just-Insane merged 3 commits intodevfrom
fix/url-preview-scroll-arrows
Mar 16, 2026
Merged

fix(url-preview): show scroll arrows only when content overflows#301
Just-Insane merged 3 commits intodevfrom
fix/url-preview-scroll-arrows

Conversation

@Just-Insane
Copy link
Collaborator

Summary

Fixes #220 — URL preview cards showed orange scroll arrows even when there was no content to scroll.

Root cause

The previous implementation used IntersectionObserver to watch 0×0 anchor divs at each end of the scroll container. These anchors triggered false positives during initial load (before images were sized) and when the container was just barely fitting its content, so arrows appeared even when scrolling wasn't possible.

Fix

Replaced the IntersectionObserver approach with:

  • A scroll event listener on the container that reads scrollLeft, scrollWidth, and clientWidth
  • A ResizeObserver on both the scroll container and its inner content box

Arrows now only render when scrollWidth > clientWidth, i.e. when there is actual overflow to scroll through. The updateArrows() function runs on mount, scroll, and any resize of the container or its contents.

…surement for arrows

The old code used IntersectionObserver anchors to determine whether scroll
arrows should be shown. This caused false positives in two scenarios:
1. When a UrlPreviewCard renders null (fetch error), the empty anchor div
   was sometimes not detected as intersecting, leaving a stale arrow visible.
2. When loading (Spinner makes card 400px wide), the IO would mark the front
   anchor as not visible, showing the arrow; after load failure the arrow
   stayed stuck.

Replace with direct scrollWidth/clientWidth measurement via ResizeObserver
(fires on container and content resize) plus a scroll event listener. Arrows
now only appear when the horizontal scroll area actually has overflowed content.

Fixes #220
@Just-Insane Just-Insane requested a review from a team March 16, 2026 19:07
@github-actions
Copy link
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

Status Preview URL Commit Alias Updated (UTC)
✅ Deployment successful! https://pr-301-sable.raspy-dream-bb1d.workers.dev f7afb8d pr-301 Mon, 16 Mar 2026 19:26:53 GMT

@Just-Insane Just-Insane enabled auto-merge March 16, 2026 19:41
@Just-Insane Just-Insane added this pull request to the merge queue Mar 16, 2026
Merged via the queue into dev with commit 888ab90 Mar 16, 2026
8 checks passed
@Just-Insane Just-Insane deleted the fix/url-preview-scroll-arrows branch March 17, 2026 03:43
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.

Orange arrow displays, suggesting that you could scroll but there's no link preview

3 participants