Skip to content

fix(ui): prevent mobile scroll flickering during AI streaming#16625

Open
fkxxyz wants to merge 1 commit intoanomalyco:devfrom
fkxxyz:fix/mobile-scroll-flickering
Open

fix(ui): prevent mobile scroll flickering during AI streaming#16625
fkxxyz wants to merge 1 commit intoanomalyco:devfrom
fkxxyz:fix/mobile-scroll-flickering

Conversation

@fkxxyz
Copy link
Copy Markdown

@fkxxyz fkxxyz commented Mar 8, 2026

Issue for this PR

Closes #16622

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR adds mobile touch event support to prevent infinite scroll flickering during AI streaming responses.

Problem:
When users try to scroll up on mobile devices while AI is generating responses, the page flickers and jumps back to the bottom repeatedly, making it impossible to read previous messages.

Root Cause:
Mobile touch events were not being captured - only desktop wheel events were handled. This caused the auto-scroll system to not detect when mobile users were manually scrolling.

Note on v1.2.24:
The core fix for respecting userScrolled state (if (!force && store.userScrolled) return at line 87) was already included in v1.2.24's refactored scroll logic. This PR complements that fix by adding mobile touch event detection.

Changes Made:

  1. Added handleTouchStart() function to detect mobile touch interactions:

    • Sets userScrolled flag when user touches the screen
    • Triggers onUserInteracted callback
    • Prevents auto-scroll from resuming during user interaction
  2. Registered touchstart event listener for mobile devices:

    • Added event listener with { passive: true } for performance
    • Added cleanup in the cleanup function to prevent memory leaks

Why This Works:

  • When a user touches the screen on mobile, handleTouchStart immediately marks the interaction
  • The existing scrollToBottom() logic (line 87) checks userScrolled and returns early
  • This eliminates the conflict between user scrolling and auto-scroll, preventing the flickering
  • Desktop behavior remains unchanged (still uses wheel events)

Files Changed:

  • packages/ui/src/hooks/create-auto-scroll.tsx (10 lines: 1 function + event listeners)

How did you verify your code works?

  1. Rebased onto v1.2.24 and resolved conflicts
  2. Tested on iOS Safari and Android Chrome
  3. Started a conversation with AI that generates long responses
  4. While AI was streaming, scrolled up to read previous messages
  5. Verified that:
    • No flickering occurs on mobile devices
    • Scroll position stays where the user left it
    • Auto-scroll resumes when user scrolls back to the bottom
    • Desktop behavior remains unchanged
    • TypeScript compilation passes

Screenshots / recordings

Mobile testing shows smooth scrolling without flickering during AI streaming. The fix has been verified on both iOS and Android devices.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

- Respect userScrolled state in smoothScrollToBottom() instead of forcibly resetting it
- Add handleTouchStart() to detect mobile touch interactions
- Register touchstart event listener for mobile devices

Fixes anomalyco#16622
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.

[BUG]: Mobile web UI infinite scroll flickering during AI streaming

1 participant