Skip to content

fix(frontend): resolve the inbox flickering search issue #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

yassinedorbozgithub
Copy link
Collaborator

@yassinedorbozgithub yassinedorbozgithub commented Apr 13, 2025

Motivation

The main motivation is to fix the inbox flickering search issue.

Fixes #892

Checklist:

  • I have performed a self-review of my own code
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • New Features
    • Introduced a new FilterTextfield component for enhanced filtering capabilities.
  • Bug Fixes
    • Improved state management for the search input, ensuring more reliable updates to the query parameters.
  • Style
    • Refined spacing adjustments in the inbox view for a cleaner and more consistent layout.

@yassinedorbozgithub yassinedorbozgithub added the bug Something isn't working label Apr 13, 2025
@yassinedorbozgithub yassinedorbozgithub self-assigned this Apr 13, 2025
@yassinedorbozgithub yassinedorbozgithub linked an issue Apr 13, 2025 that may be closed by this pull request
Copy link

coderabbitai bot commented Apr 13, 2025

Walkthrough

The changes replace the Search component with a locally defined FilterTextfield in the inbox component. The useSearch hook has been modified to remove direct state synchronization with the router’s query and now provides a debounced onSearch function along with a textFieldProps object for managing input events and state. Layout properties in the grid container were also adjusted.

Changes

File(s) Change Summary
frontend/src/components/inbox/index.tsx Removed the Search component and its related properties; added FilterTextfield with textFieldProps; updated grid layout padding (switched paddingTop to pt, added pb and mx).
frontend/src/hooks/useSearch.tsx Removed effect syncing searchText with the router query; introduced isActive state; updated onSearch to a debounced function; added and returned textFieldProps with new event handlers.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant F as FilterTextfield
    participant H as useSearch Hook
    participant R as Router

    U->>F: Types search input
    F->>H: Triggers onChange (debounced)
    H->>H: Updates searchText state and manages isActive state
    H->>R: useEffect updates router query (updateQueryParams)
    R-->>H: Acknowledges query update
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix flickering of search results in the inbox page (#892)

Poem

In a meadow of code, I hop with glee,
Replacing old search with new, wild and free.
Debounced steps keep flickers at bay, 🐰
My FilterTextfield leads the way.
Hop along, dear coder, and smile today!

~ A happy rabbit coder ~


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbeb21c and 368a4e2.

📒 Files selected for processing (1)
  • frontend/src/hooks/useSearch.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/hooks/useSearch.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: API-Tests
  • GitHub Check: Frontend Tests
  • GitHub Check: Analyze (javascript-typescript)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
frontend/src/hooks/useSearch.tsx (1)

81-85: Consider handling search text clearing.

The effect correctly updates query params when searchText changes, but only if searchText is truthy. This means when a user clears the search field completely, the query parameter won't be updated.

useEffect(() => {
-  if (searchText) {
    updateQueryParams(searchText);
-  }
}, [searchText]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53cb034 and 8e2b89f.

📒 Files selected for processing (1)
  • frontend/src/hooks/useSearch.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Frontend Tests
  • GitHub Check: API-Tests
🔇 Additional comments (4)
frontend/src/hooks/useSearch.tsx (4)

60-60: Good addition of isActive state.

Adding a state variable to track interaction with the search field is a clean approach to fixing the flickering issue. This will help control when the input field gets updated with the searchText value.


74-79: Good implementation of debounce for onSearch.

Debouncing the onSearch function reduces the frequency of state updates while typing, which helps address the flickering issue. The 300ms delay is appropriate for search inputs.

Note that you're already using debounce for updateQueryParams. Having both functions debounced creates a double delay effect, which might make the search feel slightly less responsive but will definitely fix the flickering.


107-116: Good implementation of textFieldProps with clever flickering prevention.

The approach you've taken with the conditional value in textFieldProps is elegant:

  • When the user interacts with the field (isActive is true), the input is allowed to be controlled by its internal state
  • When not interacting (isActive is false), the input shows the debounced searchText value

This effectively prevents the field from resetting while typing, eliminating the flickering issue.


74-116:

❓ Verification inconclusive

Verify this fix works across all browsers and interaction patterns.

The overall approach to fixing the flickering issue is solid. The combination of:

  1. Using debounce to limit state updates
  2. Managing input field control with the isActive state
  3. Decoupling the input field from direct router query synchronization

Should effectively resolve the flickering issue mentioned in PR #892, but it's worth testing across different browsers and interaction patterns to ensure it's consistently fixed.


🏁 Script executed:

#!/bin/bash
# Check if this solution has browser-specific issues or compatibility concerns

# Look for any browser-related issues in the codebase
echo "Checking for browser-specific issues in useSearch or related components:"
rg -i "browser|safari|firefox|chrome|edge" --glob "*.{tsx,ts}" -A 3 -B 3 "src/hooks/useSearch" || echo "No browser-specific issues found."

# Check how this pattern might be used elsewhere
echo "Checking for similar patterns to prevent flickering in other components:"
rg "isActive.*setIsActive" --glob "*.{tsx,ts}" -A 3 -B 3 || echo "No similar patterns found."

Length of output: 2209


Action Required: Ensure Comprehensive Cross-Browser Verification

The debounce and state management approach in frontend/src/hooks/useSearch.tsx now appears solid and consistent with similar patterns used elsewhere (e.g., in LegendItem.tsx and EmojiButton.tsx). Static analysis didn’t reveal any browser-specific code or potential compatibility issues. However, please perform manual testing across all target browsers and interaction scenarios to confirm that the flickering issue is resolved universally.

@yassinedorbozgithub yassinedorbozgithub marked this pull request as draft April 13, 2025 18:42
@yassinedorbozgithub yassinedorbozgithub marked this pull request as ready for review April 13, 2025 19:10
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
frontend/src/hooks/useSearch.tsx (1)

66-66: Consider alternative to delete operator

The delete operator can impact performance as noted by static analysis.

- delete query.search;
+ query.search = undefined;
🧰 Tools
🪛 Biome (1.9.4)

[error] 66-66: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e2b89f and fbeb21c.

📒 Files selected for processing (1)
  • frontend/src/hooks/useSearch.tsx (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
frontend/src/hooks/useSearch.tsx

[error] 66-66: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: API-Tests
  • GitHub Check: Frontend Tests
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
frontend/src/hooks/useSearch.tsx (4)

60-60: Effective state management for flickering prevention

Adding this state variable is a key part of fixing the inbox flickering issue. It helps control when the input field's value is synchronized with the state.


61-78: Good refinement of the query parameter handling

The updated implementation more cleanly handles query parameter updates, especially the empty search case removal. This approach reduces unnecessary URL changes.

🧰 Tools
🪛 Biome (1.9.4)

[error] 66-66: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


79-84: Excellent use of debouncing for search performance

Implementing debounce with a 300ms delay is a crucial improvement to prevent excessive re-renders during typing, directly addressing the flickering issue.


110-119: Smart solution for flickering prevention

This implementation cleverly controls input behavior by:

  1. Setting the value to undefined when active (letting the DOM handle the input value)
  2. Using the controlled value only when not active (preventing input lag)
  3. Managing the active state with mouse events

This effectively prevents flickering by avoiding value synchronization during typing.

@abdou6666
Copy link
Member

This PR works as expected the only thing that can be an issue we can only search if the cursor on search input which might lead to bad UX. If we can find a fix that would be awesome!.

@yassinedorbozgithub
Copy link
Collaborator Author

This PR works as expected the only thing that can be an issue we can only search if the cursor on search input which might lead to bad UX. If we can find a fix that would be awesome!.

Thank you for the feedback 🙏
I will try to enhance the current implementation to cover the mentioned case (when the cursor is not in)

@@ -105,5 +103,15 @@ export const useSearch = <T,>(params: TParamItem<T>) => {
}),
},
},
textFieldProps: {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the motive behind adding this prop?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The main motivation is to group all the fields needed by the Search Text component in one object

@abdou6666
Copy link
Member

When i re-tested this pr i found out that sometimes the flickering still happens.
flickering.webm

@abdou6666 abdou6666 self-requested a review April 14, 2025 14:48
@yassinedorbozgithub yassinedorbozgithub marked this pull request as draft April 14, 2025 15:17
@yassinedorbozgithub
Copy link
Collaborator Author

When i re-tested this pr i found out that sometimes the flickering still happens. flickering.webm

Thank you for the feedback, i have converted the PR to a draft status
an improved version is in preparation 🧑‍💻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix: Flickering search results in the inbox page
4 participants