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

onEndReached first mount Render fix #46350

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

noman-ansari
Copy link

@noman-ansari noman-ansari commented Sep 5, 2024

[iOS] [ANDROID] [Fixed] - onEndReached Calls on First Mount Fix

onEndReached first mount Render fix
onEndReached will only calls when data is available as there is no need to call onEndReached to call when data is not present which will also prevent onEndReached calls on first mount thus prevent the bug for OnEndReached.

Summary:

Changelog:

[iOS] [ANDROID] [Changed] - onEndReached Calls on First Mount Fix

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

Test Plan:

onEndReached first mount Render fix
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Sep 5, 2024
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

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

this looks good to me. Importing it to have more eyes on it.

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@@ -1542,7 +1542,10 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
this._listMetrics.getContentLength() !== this._sentEndForContentLength
) {
this._sentEndForContentLength = this._listMetrics.getContentLength();
onEndReached({distanceFromEnd});
// It will only runs when data is available and also it wont trigger onEndReached on First Mount as data will be empty
if (data && data.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

From a colleague of mine:

It wont trigger onEndReached on First Mount as data will be empty

This is not true, apart from maybe in this users specific scenario.
It also is inconsistent with the logic below for onStartReached.
And... we can render e.g. headers

From this comment, I believe we can't really land the change (also a test is failing internally, I'm trying to figure out if that's because of this change).

In the body of the PR, you mention:

... will also prevent onEndReached calls on first mount thus prevent the bug for OnEndReached.

Is there an issue for the "bug for OnEndReached"? do you mind linking it here so we can match the issue with the PR?

Copy link
Author

Choose a reason for hiding this comment

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

Hi @cipolleschi ,

In my PR, there are fixes related to two bugs. I encountered an issue where FlatList calls onEndReached twice, even when the data is empty. To address this, I added a check to ensure that onEndReached is only called when there is data, otherwise there is no reason for onEndReached to be triggered.

Additionally, onStartReached is functioning separately and independently. Could you please clarify how it is related to this?

Can you please also elaborate me about the test which has been failed ?

Thank you.

https://github.com/facebook/react-native/issues/45771
https://github.com/facebook/react-native/issues/38090

@cipolleschi cipolleschi self-requested a review September 18, 2024 09:08
@efstathiosntonas
Copy link

efstathiosntonas commented Sep 18, 2024

@cipolleschi hi, this is one (open) bug issue I could find:

Fix OnEndReached Call Twice on First Mount it will only call onEndReached when there is data available
refactor logic
@cipolleschi
Copy link
Contributor

/rebase - this comment automatically rebase on top of main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants