Lazy Head
The lazy head keeps the server tags in place and queues client updates until your app calls head.load().
Set up the client entry
Start with the React SSR setup. In your client entry, import from @unhead/react/lazy. Keep your server entry and existing useHead() calls.
Use a React effect to call finishHydration() after the initial entries have registered. The example places this effect in the parent of App.
import { createHead, UnheadProvider } from '@unhead/react/lazy'
import { useEffect } from 'react'
import { hydrateRoot } from 'react-dom/client'
import App from './App'
const head = createHead()
function Root() {
useEffect(() => {
head.finishHydration()
}, [])
return <UnheadProvider value={head}><App /></UnheadProvider>
}
hydrateRoot(document.getElementById('root')!, <Root />)
With selectively hydrated Suspense boundaries, the root effect can run before their entries register. Move finishHydration() to the point where your app knows the initial boundaries have hydrated.
Choose when to load
Call await head.load() when the app needs to apply queued entries. For example, call it after the destination page commits on the first navigation. Call it after hydration if the initial page needs a client-only tag. Later updates reach the document through the loaded client head.
Use streaming SSR
Keep the streaming server entry. Set Unhead({ streaming: { mode: 'manual' } }) in the Vite plugin. This keeps the streaming transforms and lets the app load the client runtime.
Pass the server's stream key to createHead({ streamKey: '__unhead__' }). Call load() once the server bootstrap is present if you need to apply streamed patches. Call head.discardStream() when leaving the initial page so late patches from that page are ignored.
See the lazy head API for options, preloads, and load errors.