Skip to content

Commit

Permalink
Make usePaginationFragment compatible with <Activity>
Browse files Browse the repository at this point in the history
Summary:
Fixes several issues with  `usePaginationFragment()` to make it compatible with unstable `<Activity>` API. The motivating bug was as follows:

* Load some component with pagination inside an `<Activity>`
* Call loadNext()
* While the request is still pending, hide the Activity component
* (request completes)
* Reveal the Activity component again

In this case the ideal behavior is that the component observes the pagination results when it is revealed and `hasNext` reflects the correct value. However, what was happening is that the fetch was being unsubscribed at the network level on unmount (or in this case, on detach), such that the results were never even written into the store.

As the bug demonstrates, cancelling work in "unmount" can leave a component in an inconsistent state. For example, the component might internally set state to track that it is pending and therefore not attempt to initiate any more fetches.  There are a few approaches - uses actions is one - but the fix here is to simply not cancel the fetch on unmount, in case it's actually just a detach. We continue to write the new results to the store and call internal and user callbacks so that the component state can update in sync with the updated store state.

Reviewed By: tyao1

Differential Revision: D62474325

fbshipit-source-id: 66fa4522cda7897c56dd77ad4c13a4382f5f15db
  • Loading branch information
Joe Savona authored and facebook-github-bot committed Sep 11, 2024
1 parent cb1b4df commit 4acf3f2
Show file tree
Hide file tree
Showing 6 changed files with 3,660 additions and 3,048 deletions.
Loading

0 comments on commit 4acf3f2

Please sign in to comment.