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
Mounted twice when layout change #5703
Comments
no, you forgot something. The next page must have an other layout and css:false for transition (navigation on client side). I have the same bug locally. |
Someone is alive ? :) |
Hi @usb248 |
Any core team feels concerned ? |
It's not just transition, still mounts twice on |
This still seems to be an issue when transitioning from one layout to another, could we get a re-open? nuxt version 2.9.2 |
Happening with Nuxt version 2.10.0 as well. I am using nuxt generate. It only happens in the production build. |
@amritk @swapneelvivekdesaithoughtworks with the same reproduction from above? If not, please provide one. |
Hit the link and watch the console |
Thanks for your contribution to Nuxt.js!
Issues that are labeled as |
It is still an issue: |
I can confirm this does still happen with Nuxt 2.10.2 when page transitions are enabled. I used to have these objects in my Nuxt config file in order to enable transitions:
I had to remove both of them to prevent pages components to be mounted/created twice. |
As a temporary fix, I wrapped my code inside
|
Don't know if this can help, but I managed to find my problem by putting breakpoints inside the fetch methode to realize the page was being loaded twice, by two different methods. We had an el-menu made by Element-UI, that had inside of it, nuxt-links, so the route was loaded twice simultaneously. I realize this was a coding error but this might help anyone looking for awnsers. Try to trace how the route gets changed ! |
My temporary workaround. ~/plugins/inject-layout.js export default (context, inject) => {
inject('layout', {
// Layout name and route.name of pages that are not dafault layout
map: {
'one-column': ['signup', 'signin'],
'some-other-layout': ['some-route-name']
},
// Property that represents correct layout name of current page
current: 'default'
})
} nuxt.config.js export default {
plugins: ['~/plugins/inject-layout.js']
} ~/mixins/layout.js export default {
// Set and keep correct layout name of current page
layout({ app, route }) {
let layoutName = 'default'
for (const [key, value] of Object.entries(app.$layout.map)) {
if (value.includes(route.name)) layoutName = key
}
app.$layout.current = layoutName
return layoutName
},
data() {
return {
// True while duplicated lifecycle hooks are running
incorrectLayout: this.$nuxt.layoutName !== this.$layout.current
}
}
} ~/pages/**/*.vue import layout from '~/mixins/layout'
export default {
// Layout setting
mixins: [layout],
// Hooks will be executed twice, but
mounted() {
// Return immediately if duplicated runs
if (this.incorrectLayout) return
console.log('This is only displayed once.')
}
} |
This is still occurring for me as of today, in nuxt@2.11.0. My Vue browser extension reports that in the default layout, there are two views and thus everything occurs twice. This is in dev mode. While running in dev mode, if I remove the element from layouts/default.vue, the page structure is cleared. Adding it back, one view appears (according to the Vue browser extension). After that, refreshing the page results in two views, indefinitely. Given that this is happening within Nuxt, I don't know of any workarounds or logical statements that can prevent it. |
similar to #6961 |
I have the same issue with twice mounted on nuxt, what I did is this.
hope it helps. |
I had something similar |
@tsarrB can you provide any details? examples? |
My issue was having a key like this over the components. <div :key="$helper.uuid()">
<ComponentTest></ComponentTest>
</div> |
Hi, is there any update on this? I can still reproduce this in Nuxt version |
Any ideas? Having the same issue |
this works for me |
This helped me :
But I don't understand why this ticket is "closed" ? The problem is still happening in 2.15.8 . |
I can also confirm this as of 2.15.7 SSR Mode (from the previous comment 2.15.8 isn't any different). What helped was wrapping I have page transitions still enabled (
|
Same issue here |
Why close this issue? It's still happen on 2.15.7 |
In my case, I have a component <template>
<div>
<div class="default-layout">
<slot>
<Nuxt />
</slot>
</div>
<TheNavbar />
</div>
</template> In this component, I have a computed that mapped from vuex store. And the navbar will render links dynamically based on that computed. I have to put that template code that uses the vuex state within The state from my vuex is set when a client side plugin executing. If it was set from the server side this will not happen, I guess. |
I am having this problem in version 2.14.3. When I get data from the cookie, the components are mounted twice. I have a link list in footer. I need to show one of these links when language is 'tr' only.
In checkLanguage(), I am getting language data from Cookie.
I don't get any errors while using them, but the components are mounted twice.
|
Have you tried using |
No, actually I solved my problem with computed variable. |
Had the same issue! This thread was a huge help. For me the problem was having multiple elements directly in the page templates. What I had before (triggered double mount):
Fixed (single mount):
I was under the impression you are allowed to have multiple elements in the page template as long as only 1 rendered. Apparently not 🤷♂️ Hope this helps anyone |
In my case, one page had an Components stopped being mounted twice after returning that data directly from the |
none of the above highlighted solution worked for me on nuxt: 2.15.8 |
And problem with same root, layout and page not sync changed. Page1 with layout1 would render in layout2, and after it in layout 1 Some debug log for this problem.
|
It's late but I hope this would be useful for some one. |
@vanminhquangtri what do you have in the |
@trandaison usually because of the splitChunks property inside the build property. Just try to remove the build property to check whether the error is caused by it. |
I faced with the same problem :) are there any ideas ? I have build => transpile that i need ) if I remove it works well |
I solved this problem by overriding export default function (Vue, context) {
const originData = context.app.data;
context.app.data = function () {
const data = originData.call(this);
return {
...data,
layout: 'div',
};
};
} |
Can you say more about your fix? |
Thank you so much |
This was a real head scratcher for us. This workaround worked though, thanks.
|
THIS SOLVE IN MY CASE, splitChunks.layouts = false fix the problem. |
|
Version
v2.6.2
Reproduction link
https://codesandbox.io/s/wn7j570y85
Steps to reproduce
Simply click on button named "Mounted triggered twice, see console" and see in console.
(reproducable only with css:false for transition)
What is expected ?
mounted once
What is actually happening?
mounted twice
Additional comments?
The bug is still present on last release 2.7.1
It can be fixed quickly ? it's really a brake on client-side performance.
(Related : #5616)
The text was updated successfully, but these errors were encountered: