Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

b-table memory leak with vue-router and <keep-alive> #4214

Closed
sprocket99 opened this issue Oct 7, 2019 · 5 comments
Closed

b-table memory leak with vue-router and <keep-alive> #4214

sprocket99 opened this issue Oct 7, 2019 · 5 comments

Comments

@sprocket99
Copy link

Describe the bug

I have a b-table like so:

  <b-table primary-key="id" :fields="packages.fields" :items="packagesData" :filter="packages.filter" :busy="packages.isBusy" head-variant="light" filter-debounce="200" sticky-header no-border-collapse small show-empty hover bordered>
    <div slot="table-busy" class="text-center text-primary">
      <b-spinner class="align-middle"></b-spinner>
    </div>
  </b-table>

And my code is:

  export default {
    data: function () {
      return {
        packages: {
          filter: '',
          fields: [
            {
              key: 'targetType',
              label: 'Target',
              sortable: false,
              thStyle: { width: '100px !important' }
            },
            {
              key: 'fileName',
              label: 'Package',
              sortable: false,
              thClass: 'align-left',
              tdClass: 'align-left'
            },
            {
              key: 'version',
              sortable: false
            },
            {
              key: 'bootType',
              label: 'Boot',
              sortable: false
            }
          ],
          isBusy: false
        }
      };
    },
    async activated() {
      await this.refreshPackages();
    },
    methods: {
      async refreshPackages(force) {
        if (force || !this.packagesData || this.packagesData.length === 0) {
          // only goes in here once...
          this.packages.isBusy = true;
          await this.$store.dispatch('refreshNodePackages', this.$route.params.id);
          this.packages.isBusy = false;
        }
      }
    },
    computed: {
      node() {
        return this.nodesLookup[this.$route.params.id];
      },
      packagesData() {
        return this.nodePackagesLookup[this.$route.params.id];
      }
    }
  };

This page remains active using keep-alive and is launched using:

<b-button @click="$router.push({name: 'node-detail', params: { id: row.item.id }})"></b-button>

Steps to reproduce the bug

  1. Hit the page, DOM node count goes from like 1000 to 8000 (I have 800+ rows in the table)
  2. Press back
  3. Press forward
  4. DOM count increases by 8K every time

Expected behavior

For this to only happen once. I commented out just the HTML for b-table and the issue did not occur, but then I had no table either.

Versions

Libraries:

  • BootstrapVue: 2.0.3

Environment:

  • Browser: Chrome

Here is a .gif of me navigating back and forward on the browser:
memory leak

@tmorehouse
Copy link
Member

tmorehouse commented Oct 7, 2019

@sprocket99 There are issues with Vue's <keep-alive> component:

And a similar issue is present with vue-router and keep-alive

@tmorehouse tmorehouse changed the title b-table memory leak b-table memory leak with vue-router and <keep-alive> Oct 7, 2019
@tmorehouse
Copy link
Member

tmorehouse commented Oct 7, 2019

Which version of Vue and Vue-router are you using?

<b-table> doesn't retain any references to the actual DOM elements (just passes the rendered vNodes to Vue to deal with).

I would suggest removing the <keep-alive> to see if the problem clears up, and if so then it would be related to the upstream bugs with keep-alive and vue router.

@sprocket99
Copy link
Author

I am using:

"axios": "^0.19.0",
"bootstrap": "^4.3.1",
"bootstrap-vue": "^2.0.3",
"core-js": "^2.6.5",
"vue": "^2.6.10",
"vue-axios": "^2.1.5",
"vue-router": "^3.1.3",
"vuex": "^3.1.1"

I think I am on the latest versions of everything. So the bugs are old and fixed at this point. Also I have no max set. I simply have a parent with:

<div class="container-fluid">
  <keep-alive>
    <router-view />
  </keep-alive>
</div>

Also, yes obviously the problem will go away if I take the <keep-alive> off. Since the component will be destroyed and won't have a chance to accumulate anything.

@sprocket99
Copy link
Author

I can discount the router because I can do:

<b-collapse  :visible="expanded">
  // table here with v-if="expanded" also
</b-collapse>

The problem occurs if I expand and collapse this again and again. So the rendering of the table somehow plays into it. Navigation is not needed.

@sprocket99
Copy link
Author

It probably is to do with keep-alive since I can repeat it even when I replace the b-table with a vanilla HTML table. Ill raise upstream, maybe I am doing something incorrectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants