DOM nodes of rendered content are not available in onMounted hook on HMR
Environment
- Operating System:
Darwin - Node Version:
v18.12.0 - Nuxt Version:
3.0.0 - Nitro Version:
1.0.0 - Package Manager:
[email protected] - Builder:
vite - User Config:
css,app,modules,postcss - Runtime Modules:
@nuxt/[email protected] - Build Modules:
-
Reproduction
https://stackblitz.com/edit/github-k7uuyg?file=pages/[...slug].vue
To demostrate it, I used the scrollHeight/children property of the wrapper element. On initial render, correct values are displayed. If you try to comment/uncomment false to trigger reload, height equals to 0 and no child is found.

Describe the bug
If I try to access the DOM nodes rendered by any of the content components, they are available on first render in an onMounted hook but not on HMR.
I also noticed that this happens only to nodes rendered from markdown. For example if adding: <h1>{data.title}</h1> before <ContentRendererMarkdown />, the h1 is found.
Workaround:
Had no luck with nextTick() or plain setTimeout but the following workaround seems to work:
onMounted(async () => {
await new Promise((resolve) => setTimeout(resolve));
// Code to access nodes...
});
Additional context
No response
Logs
No response
I ran into this issue as well, except with the following:
<ContentList v-slot="{ list }" query="{ path: `/content/${slug}` }">
I'm using:
"@nuxt/content": "^2.6.0",
"nuxt": "^3.4.0"
The following workaround, as mentioned by @vertigo09:
onMounted(async () => {
await new Promise((resolve) => setTimeout(resolve))
// Code to access nodes...
})
didn't work for me when using ContentList but it did work when I switched to using:
const { data: content } = useAsyncData('content', () => {
return queryContent(`/docs/content${route.path}`).find()
})
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Still bugged out