useHead causes flickering when hydrating SSR-rendered page on Nuxt
See original GitHub issueOriginal issue is https://github.com/nuxt/framework/issues/5735
Environment
- Operating System:
Linux
- Node Version:
v16.14.0
- Nuxt Version:
3.0.0-rc.4
- Package Manager:
npm@8.3.1
- Builder:
vite
- User Config:
modules
,css
- Runtime Modules:
@nuxtjs/tailwindcss@5.1.3
- Build Modules:
-
Reproduction
Use useHead
to assign some CSS classes to body, and then visit the page:
<script setup lang="ts">
useHead({
bodyAttrs: {
class: 'accent-yellow dark-zinc dark'
}
});
</script>
https://user-images.githubusercontent.com/1329592/177387658-5884e692-6dde-455a-ab0a-34bdefca962f.mp4
Describe the bug
SSR correctly generates classes on body, then on hydration they are removed and then added again, resulting in a very noticeable flicker, especially when these classes are used to switch between dark and light styles of whole page.
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:8
Top Results From Across the Web
useHead causes flicker when hydrating SSR-rendered page
SSR correctly generates classes on body, then on hydration they are removed and then added again, resulting in a very noticeable flicker, ...
Read more >Server Side Rendering - Nuxt
The browser receives the rendered page from the server with the generated HTML. The content is displayed and the Vue.js hydration kicks in,...
Read more >Flickering content when trying to show non-authenticated and ...
This is why you see the "flickering" and I'm afraid there is no easy solution to this problem when your site if fully...
Read more >The head from vueuse - GithubHelp
import { useHead as originalUseHead, HeadObject } from '@vueuse/head' export const ... useHead causes flickering when hydrating SSR-rendered page on Nuxt.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Available in https://github.com/vueuse/head/releases/tag/v0.8.0, will be shipped to Nuxt in the next few days
I was able to workaround this by calling
useHead
in middleware. I was originally setting it in a layout file, so moving the call further up the execution stack works. Not sure why this matters, but hope it helps.