Skip to content

fix(tabs): re-measure Tabs.List overflow with ResizeObserver - #708

Merged
blvdmitry merged 3 commits into
mainfrom
claude/ecstatic-archimedes-keli2h
Nov 9, 2026
Merged

blvdmitry merged 3 commits into
mainfrom
claude/ecstatic-archimedes-keli2h

Conversation

@blvdmitry

@blvdmitry blvdmitry commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

useFadeSide only re-measured clientWidth < scrollWidth on window resize and on scroll. So Tabs.List never became scrollable when its available width changed for any other reason: the container was resized, a sibling appeared or grew, or the tabs themselves grew (a label changed, a badge appeared, a font loaded).

This PR replaces the window resize listener and the initial requestAnimationFrame measurement with a ResizeObserver that watches:

  • the scrollable .inner element, which catches changes to its available width (clientWidth)
  • the .list element, which catches changes to the content width (scrollWidth). TabsList passes it to the hook through a new contentRef option.

ResizeObserver reports once when observation starts, so it covers the initial measurement too. It already reports once per frame after layout, so it calls updateFade directly. The scroll listener still goes through rafThrottle. updateFade now also returns early when the list isn't scrollable.

I added a changeset (reshaped: patch) and a test: overflow on size change story. It toggles the container width, then a tab label's length, and checks that .inner switches between overflow: visible and overflow: auto with no window resize.

Related Issue

Fixes #707

Screenshots / Recordings

No visual changes. The bug is reproduced and covered by the new story.

Notes for Reviewers

  • I ran the Tabs story tests locally. With this change all 16 pass. With the old hook, the new story fails (expected 'visible' to be 'auto').
  • The old comment said the initial rAF was needed for "an edge case inside the complex flexbox layout". The observer's first callback fires after layout, so that case should still be covered. It may be worth a quick check in that layout if you remember where it was.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKGZMiunH84FFWpx6zH4fN

Tabs.List only re-measured its overflow on window resize and on scroll, so
it never became scrollable when its container shrank, a sibling appeared or
grew, or the tab content itself grew after mount.

Replace the window resize listener and the initial rAF measurement with a
ResizeObserver on the scrollable element (available width) and the list
element (content width). Also return early in updateFade when the list
isn't scrollable.

Fixes #707

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMiunH84FFWpx6zH4fN
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMiunH84FFWpx6zH4fN
…esize updates

- Observe the content element via an explicit contentRef instead of
  relying on firstElementChild
- Call updateFade directly from the ResizeObserver, which already fires
  once per frame after layout, instead of deferring it another frame
- Loop over the story test cases instead of repeating the steps

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMiunH84FFWpx6zH4fN
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Library / JS 52.77 KB (+0.08% 🔺) 1.1 s (+0.08% 🔺) 0 ms (+100% 🔺) 1.1 s
Library / CSS 24.57 KB (0%) 492 ms (0%) 0 ms (+100% 🔺) 492 ms
Theming / JS 7.8 KB (0%) 156 ms (0%) 254 ms (+21.6% 🔺) 410 ms
Theming with a default theme definition / JS 8.68 KB (0%) 174 ms (0%) 361 ms (-15.55% 🔽) 535 ms

@blvdmitry
blvdmitry merged commit de2a1da into main Nov 9, 2026
11 checks passed
@blvdmitry
blvdmitry deleted the claude/ecstatic-archimedes-keli2h branch November 9, 2026 19:42
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.

Tabs.List doesn't become scrollable when its available width changes without a window resize

2 participants