Skip to content
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

Fix: Smooth scrolling interrupted during infinite scroll #2540

Open
wants to merge 4 commits into
base: develop-postgres
Choose a base branch
from

Conversation

sezallagwal
Copy link

@sezallagwal sezallagwal commented Dec 1, 2024

What kind of change does this PR introduce?

bugfix

Issue Number:

Fixes #2437

Did you add tests for your changes?

No

Snapshots/Videos:

2437.mp4

If relevant, did you update the documentation?

No

Summary

When scrolling through the user list, the page should load new users smoothly. However, currently, the screen jumps when new users are loaded, disrupting the scrolling experience.

Does this PR introduce a breaking change?

No

Other information

No

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Enhanced user search functionality with improved filtering and sorting options.
  • Bug Fixes

    • Resolved issues with loading states and user display messages for better clarity.
  • Refactor

    • Improved type safety and logic handling within the Users component for a more robust user experience.
    • Streamlined rendering logic for better readability and user data display.

Copy link

coderabbitai bot commented Dec 1, 2024

Walkthrough

The changes made to the Users component in src/screens/Users/Users.tsx focus on enhancing type safety, refining user data handling, and improving the overall code clarity. This includes updates to type annotations for the useQuery hook, adjustments in error handling, and refinements in the logic for user filtering and sorting. Additionally, the rendering logic has been simplified to improve readability and user experience, particularly regarding loading states and user interactions.

Changes

File Change Summary
src/screens/Users/Users.tsx - Enhanced type safety for useQuery hook and refined destructuring.
- Updated parameter type for handleSearchByEnter function.
- Adjusted loadMoreUsers logic to ensure previous state is defined.
- Modified logic for displayedUsers to prevent unnecessary resets.
- Streamlined rendering logic in InfiniteScroll component.

Assessment against linked issues

Objective Addressed Explanation
Smooth scrolling during infinite scroll (#2437)

🐰 In the meadow, we hop and play,
With users loading smooth all day.
Type safety shines, the code is bright,
No more jumps, just pure delight!
So let us cheer, for changes made,
In our happy code, we’ll never fade! 🌼

Warning

Rate limit exceeded

@sezallagwal has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 125d463 and f034bc2.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 resolve resolve all the CodeRabbit review comments.
  • @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.

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

github-actions bot commented Dec 1, 2024

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Congratulations on making your first PR! 🎊 If you haven't already, check out our Contributing Guidelines and PR Reporting Guidelines to ensure that you are following our guidelines for contributing and creating PR.

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

🧹 Outside diff range and nitpick comments (1)
src/screens/Users/Users.tsx (1)

425-475: Consider additional optimizations for smoother scrolling

While the current changes fix the immediate jumping issue, consider these additional improvements for better performance:

  1. Add fixed height to the scroll container to prevent layout shifts
  2. Implement virtualization for better performance with large lists
  3. Add scroll position restoration when users navigate back
 <InfiniteScroll
   dataLength={displayedUsers.length ?? 0}
   next={loadMoreUsers}
   loader={<TableLoader noOfCols={headerTitles.length} noOfRows={perPageResult} />}
   hasMore={hasMore}
   className={styles.listBox}
+  height="calc(100vh - 200px)"
+  scrollThreshold={0.9}
   data-testid="users-list"
   endMessage={
     <div className={'w-100 text-center my-4'}>

Consider using a virtualization library like react-window or react-virtualized for better performance with large lists. Would you like me to provide an example implementation?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c2630ae and 125d463.

📒 Files selected for processing (1)
  • src/screens/Users/Users.tsx (5 hunks)
🔇 Additional comments (3)
src/screens/Users/Users.tsx (3)

176-180: LGTM: Improved type safety

The explicit typing of the keyboard event improves code reliability.


234-236: Great fix: Prevents unnecessary list resets

This change directly addresses the scrolling issue by preventing unnecessary clearing of the displayed users list. Only clearing when the sorting/filtering option actually changes helps maintain scroll position and prevents screen jumps.

Also applies to: 265-267


425-475: Verify the fix across different scenarios

While the changes address the core scrolling issue, please verify the fix works in these scenarios:

  1. Rapid scrolling with slow network
  2. Switching between sort/filter options while scrolling
  3. Different screen sizes and orientations
✅ Verification successful

Based on the shell script results, I can now generate the final response since I have enough information about the infinite scroll implementation across the codebase.

Infinite scroll implementation is consistent and reliable

The codebase shows a consistent pattern for handling infinite scroll scenarios:

  • Uses react-infinite-scroll-component consistently across all list views
  • Proper handling of scroll events and data loading
  • Consistent implementation of loader components and end messages
  • Robust state management for displayed items

The changes in the Users component follow these established patterns and include:

  • Proper data length tracking via displayedUsers.length
  • Standard loader component while fetching more data
  • Clear end-of-results message
  • Maintained scroll position during sort/filter operations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any scroll-related issues or bugs reported in the past
rg -g '!node_modules' -g '*.{tsx,ts,js,jsx}' -A 3 'scroll|InfiniteScroll|jump|position'

# Look for similar implementations in the codebase for consistency
ast-grep --pattern 'InfiniteScroll {
  $$$
}'

Length of output: 61029

src/screens/Users/Users.tsx Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 1, 2024
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

🧹 Outside diff range and nitpick comments (1)
src/screens/Users/Users.tsx (1)

425-475: Add CSS properties for smoother scrolling

While the InfiniteScroll implementation is good, adding specific CSS properties could further improve the smooth scrolling experience.

Add these CSS properties to the listBox class in your CSS module:

 .listBox {
+  overflow-y: auto;
+  -webkit-overflow-scrolling: touch;
+  scroll-behavior: smooth;
   /* ... existing styles ... */
 }

These properties will:

  1. Enable smooth scrolling behavior
  2. Improve touch device scrolling
  3. Prevent sudden jumps during scroll operations
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 125d463 and f034bc2.

📒 Files selected for processing (1)
  • src/screens/Users/Users.tsx (6 hunks)
🔇 Additional comments (2)
src/screens/Users/Users.tsx (2)

115-123: Good: State management improvements help prevent UI jumps

The changes improve the handling of user data updates by:

  1. Adding proper null checks before accessing the users array
  2. Resetting displayed users when sorting/filtering changes
  3. Ensuring clean state transitions during updates

These improvements help prevent the screen jumping issue by maintaining consistent state during data updates.

Also applies to: 234-236, 265-267


87-99: LGTM: Type definitions improve safety

The updated type definitions with optional chaining for the users array provide better type safety and accurately represent the possible states of the GraphQL response.

Let's verify the GraphQL query structure:

✅ Verification successful

Type definitions correctly match the GraphQL query structure

The type definitions in the useQuery hook perfectly align with the USER_LIST query structure:

  • Query variables match: first, skip, firstName_contains, lastName_contains, and order
  • The optional users array type is appropriate as GraphQL queries can return null
  • Type safety improvements don't affect runtime behavior
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the USER_LIST query structure matches the type definitions

# Search for USER_LIST query definition
rg -A 10 "USER_LIST\s*=\s*gql`" 

Length of output: 116


Script:

#!/bin/bash
# Description: Verify the USER_LIST query structure matches the type definitions

# Search for USER_LIST query definition with different syntax
rg -A 10 "USER_LIST.*=.*gql"

Length of output: 1872


Script:

#!/bin/bash
# Let's see the complete USER_LIST query structure including return fields
rg -A 20 "^export const USER_LIST = gql"

Length of output: 1132

src/screens/Users/Users.tsx Show resolved Hide resolved
Copy link

codecov bot commented Dec 1, 2024

Codecov Report

Attention: Patch coverage is 68.42105% with 6 lines in your changes missing coverage. Please review.

Project coverage is 83.77%. Comparing base (c2630ae) to head (f034bc2).

Files with missing lines Patch % Lines
src/screens/Users/Users.tsx 68.42% 6 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #2540       +/-   ##
=====================================================
- Coverage             95.82%   83.77%   -12.05%     
=====================================================
  Files                   295      312       +17     
  Lines                  7037     8118     +1081     
  Branches               1520     1834      +314     
=====================================================
+ Hits                   6743     6801       +58     
- Misses                   98     1179     +1081     
+ Partials                196      138       -58     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@palisadoes
Copy link
Contributor

Please fix the failing tests. Our test code coverage system will fail if any of these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. The code does not comply with our linting check or other related formatting requirements

We do this to ensure the overall reliability of the code base is maintained. This is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

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.

2 participants