Repository navigation
fix(Chat): use callback ref for content observation (#2282) - #2285
Merged
Merged
Conversation
Adds ChatAutoScroll.stories.tsx with three stories demonstrating the difference in auto-scroll behavior between streaming text and discrete block additions (tool calls, custom elements): - ScrollBehaviorComparison: interactive controls to test each case - RapidToolCalls: stress-tests rapid discrete additions - MixedStreamAndTools: realistic sequence showing the transition
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- XDSBadge uses label prop, not children - XDSText type='small' doesn't exist, use 'label' instead
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
Adds tests proving that useXDSChatNewMessages does NOT attach its ResizeObserver when contentRef.current is set after the initial effect run (e.g. when XDSChatMessageList mounts conditionally). The tests assert the *broken* behavior — they will need to be flipped to assert the correct behavior once the fix is applied: - 'does NOT call onResize' → 'DOES call onResize' - 'does NOT observe content element' → 'DOES observe content element' Root cause: useEffect dep is [contentRef] (ref object, stable identity), so the effect never re-runs when contentRef.current changes from null to a DOM element.
useXDSChatNewMessages previously depended on a contentRef (ref object)
passed as an option, with useEffect dep [contentRef]. Since ref objects
have stable identity, the effect only ran once on mount. When
XDSChatMessageList mounted conditionally (e.g. {!isEmpty && ...}),
contentRef.current was null at effect time and the ResizeObserver never
attached — breaking auto-scroll entirely.
Fix: useXDSChatNewMessages now returns a callback ref. When the content
element mounts or unmounts, the callback fires and the observer
attaches/detaches immediately. No state, no version counter — the ref
callback itself is the subscription mechanism.
XDSChatLayout passes the hook's returned contentRef directly into
the layout context. XDSChatMessageList calls it when it mounts,
and the observer attaches on the spot.
cixzhang
force-pushed
the
navi/fix/auto-scroll-demo-story
branch
from
May 21, 2026 23:28
5f31c03 to
631f788
Compare
cixzhang
added a commit
that referenced
this pull request
Jun 21, 2026
* feat(storybook): add auto-scroll demo stories for issue #2282 Adds ChatAutoScroll.stories.tsx with three stories demonstrating the difference in auto-scroll behavior between streaming text and discrete block additions (tool calls, custom elements): - ScrollBehaviorComparison: interactive controls to test each case - RapidToolCalls: stress-tests rapid discrete additions - MixedStreamAndTools: realistic sequence showing the transition * fix: use correct XDSBadge label prop and XDSText type - XDSBadge uses label prop, not children - XDSText type='small' doesn't exist, use 'label' instead * test: add failing tests for late-mount contentRef bug (#2282) Adds tests proving that useXDSChatNewMessages does NOT attach its ResizeObserver when contentRef.current is set after the initial effect run (e.g. when XDSChatMessageList mounts conditionally). The tests assert the *broken* behavior — they will need to be flipped to assert the correct behavior once the fix is applied: - 'does NOT call onResize' → 'DOES call onResize' - 'does NOT observe content element' → 'DOES observe content element' Root cause: useEffect dep is [contentRef] (ref object, stable identity), so the effect never re-runs when contentRef.current changes from null to a DOM element. * fix(Chat): use callback ref for content observation (#2282) useXDSChatNewMessages previously depended on a contentRef (ref object) passed as an option, with useEffect dep [contentRef]. Since ref objects have stable identity, the effect only ran once on mount. When XDSChatMessageList mounted conditionally (e.g. {!isEmpty && ...}), contentRef.current was null at effect time and the ResizeObserver never attached — breaking auto-scroll entirely. Fix: useXDSChatNewMessages now returns a callback ref. When the content element mounts or unmounts, the callback fires and the observer attaches/detaches immediately. No state, no version counter — the ref callback itself is the subscription mechanism. XDSChatLayout passes the hook's returned contentRef directly into the layout context. XDSChatMessageList calls it when it mounts, and the observer attaches on the spot. * fix: add type="button" to test buttons
cixzhang
added a commit
that referenced
this pull request
Jun 21, 2026
* feat(storybook): add auto-scroll demo stories for issue #2282 Adds ChatAutoScroll.stories.tsx with three stories demonstrating the difference in auto-scroll behavior between streaming text and discrete block additions (tool calls, custom elements): - ScrollBehaviorComparison: interactive controls to test each case - RapidToolCalls: stress-tests rapid discrete additions - MixedStreamAndTools: realistic sequence showing the transition * fix: use correct XDSBadge label prop and XDSText type - XDSBadge uses label prop, not children - XDSText type='small' doesn't exist, use 'label' instead * test: add failing tests for late-mount contentRef bug (#2282) Adds tests proving that useXDSChatNewMessages does NOT attach its ResizeObserver when contentRef.current is set after the initial effect run (e.g. when XDSChatMessageList mounts conditionally). The tests assert the *broken* behavior — they will need to be flipped to assert the correct behavior once the fix is applied: - 'does NOT call onResize' → 'DOES call onResize' - 'does NOT observe content element' → 'DOES observe content element' Root cause: useEffect dep is [contentRef] (ref object, stable identity), so the effect never re-runs when contentRef.current changes from null to a DOM element. * fix(Chat): use callback ref for content observation (#2282) useXDSChatNewMessages previously depended on a contentRef (ref object) passed as an option, with useEffect dep [contentRef]. Since ref objects have stable identity, the effect only ran once on mount. When XDSChatMessageList mounted conditionally (e.g. {!isEmpty && ...}), contentRef.current was null at effect time and the ResizeObserver never attached — breaking auto-scroll entirely. Fix: useXDSChatNewMessages now returns a callback ref. When the content element mounts or unmounts, the callback fires and the observer attaches/detaches immediately. No state, no version counter — the ref callback itself is the subscription mechanism. XDSChatLayout passes the hook's returned contentRef directly into the layout context. XDSChatMessageList calls it when it mounts, and the observer attaches on the spot. * fix: add type="button" to test buttons
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #2282 — auto-scroll was completely broken when
XDSChatMessageListmounts conditionally (e.g. behind{!isEmpty && ...}).Root Cause
useXDSChatNewMessagesused a ref-object-basedcontentRefas auseEffectdependency. Ref objects have stable identity, so the effect only ran once — on mount. WhenXDSChatMessageListmounted later (after the first message arrived),contentRef.currentwas set but the observer effect never re-ran. No ResizeObserver ever attached →scrollIfLocked()never called → no auto-scroll.This affects any consumer that conditionally renders
XDSChatMessageList(like Clio does with{!isEmpty && <ChatView />}). The Storybook stories didn't catch it because they always render the message list with seed data from the start.Fix
useXDSChatNewMessagesnow returns a callback ref instead of accepting a ref object. When the content element mounts or unmounts, the callback fires and the ResizeObserver attaches/detaches immediately — no state, no version counter. The ref callback itself is the subscription mechanism.Testing
Storybook
Also adds
ChatAutoScroll.stories.tsxwith interactive demos: