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

Fixes person navigation after image upload #9076

Merged
merged 2 commits into from
Dec 18, 2024

Conversation

mdrazak2001
Copy link
Contributor

Fixes #8949

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR modifies the record navigation logic to fix pagination issues that occurred after uploading profile images in the People section.

  • Added id: { neq: objectRecordId } filter in /packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordShowPagePagination.ts to exclude current record from before/after queries
  • Modified cursor-based pagination to properly handle record navigation after image uploads
  • Fixed edge case where navigation buttons were unresponsive after profile image changes

💡 (3/5) Reply to the bot's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

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

Hi @mdrazak2001, thanks for opening a PR :)
Your fix does not feel right though, I've left a comment

@@ -81,7 +83,9 @@ export const useRecordShowPagePagination = (
const { loading: loadingRecordAfter, records: recordsAfter } =
useFindManyRecords({
skip: loadingCursor,
filter,
filter: {
id: { neq: objectRecordId },
Copy link
Member

Choose a reason for hiding this comment

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

this does not feels right to me, we need to retrieve the previous (resp. next) record based on the viewFilters and sort. We cannot remove the filter as you are doing.

Could you explain your change and how you think it's fixing the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @charlesBochet,

Thanks for the feedback! You're right—replacing filter entirely was incorrect. I've updated the code to combine the original filter with { id: { neq: objectRecordId } } to ensure we respect view filters and sorting while excluding the current record (to prevent duplicate pagination results).

Let me know if this works!

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit confused because to me this should not be tied to filters.
It should be tied to cursor / pagination logic. To get the next record for example, we do:

cursorFilter: cursorFromRequest
        ? {
            cursorDirection: 'after',
            cursor: cursorFromRequest,
            limit: 1,
          }
        : undefined,

This should already get the next item without having to change the filters. Why isn't this working?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did some logging to understand the behavior further. Here’s what I observed:

  1. Before the image upload (Added Dummy ids for the below example):
  •     Records Before: []
    
  •     Records After (contains the next person information):
          [
            {
              "__typename": "Person",
              "id": "B"
            }
          ]
    
  1. After the image upload:
  •     Records Before:
           [
              {
                "__typename": "Person",
                "id": "A"
              }
            ]
    
  •     Records After :
           [
              {
                "__typename": "Person",
                "id": "A"
              },
              {
                "__typename": "Person",
                "id": "B"
              }
            ]
    

These responses were returned by useFindManyRecords. It seems that after the image upload, the Records After array includes both the current record and the next record. As a result, when the "Next" button is pressed, it navigates to the current person instead of the expected next person.
This behavior suggests that while the cursor logic retrieves records after the current position, the filtering isn't excluding the current record
Explicitly adding a filter like { id: { neq: currentRecordId } } ensures the current record is excluded, preventing this duplication and aligning the navigation behavior with expectations.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, I think this is an optimistic rendering issue. What's likely happening is that on record update (useUpdateOneRecord) we are triggering optimistic effects triggerUpdateRecordOptimisticEffect.

This Optimistic effects (through cache.modify) is checking if the updated record match the query and if yes it adds it.

  const updatedRecordShouldBeAddedToRootQueryEdges =
          updatedRecordMatchesThisRootQueryFilter &&
          !updatedRecordFoundInRootQueryEdges;

However this logic does not take the cursor into account : it's not because it matches the filter that the record should be added to the query result, it should also check that if we have orderBy + cursor + limit, it should be added.

This is not a big change but might be a bit tricky to implement.

Now I understand your change and even if not completely right it might solve the issue for now

Copy link
Member

Choose a reason for hiding this comment

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

And I think it works

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @charlesBochet for the detailed explanation, am able to connect the dots now!

@charlesBochet charlesBochet merged commit f620fd3 into twentyhq:main Dec 18, 2024
20 checks passed
@charlesBochet
Copy link
Member

Thank you @mdrazak2001, interesting one

Copy link

Thanks @mdrazak2001 for your contribution!
This marks your 2nd PR on the repo. You're top 20% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot navigate to next record after uploading an image identifier
2 participants