-
Notifications
You must be signed in to change notification settings - Fork 787
fetchMore does not rerender redux connected components #549
Comments
I'm actually also experiencing similar issues with fetchMore. Steps to Reproduce
Buggy Behavior(I'm using new and old areas to describe what's really just a cursor split into two.) So my actual code is a bit more complex, but I've rewritten it many times over in search of the issue causing this bug. Eventually, I got to the point where I ripped out Redux & Expected BehaviorI expect that when Version
|
As a bit of an update, I put some logging inside of |
@cdreier @HorizonXP Thanks for reporting the issue. Could one of you provide a quick reproduction with https://github.com/apollographql/react-apollo-error-template? That would help us a lot in resolving this issue. |
@helfer Done: https://github.com/HorizonXP/react-apollo-error-template/tree/fetchmore-data-error-repro That reproduction is a little convoluted, so let me provide context. In my application, I'm loading a number of points from GraphQL that I want to plot on a map. Thus, as the user moves around the map, I'm using fetchMore to get more data points from my GraphQL endpoint. However, I update my query to also send
I've tried to recreate something along these lines in
Step 4 doesn't happen, and while producing this repro code, I may have figured out what's happening. Anyway, here's what happens:
So now I'm not convinced this is a bug in
I think I need to get Redux to not rerender when the state is updated. I'll need to play with this some more. |
You might want to have a look at apollo-client changelog and apollographql/apollo-client#1416
const newList = [
...previousResult.category.list,
...fetchMoreResult.data.category.list,
]; becomes const newList = [
...previousResult.category.list,
...fetchMoreResult.category.list,
]; |
@bondz thank you - already noticed that and was not the problem in my app :/ |
So I was able to get my repro to work correctly. Doesn't work: https://github.com/HorizonXP/react-apollo-error-template/tree/e57e38d24369bfc14904cc1a1d91de6b7c27c539 So what I figured out is that Anyway, I'd chalk this up to some confusion about the interoperability between Apollo, Redux, and React. I'm not sure if there's an action item from this issue. |
Sadly, I can't seem to use this new knowledge to fix my actual project. I can now get it to only fire |
Finally figured it out! The issue was that in my application, my React component was a stateless component, so the closure wasn't being recreated each time. Forcing it to be a class-based component with a stateful function defined on it solved my issue. That took 2 days of debugging. But wow, do I have a better understanding of how this all relates. Sorry for airing this out on the issue tracker! |
I had a similar issue (no redux), and solved by altering two things in my code. My "updateQuery" method would concat an array altering a property on the previous result and return that. I was exporting my component like this:
Now I assign that to a constant before exporting: `const MyComponentWithData = graphql(CONTENT_QUERY, { export default MyComponentWithData;` Not sure why it solves the issue, but maybe it will help someone out. |
Facing the same issue. I played around with different versions and figured out that with apollo-client v0.9.0 and below this issue is not happening regardless of react-apollo version |
@cdreier @yury-dymov I now think this has to do with the fragment matcher. Could you try the solution outlined in the link below and report back, please? |
@rbpinheiro Thanks a lot! I was struggling with this issue for more than a day before I came across your solution. No idea why this solves the problem though. |
looks like a solution was found? |
@jbaxleyiii no, this should be re-open |
I believe I have found a cause/symptom of the problem in my case: adding a new attribute to the returned object. so it the object is: {
id: 100,
a: 1
} So, this doesn't work: // (...)
updateQuery: (previousResult, { fetchMoreResult }) => {
return {
id: 100,
a: 1,
b: 2 // new
}
} But this does: // (...)
updateQuery: (previousResult, { fetchMoreResult }) => {
return {
id: 100,
a: 2, // different
}
} Also, this returns the object in render() without // (...)
updateQuery: (previousResult, { fetchMoreResult }) => {
return {
id: 100,
a: 2, // different
b: 2 // new
}
} |
Resolved: I did not realize that this simply grabbed the data from the server, but does not pass it as props to the component directly -- it still calls the |
Steps to Reproduce
Describe how to reproduce this issue.
componentWillReceiveProps
and connected component rerenders the dataBuggy Behavior
componentWillReceiveProps
is not called after fetchMore returned new state, so nothing new is rendered though the new data is availableExpected Behavior
after fetchMore returns new data,
componentWillReceiveProps
is called and component rerendersVersion
The text was updated successfully, but these errors were encountered: