Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

[Bug] loading doesn't change back to false if updateQuery doesn't mutate the store #228

Closed
migueloller opened this issue Sep 23, 2016 · 12 comments
Assignees
Labels

Comments

@migueloller
Copy link

This is a continuation of apollographql/apollo-client#698.

@tmeasday,

I'm very low on time at the moment but I'll try to get a PR done in the next couple of days with the failing test case.

@tmeasday tmeasday self-assigned this Sep 23, 2016
@tmeasday
Copy link
Contributor

Thanks @migueloller. I may end up doing this myself, I'll let you know if so.

@tmeasday tmeasday added the bug label Sep 23, 2016
@davidyaha
Copy link

@migueloller @tmeasday Is there any known workaround?
It seems that returning a cloned object will not do the trick.

@migueloller
Copy link
Author

@davidyaha, the way I got to work around it was by checking if the query variable existed and used that as a proxy for loading.

For example, if your top level query is named post then do post !== undefined to check if it has finished loading. This is far from ideal but it worked for me in the mean time while loading is fixed in apollo-client.

I would also recommend to assume that loading is of type ?boolean, as opposed to boolean. I've had a few issues because I assumed that loading would always be true or false but it is sometimes undefined.

@stretchkennedy
Copy link

We do

class Foo extends Component {
  constructor() {
    super();
    this.state = {
      hasRefetched: false,
      refetching: false,
    };
  }

  setRefetchingToFalse() {
    this.setState({ refetching: false });
  }

  fetchMore() {
    this.setState({ refetching: true, hasRefetched: true });
    this.props.data.fetchMore({
      // ...
    }).then(this.setRefetchingToFalse).catch(this.setRefetchingToFalse);
  }

  render() {
    const loading = this.state.hasRefetched ? this.state.refetching : this.props.data.loading;
    // ...
  }
}

It's not perfect by any means, and could have some nasty bugs with regards to loading state in other components, but it works for our use case.

@jbaxleyiii
Copy link
Contributor

@migueloller can you try version 0.5.8?

@davidyaha
Copy link

@jbaxleyiii From what I see now, it is not changing into true when I use fetchMore. There is a new networkStatus variable instead?

@kojuka
Copy link

kojuka commented Oct 12, 2016

I'm also seeing this bug since updating to 0.5.8 - any work arounds?

@tmeasday
Copy link
Contributor

Ok, I foolishly created a failing test and then realised it doesn't make sense any more: https://github.com/apollostack/react-apollo/tree/228-failing-test

@tmeasday
Copy link
Contributor

@davidyaha you are correct on both counts. See apollographql/apollo-client#707

@tmeasday
Copy link
Contributor

tmeasday commented Oct 21, 2016

@webular by "bug" do you mean the fact that it never goes loading when you fetchMore?

If so a "workaround"[1] is to use your own internal state, just as you would for mutations:

@graphql(...)
class Foo extends React {
  onFetchMore() {
     this.setState({ fetching: true });
     this.data.fetchMore(...)
        .then(() => this.setState({ fetching: false });
  }
}

We should document this better but I'm going to close this because this isn't really a bug any more.

[1] Arguably this behaviour is more correct than before, but we did take away a feature I guess ;)

@jasonmorita
Copy link

jasonmorita commented Apr 22, 2017

I am still having this issue. I see in the docs that loading is used to show <Loading />, but for me the component doesn't re-render during fetchMore and by the time it does re-render, loading is false

What am I doing wrong here? (assume my code is the same as the docs because that is what I used as a model)

@ramsaylanier
Copy link

👍 also still having this issue

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

No branches or pull requests

8 participants