-
Notifications
You must be signed in to change notification settings - Fork 786
Loading state stuck on true and network request is never made #1385
Comments
I created the same issue on the apollo-client repo, but I think it belongs here. |
@jbaxleyiii I've been doing some digging and I think this is related to the {data:{}, loading:true, networkStatus:1, partial:true} It seems like after erroring, the query observable stream doesn't update any more and keeps emitting the same value over and over again (or doesn't emit any new ones). |
I can also confirm that this is still happening on |
I'm having exactly this issue. After a data error, if the same query is reissued then the data loading flag never clears. apollo-client 2.1.0 with react-apollo 2.0.4 |
At this point, and from what we could gather, this seems to me like a serious issue that pretty much renders the component unusable under general circumstances. Input from collaborators would be really nice. @peggyrayzis? |
See this doco:
Does that mean its better to use this instead? |
@prawana-perera It's better if you want your components to behave differently according to which HTTP status you get back from the endpoint. Still, the |
So I've dug into this problem and here's my take on it. This is not actually a bug in the react-apollo code, but in the ObservableQuery code. When an error occurs, the observable query calls cleanup code which tears down the observer, which then triggers the tearDownQuery() code here: Which is fine cause the next call to update the query sets up another observer (after first setting up the query). So based on this PR: https://github.com/apollographql/apollo-client/pull/1154/files it shouldn't immediately fire a query when there are no observers, instead preferring to defer them until an observer appears. Again, no problem. The bug appears when the observer is attached and it tries to fire off another query. This code: https://github.com/apollographql/apollo-client/blob/d4dc034f1a74a177a9187870b96ac6d397064774/packages/apollo-client/src/core/ObservableQuery.ts#L532-L533 remembers the last query and error and returns them to the newly set up observer resulting in incorrect results being sent to the observer, and resolving the internal promise so the real query results are dropped. My solution is to tear down the last error and last result when the last observer dissapears. But again, this is a bug in the apollo client, not react-apollo |
Or probably even better, setVariables should clear the lastResult and lastError |
This PR should has fix it #1531. |
This is still a problem for me, using apollo-client 2.2.1 and react-apollo 2.1.0-beta.0. @fracmak is dead on here. The As @fracmak suggested, removing these lines https://github.com/apollographql/apollo-client/blob/d4dc034f1a74a177a9187870b96ac6d397064774/packages/apollo-client/src/core/ObservableQuery.ts#L532-L533 fixes this for me. |
@fracmak Care to point out the same thing over at the |
Same issue as all the above commenters, with
in my locally |
I'm also experiencing this issue on |
react-apollo@^2.1.0 fixes for me |
@luccasmaso what is your "apollo-client" package version ? thx! |
@ynuska apollo-client@^2.2.8 |
thx! I've updated to react-apollo@^2.1.0 and now I get this error |
Hi all - this should be fixed in newer versions of |
Hey @hwillson , I'm still facing this issue. Sometimes the loading prop stays stuck on true and I can't see any outgoing requests nor requests hitting the backend. I am using |
Thanks @chevalam - re-opening to investigate. |
And similarly with |
+1 |
+1 Facing this in AppSync now |
+1, having this issue in |
Update: This happens if i create the following container: import { compose, graphql } from 'react-apollo';
const query1 = graphql(ACTIVE_ORDERS_QUERY, {
name: 'q1Data',
props: ({ q1Data }, ownProps) => {
return { ...q1Data, ...ownProps };
},
});
const query2 = graphql(ACTIVE_ORDERS_QUERY, {
name: 'q2Data',
props: ({ q2Data }, ownProps) => {
return { ...q2Data, ...ownProps };
},
});
export default compose(
query1,
query2,
)(MyComponent); If I remove the props key from both queries, import { compose, graphql } from 'react-apollo';
const query1 = graphql(ACTIVE_ORDERS_QUERY, {
name: 'q1Data',
// props: ({ q1Data }, ownProps) => {
// return { ...q1Data, ...ownProps };
// },
});
const query2 = graphql(ACTIVE_ORDERS_QUERY, {
name: 'q2Data',
// props: ({ q2Data }, ownProps) => {
// return { ...q2Data, ...ownProps };
// },
});
export default compose(
query1,
query2,
)(MyComponent); I have tried setting @hwillson Please let me know if you need any more info, or if it is something I can do to help! |
Still not fixed! I'm using "apollo-client": "^2.4.5",
"react-apollo": "^2.2.4", and I also tried |
Same. Is there a workaround? |
I figured out that the only things they are not working are the queries they want to get data from the server. All the
So I have to do the following now because withApollo is the only method which is working. I hope it will be fixed soon so that my code will be less complex. class UserContainer extends React.Component {
constructor() {
super();
this.state = {
me: null,
};
}
componentDidMount() {
const { client, authToken } = this.props;
client
.query({
query: getMe,
...createAuthContext(authToken),
})
.then(({ data: { me } }) => this.setState({ me }));
}
render() {
const { me } = this.state;
return me ? <User user={me} /> : null;
}
}
export default compose(
withApollo,
graphql(getAuthToken, {
props: ({ data: { authToken } }) => ({
authToken: authToken.token,
}),
}),
)(UserContainer); |
@ckj Have you found a real solution for this problem? |
@sapkra In my situation I was using multiple enhancers on a component without utilizing |
I figured out a solution for this problem! I forgot to add the following part before my component is rendered. I just added this to my component and the problem was solved. You can find an example in the README of this repository. if (loading) return 'Loading...';
if (error) return `Error! ${error.message}`; The reason why it didn't triggered the request is that the javascript crashed after trying to render the component with no data & This example is missing in the docs so someone can easely get this error. |
Is this still a problem or can it be closed? It is unclear to me from the history. |
I think it can be closed - when someone has still this problem he/she can create a new issue. |
I am still experiencing this issue using the latest version of apollo client, I have open issue #3090 |
I solved this ( |
I'm having an issue using the
graphql
HOC. I'm receiving via props on my wrapped component an object with the variables that are used on the graphql query (let's call it thefilters
object). When an error occurs on the API, thedata { error }
prop is injected correctly into my wrapped component and contains the error that comes on the response. But, after this, when the query is re-run with differentvariables
(due to thefilters
object being updated),graphql
makes NO NETWORK REQUEST at all, and thedata { loading }
prop is stuck ontrue
forever.I've even tried setting the
errorPolicy
toall
. But in that case, thedata { error }
prop always come asundefined
(even when there are errors on the API response). Not sure if this is intended or another bug 😛Here is my wrapped component (I'm using recompose):
I'm using these package versions:
The text was updated successfully, but these errors were encountered: