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

Lazy rendering. #8

Closed
vadimpopa opened this issue Jun 13, 2017 · 14 comments
Closed

Lazy rendering. #8

vadimpopa opened this issue Jun 13, 2017 · 14 comments
Labels

Comments

@vadimpopa
Copy link

I'm beginner in VueJs. I've been trying to optimize some 2 level nested tabs with subtabs that have at least 6 highcharts each one. Currently vue-tabs is lazy rendering, which is good for some scenarios, but thinking how to experiment if still doing lazy rendering but with render only once, so the active tab is not destroyed after transition so next time is not going to be rendered again. Any ideas ?

@cristijora
Copy link
Owner

@vadimpopa This can be achieved with https://vuejs.org/v2/api/#keep-alive

@vadimpopa
Copy link
Author

Yes I saw that, but did a few experiments, haven't noted any difference. So according to you, in the following template where I should add it ?

<template>
  <div class="vue-app-wrapper">
    <vue-tabs>
      <v-tab v-for="(tab, i) in tabs" :key="i" :title="tab.name">
        <vue-tabs>
          <v-tab v-for="(subTab, j) in tab.subTabs" :key="j" :title="subTab.name">
            <div v-for="(type, index) in subTab.charts" :key="index">
              <chart class="Grid-cell" :query="tab.searchQuery" :type="type"></chart>
            </div>
          </v-tab>
        </vue-tabs>
      </v-tab>
    </vue-tabs>
  </div>
</template>

@cristijora
Copy link
Owner

Let's create a jsfiddle and start from there. Please Create one with your example and maybe put something else than charts and point what you want to cache.

@vadimpopa
Copy link
Author

I'll work on it as soon as I'll get more time to play. I noticed that keep-alive is not working well with the v-for, especially in such tabs context. Caching worked but it rendered only the first tab.

@cristijora
Copy link
Owner

Let's start from here https://jsfiddle.net/b44cc4dq/87/

@vadimpopa
Copy link
Author

Ok, see the screenshot, this is what I've got.

screen shot 2017-06-13 at 2 45 08 pm

@cristijora
Copy link
Owner

cristijora commented Jun 13, 2017

Maybe I'm missing something but tabs are already kept in the DOM. Internally they use v-show to display content which sets display:none on the tab.
You can see that all tabs are present in the DOM but only one is visible. The rest have aria-hidden="true"
This also applies to sub-tabs so you might not need keep-alive at all. So

so the active tab is not destroyed after transition so next time is not going to be rendered again

Is actually true by default since tabs are rendered only once and they are present in the DOM

image

Maybe you can detail more on what the issue is exactly. Your chart get's destroyed and re-rendered? How do you know about that

@vadimpopa
Copy link
Author

vadimpopa commented Jun 13, 2017

Yep, you missed pushing a new release with latest changes, and I missed as well this but only now noticed. The npm version is from 9 May, but that fiddle is working with the latests which has the 10 days ago changes. The npm version is working like with v-if.

@cristijora
Copy link
Owner

Oh ok. Thanks for pointing that out. I will try to do small releases with like 1-2 issues from now on so I don't encounter such situations later on. For now you can point to a github repo in package.json so you get the latest version or wait for the next release in 1-2 days.

@vadimpopa
Copy link
Author

vadimpopa commented Jun 13, 2017

Nah, since yours is not going to have lazy rendering it's not suitable anymore for me. I've tested a bunch of libraries like vuetify , vue-material , only vuetify has lazy rendering on tabs (v-if instead of v-show). But besides lazy rendering I need the "render only once"/deferred rendering feature: so when the tab first is activated the content is rendered, next time when the tab is activated again the content should be in DOM already. This called "deferred rendering", ExtJS has this and works very well. I may need to implement the tabs myself with this feature.

Thanks tough for your help. Cu vreo ocazie daca ne vedem in oras, te servesc cu o bere, mi-ar face placere sa mai vb.

@cristijora
Copy link
Owner

Sure, putem vb joracristi@gmail.com. I will think over the issue and see if I can find some solution for that

@cristijora
Copy link
Owner

Ai incercat sa te uiti peste https://vuejs.org/v2/api/#v-once ?

@vadimpopa
Copy link
Author

vadimpopa commented Jun 13, 2017

I have v-once, but is not helping much....anyways looks like vuikit (https://github.com/vuikit/vuikit) does deferred rendering, I haven't looked much into, just did a quick test.

@SSmJaE
Copy link

SSmJaE commented Apr 30, 2021

    @Prop({ default: true }) keepAlive!: boolean;
    @Prop({ default: true }) lazy!: boolean;
    loaded = false;

    render() {
        let loadContentFlag: boolean = false;
        let needToFigureIsActiveAndKeepAlive: boolean = false;

        if (this.lazy) {
            if (this.loaded) {
                needToFigureIsActiveAndKeepAlive = true;
            }
        } else {
            needToFigureIsActiveAndKeepAlive = true;
        }

        if (needToFigureIsActiveAndKeepAlive) {
            if (this.active) {
                loadContentFlag = true;
            } else {
                if (this.keepAlive) {
                    loadContentFlag = true;
                }
            }
        }

        return (
            <section
                class="tab-container"
                id={`p-${this.tabId}`}
                aria-labelledby={`t-${this.tabId}`}
                role="tabpanel"
                v-show={this.active}
            >
                   {loadContentFlag && this.$slots.default}
            </section>
        );
    }

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

No branches or pull requests

3 participants