Skip to content

Conversation

RishiAhuja
Copy link

@RishiAhuja RishiAhuja commented Oct 9, 2025

Pull Request Description

Feature Preview

Before

before.mov

After

after.mov


What This PR Does

This PR fixes the page flickering issue that occurs when rapidly clicking between pages in the sidebar (#8252).

The Problem:
When users click rapidly between pages in the sidebar, all those clicks were being processed sequentially. Each click triggered a navigation event, causing the page to rapidly switch and re-render, creating a visible flickering effect (A→B→C→D).

I tried to implement a two-layer approach:

  1. UI-level throttling: Added throttling in view_item.dart on the sidebar click handler. Subsequent clicks within a 200ms window are ignored. This interval feels instantaneous to the user but is effective at catching most unintentional rapid clicks.

  2. Bloc-level deduplication: As a fallback, logic has been added to tabs_bloc.dart. The bloc now tracks the most recently opened plugin and its timestamp. If another request to open the same plugin arrives within a 500ms window, it is ignored. This prevents duplicate events from causing re-renders.

This implementation uses simple DateTime comparisons, avoiding the need for Timer objects or more complex state management, and is similar to the Debounce utility already used elsewhere in the codebase.

Files Modified:

  • lib/workspace/presentation/home/menu/view/view_item.dart - Added _handleViewTap() method with click throttling
  • lib/workspace/application/tabs/tabs_bloc.dart - Added plugin deduplication in openPlugin handler

Issues

Fixes #8252


PR Checklist

  • My code adheres to AppFlowy's Conventions
  • I've listed at least one issue that this PR fixes in the description above.
  • I've added a test(s) to validate changes in this PR, or this PR only contains semantic changes.
  • All existing tests are passing.

Note: Manual testing performed on macOS. The fix prevents flickering while maintaining responsive navigation. Would appreciate testing on other platforms (Linux, Windows) to ensure consistency.


Summary by Sourcery

Prevent rapid navigation flicker by throttling sidebar taps and deduplicating plugin open events

Bug Fixes:

  • Throttle sidebar item taps within 200ms in view_item.dart to ignore rapid clicks
  • Deduplicate plugin open events within 500ms in TabsBloc to skip repeated navigation requests

Copy link
Contributor

sourcery-ai bot commented Oct 9, 2025

Reviewer's Guide

Implements a two-layer approach that throttles rapid sidebar clicks at the UI level and deduplicates consecutive plugin open events in the bloc to eliminate flicker during fast navigation.

Sequence diagram for sidebar click throttling and plugin deduplication

sequenceDiagram
actor User
participant Sidebar (view_item.dart)
participant TabsBloc (tabs_bloc.dart)
participant Plugin
User->>Sidebar (view_item.dart): Clicks sidebar item
Sidebar (view_item.dart)->>Sidebar (view_item.dart): Check last click time
alt Click within 200ms
Sidebar (view_item.dart)-->>User: Ignore click
else Click after 200ms
Sidebar (view_item.dart)->>TabsBloc (tabs_bloc.dart): onSelected()
TabsBloc (tabs_bloc.dart)->>TabsBloc (tabs_bloc.dart): Check last opened plugin and time
alt Same plugin within 500ms
TabsBloc (tabs_bloc.dart)-->>Sidebar (view_item.dart): Ignore event
else New plugin or after 500ms
TabsBloc (tabs_bloc.dart)->>Plugin: Open plugin
end
end
Loading

Class diagram for updated click throttling and deduplication logic

classDiagram
class SingleInnerViewItem {
  +onSelected(context, view)
}
class _SingleInnerViewItemState {
  -DateTime? _lastClickTime
  -static const _clickThrottleDuration
  +void _handleViewTap()
}
SingleInnerViewItem <|-- _SingleInnerViewItemState

class TabsBloc {
  -String? _lastOpenedPluginId
  -DateTime? _lastOpenTime
  -static const _deduplicationWindow
  +openPlugin(plugin, view, setLatest)
}
Loading

File-Level Changes

Change Details Files
Add click throttling to sidebar view taps
  • Introduce _lastClickTime and throttle duration constant
  • Implement _handleViewTap to ignore taps within 200ms
  • Replace direct onTap call with throttled handler
lib/workspace/presentation/home/menu/view/view_item.dart
Add plugin open deduplication in TabsBloc
  • Track last opened plugin ID and timestamp
  • Ignore openPlugin events for same plugin within 500ms window
  • Update openPlugin handler to apply deduplication logic
lib/workspace/application/tabs/tabs_bloc.dart

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart:83-86` </location>
<code_context>
+            final now = DateTime.now();
+
+            // deduplicate. skip if same plugin was just opened
+            if (_lastOpenedPluginId == plugin.id && _lastOpenTime != null) {
+              final timeSinceLastOpen = now.difference(_lastOpenTime!);
+              if (timeSinceLastOpen < _deduplicationWindow) {
+                return;
+              }
+            }
</code_context>

<issue_to_address>
**question:** Deduplication logic may block legitimate rapid plugin switches.

This logic may block valid rapid switches between plugins with the same ID. Consider if this matches the desired UX, or if deduplication should use additional context like view ID.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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] Switching too fast between pages causes issues

1 participant