facebook / facebook/relay

loadMore callback doesn't fire

Open
#2,356 3 comments 0 reactions 0 assignees View on GitHub
wontfix
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Hello. I am not sure if this is by design or a bug.

When having a network layer that uses observables, it seems that you must call `complete` after the first payload. If you don't do this, the callback in the `loadMore(size, callback)` for the pagination container doesn't fire, to me, this sounds like a bug because I don't think you would want to continue to listen on updates after the first payload arrived for these types of queries.

From the network layer, there is no way to determine if the query is a pagination query, refetch query or similar to be able to call `complete`.

I have a solution that works by changing our product code to use an observable with the `next` method defined as the callback instead. AFAIK this will cause a memory leak if we continue to subscribe to new queries but never unsubscribe.

```
relay.loadMore(10, () => { this.setState({ isLoading: false })}); // does not work
relay.loadMore(10, { next: () => this.setState({ isLoading: false })}); // does work
```
So my question is, is this intended to be like this? To me it looks like there is no way at all to unsubscribe unless calling `complete` in the network layer.. however that is not an option for me.

Contributor guide

Open the contributing guide

Research direction

Start at the relay.loadMore(size, callback) entry point and trace how the observable network-layer payload and complete signal affect the callback. Compare the callback form with the { next } form shown in the issue; done means the intended subscription and callback behavior is established, including whether the first payload can finish loading without requiring complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.