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.

Reactivity removed on refresh

See original GitHub issue

I am having trouble with my store elements not continuing to be reactive after refreshing the page. My state to start is empty such that:

const state = {
  items: [],
};

I then am using axios to get information from an API and then pushing objects into this array. Below is my mutation:

loadData(state, response) {
    response.items.forEach(function(item) {
      state.items.push(item);
    });
    // Vue.set(state, 'items', response.items);
  },

When I inspect this property in the console, I can see that the reactive getters and setters are added onto these objects within the array. However, when I refresh the page and inspect these objects, the array is reactive but the actual objects are not.

How can I fix this without having to manually go through and fix this on every single module? (I tried to do a global Vue.set() on the state, but that didn’t fix it either.)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
izziaraffaelecommented, Aug 11, 2018

I had the same issue but I wasn’t able to find a working solution so I decided to switch to Vuex-persistedstate which does not have this issue and provides almost the same functionalities as this package.

1reaction
fdabek1commented, Feb 22, 2018

For anybody that is struggling with this same issue, I just implemented a quick recursive function that solves this solution for now. This is basically a hack so I am hoping that there is a better way to overcome this.

function makeReactive(state) {
  if (typeof state !== 'object') return;

  Object.keys(state).forEach(function (key) {
    if (state[key] !== null && state[key] !== undefined) {
      Vue.set(state, key, state[key]);
      makeReactive(state[key]);
    }
  });
}

export const actions = {
  initial({rootState}) {
    makeReactive(rootState);
  },
};

Just call the action as the first thing on the load of the page.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vuex State not Reactive without Page reload - Stack Overflow
I have played around with async and await by removing them and adding them on certain places. I have used the $nextTick function...
Read more >
"Forcing" a reactive to rerun - Google Groups
In the app I'm working on, I have a 'reactive' (r) that pulls data from a data base which is used in multiple...
Read more >
Advanced Svelte: Reactivity, lifecycle, accessibility
We will learn how to deal with reactivity issues related to updating ... MoreActions : Displays the Check All and Remove Completed buttons, ......
Read more >
[OutSystems Data Grid] Data Grid Reactive
In DataGrid Reactive, when I try to remove the row by clicking Remove Row it gets removed. But, when I refresh the screen...
Read more >
Reactivity in Depth - Vue.js
When you assign or destructure a reactive object's property to a local variable, the reactivity is "disconnected" because access to the local variable...
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