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.

Table sort triggers [vuex] Do not mutate vuex store state outside mutation handlers

See original GitHub issue

When sorting the a table rendered with the code below:

<template>
  <b-table striped hover :items="items" :fields="fields">
    <template slot="username" scope="item">
      {{item.item.username}}
    </template>
    <template slot="isActive" scope="item">
      {{item.item.active?'Yes :)':'No :('}}
    </template>
    <template slot="email" scope="item">
      {{item.item.Email}}
    </template>
  </b-table>
</template>

<script>
  export default {
    name: 'variant-table',
    props: ['items'],
    data: function () {
      return {
        fields: {
          username: {
            label: 'Username',
            sortable: true
          },
          isActive: {
            label: 'is Active'
          },
          email: {
            label: 'E-mail'
          }
        },
        filter: null
      }
    }

  }
</script>

My console throws a Vuex warning to not mutate the store state outside mutation handlers. I don’t feel that disabling strict: true in my store is the way to go.

Could it be a Vuex error inside the boostrap-vue package?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tmorehousecommented, Dec 11, 2017

Table details needs to use Vue’s $set(...) method in order to update the row’s details flag in the record data, which triggers the display of the details scoped slot.

Currently b-table creates a shallow slice() of the items array so that the order of the orignal table order is not mutated. But it doesn’t copy the rows data, rather it maintains the original record object reference.

We had, a few versions ago, switched to a deep copy of the record data, but many people were relying on the data being a reference to the actual data, and the ability to mutate it, so we switched back to using just a slice of the original items array. Not to mention, the overhead that was introduced by the deep copy (slowing the responsiveness of the table) and the lack of ability to clone certain data types and function references (loosing their this bound reference).

1reaction
pi0commented, Apr 26, 2017

@Mark-de-Haan @piotrekfracek Thanks for reporting. 6e1f0a2 should resolve this problem by cloning data when filtering/sorting using slice() and JSON trick is not needed anymore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

do not mutate vuex store state outside mutation - Stack Overflow
SO - to fix that, you'll want to only commit the mutation in the set() handler of your computed property. Then, add an...
Read more >
Do not mutate vuex store state outside mutation handlers
Now this table is draggable / sortable so this changes the “records” so in the dragReorder method first thing I do is clone...
Read more >
Mutate Vuex state directly without using mutations-Vue.js
One of them is that you can make a reactive object outside of your Vue components, import that object into your components as...
Read more >
Mutation Not Committing State Vuex - Nuxt - ADocLib
Stack Overflow works best with JavaScript enabled, Where Vuex inside nuxt app throws Do not mutate vuex store state outside mutation handlers!
Read more >
vuex do not mutate vuex store state outside mutation handlers ...
const items = JSON.parse(JSON.stringify(this.$store.getters['cart/items']))
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