question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component not re-render in apollo-link-state after upgrading apollo-cache-inmemory to 1.3.*

See original GitHub issue

Intended outcome:

I use apollo link state to save an array of objects to the local client. In apollo-cache-inmemory 1.2.10, the component is able to re-render on pushing new items to the array or deleting one item from the array. After upgrading to 1.3.5, I expected everything would stay the same.

Actual outcome:

However the component fails to re-render at all with 1.3.*.

How to reproduce the issue:

apollo-cache-inmemory 1.2.10:

https://codesandbox.io/s/l99l9r1ml9 (There’s an issue with codesandbox. I have to double click the buttons to trigger the re-render, but on my local, there’s no such issue.)

apollo-cache-inmemory 1.3.5

https://codesandbox.io/s/8xqn9mz0l (It doesn’t work at all, even if I double click either buttons)

Versions

  "dependencies": {
    "graphql": "0.13.2",
    "react": "16.5.0",
    "apollo-cache-inmemory": "1.3.5",
    "apollo-link-state": "^0.4.2",
    "apollo-link-http": "1.5.5",  
    "react-apollo": "2.2.4",
    "react-dom": "16.2.0",
    "apollo-client": "^2.4.2",
    "graphql-tag": "^2.10.0"        
  },

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:33 (15 by maintainers)

github_iconTop GitHub Comments

6reactions
dmarkowcommented, Oct 18, 2018

Similar issue here going from 1.2.10 to 1.3.5, though I’m using readQuery/writeQuery in the update callback of a mutation. I was using .push to add something to a nested array and writing the data back, but nothing re-rendered. I now have to provide a new top level object to get it to re-render (which I can do with an immutability library, but will require updating hundreds of callbacks in our app).

I also did this based on the documentation examples mutating the cache results:

update: (proxy, { data: { createTodo } }) => {
      const data = proxy.readQuery({ query });
      data.todos.push(createTodo);
      proxy.writeQuery({ query, data });
    }
4reactions
benjamncommented, Oct 20, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

React not re-rendering child component after updating state ...
The Grid component's resetPaint state var is changed from false to true; This causes a re-render of Grid with resetPaint set to true;...
Read more >
@apollo/client | Yarn - Package Manager
Apollo Client is a fully-featured caching GraphQL client with integrations for React, Angular, and more. It allows you to easily build UI components...
Read more >
apollo-cache-inmemory - npm
Core abstract of Caching layer for Apollo Client. Latest version: 1.6.6, last published: 3 years ago. Start using apollo-cache-inmemory in ...
Read more >
Migrating to Apollo Client 3.0 - Apollo GraphQL Docs
Updating imports. The @apollo/client library includes functionality that previously required installing additional packages. As part of migrating to Apollo ...
Read more >
5 Ways to Avoid React Component Re-Renderings
So, it will not re-render the component if the user clicks the same item again and ... React Query library has more than...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found