Skip to content

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Oct 16, 2025

Summary

This PR fixes the UI flickering issue that occurs when users cancel API responses or restore checkpoints. The flickering was caused by full task recreation triggering complete state refreshes in the React UI.

Problem

When users pressed "Cancel" during an API response or restored a checkpoint, the entire task was recreated from scratch, causing the UI to flicker and sometimes reload completely. This led to:

  • Loss of scroll position
  • Visual flickering
  • Occasional message duplication
  • Poor user experience

Solution

Implemented a "soft reload" mechanism that preserves UI state during these operations:

  1. Added soft reload flag: Tracks when operations should preserve UI state
  2. Implemented state debouncing: Prevents rapid consecutive state updates (50ms delay)
  3. Modified cancel flow: Sets soft reload flag during task recreation
  4. Updated checkpoint restoration: Wraps operations with soft reload state
  5. Enhanced UI handling: Skips state resets when soft reload is active

Changes

  • Added isSoftReloading flag to ClineProvider with proper JSDoc documentation
  • Added STATE_UPDATE_DEBOUNCE_MS constant for maintainability
  • Implemented debouncing in postStateToWebview() method
  • Modified cancelTask() to use soft reload mechanism
  • Updated checkpoint restoration handler to set soft reload state
  • Added isSoftReload property to ExtensionMessage interface
  • Modified ChatView to check for soft reload flag and preserve UI state
  • Added comprehensive unit tests for the new functionality

Testing

  • All existing tests pass
  • Added new tests for debouncing and soft reload functionality
  • Manually tested cancel operations and checkpoint restoration
  • Verified UI state preservation during these operations

Fixes #8677


Important

Implements a soft reload mechanism to prevent UI flickering during cancel operations and checkpoint restoration in the chat UI.

  • Behavior:
    • Implements a soft reload mechanism in ClineProvider.ts to prevent UI flickering during cancel operations and checkpoint restoration.
    • Adds isSoftReloading flag to ClineProvider to track soft reload state.
    • Debounces state updates in postStateToWebview() to prevent rapid consecutive updates.
    • Modifies cancelTask() and checkpoint restoration to use the soft reload mechanism.
    • Updates ChatView.tsx to check for isSoftReload flag and preserve UI state.
  • Testing:
    • Adds unit tests for debouncing and soft reload functionality in ClineProvider.spec.ts and checkpointRestoreHandler.spec.ts.
    • Verifies UI state preservation during cancel operations and checkpoint restoration.
  • Misc:
    • Adds STATE_UPDATE_DEBOUNCE_MS constant for maintainability.
    • Adds isSoftReload property to ExtensionMessage interface.

This description was created by Ellipsis for 42385ae. You can customize this summary. It will automatically update as commits are pushed.

…nt restoration

- Added isSoftReloading flag to ClineProvider to track soft reload state
- Updated ExtensionMessage interface to include optional isSoftReload property
- Modified cancelTask to set/reset soft reload flag around task recreation
- Updated checkpointRestoreHandler to use soft reload flag for checkpoint operations
- Added UI-side handling in ChatView to check isSoftReload flag and skip re-rendering
- Implemented debouncing mechanism (50ms) for state updates to prevent rapid flickering
- Cancel button now passes isSoftReload flag to prevent UI flicker

This fixes the issue where the chat window would flicker and sometimes duplicate messages when users press Cancel to stop an API response or when restoring checkpoints after editing messages.

Fixes #8677
- Add JSDoc documentation for soft reload mechanism
- Use proper TypeScript typing instead of 'as any'
- Extract STATE_UPDATE_DEBOUNCE_MS as named constant
- Add detailed comments explaining the flickering prevention mechanism
@roomote roomote bot requested review from cte, jr and mrubens as code owners October 16, 2025 01:29
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. UI/UX UI/UX related or focused labels Oct 16, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files. UI/UX UI/UX related or focused

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] Chat window flickers and reloads after pressing "Cancel" or restoring checkpoint, causing duplicated messages

2 participants