Environment
Nuxt project info:
|
|
| Operating system |
Linux 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 |
| CPU |
Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz (8 cores) |
| Node.js version |
v22.22.0 |
| nuxt/cli version |
3.34.0 |
| Package manager |
pnpm@8.15.6 |
| Nuxt version |
4.4.2 |
| Nitro version |
2.13.3 |
| Builder |
vite@7.3.2 |
| Config |
app, compatibilityDate, css, devtools |
| Modules |
- |
Reproduction
https://stackblitz.com/edit/github-pt2vwnd7?file=app%2Fapp.vue
Describe the bug
Hello,
Following setup causes the whole page to be duplicated whenever the template branch containing a <NuxtPage> changes:
- You have a wrapper page that renders
<NuxtPage> conditionally AND a <template> tag is used as the direct (conditional) parent of the <NuxtPage>
<script setup lang="ts">
const toggleOn = ref(true);
</script>
<template>
<div>
<button @click="toggleOn = !toggleOn">TOGGLE PATH</button>
<template v-if="toggleOn">
<h4>Path A</h4>
<NuxtPage />
</template>
<template v-else>
<h4>Path B</h4>
<NuxtPage />
</template>
</div>
</template>
- The rendered page contains a component that uses a top-level await in its setup block
<!-- Page index.vue -->
<template>
<div >
<ComponentWithAwait />
</div>
</template>
<!-- ComponentWithAwait.vue -->
<script setup lang="ts">
const someValue = await Promise.resolve(1);
</script>
<template>
<div>
Component with await
</div>
</template>
- Page transitions are enabled in
nuxt.config.ts
In this case whenever the <NuxtPage> branch changes, the whole page gets stuck in the DOM and a new instance of the same page is created under the stuck old page.
As a workaround a div instead of a template can be used to wrap the NuxtPages.
Additional context
There are a few issues that have similar reproductions but I think it is not 100% the same problem. In those cases the order of components was changed or the onMounted hook is called twice:
#28220
#32371
Logs
Environment
Nuxt project info:
Linux 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz (8 cores)v22.22.03.34.0pnpm@8.15.64.4.22.13.3vite@7.3.2app,compatibilityDate,css,devtools-Reproduction
https://stackblitz.com/edit/github-pt2vwnd7?file=app%2Fapp.vue
Describe the bug
Hello,
Following setup causes the whole page to be duplicated whenever the template branch containing a
<NuxtPage>changes:<NuxtPage>conditionally AND a<template>tag is used as the direct (conditional) parent of the<NuxtPage>nuxt.config.tsIn this case whenever the
<NuxtPage>branch changes, the whole page gets stuck in the DOM and a new instance of the same page is created under the stuck old page.As a workaround a div instead of a template can be used to wrap the NuxtPages.
Additional context
There are a few issues that have similar reproductions but I think it is not 100% the same problem. In those cases the order of components was changed or the onMounted hook is called twice:
#28220
#32371
Logs