Next.js Discord

Discord Forum

Soft Navigation stopped working & Hydration error

Answered
ncls. posted this in #help-forum
Open in Discord
Avatar
Hello,

my app recently just stopped taking advantage of soft navigation but rather reloads the whole page every time and I don't know why. Could the hydration error be the issue?
I added a dark mode using [next-themes](https://npmjs.com/package/next-themes) and the toggle causes a hydration error because the SVG inside is not the same in dark mode but the server expects the icon that's shown in light mode. Adding suppressHydrationWarning to the HTML does not work.

This is my theme toggle:
<Button
  style="icon"
  icon={resolvedTheme === 'dark' ? <LuMoon size={24} /> : <LuSun size={24} />}
  onClick={() => setTheme(oppositeTheme)}
/>

Button component:
<button type={type} className={twMerge(baseStyle, className)} disabled={disabled} onClick={onClick}>
  {icon}
  {children}
</button>
Answered by ncls.
The issue was that I didn't have a root layout but rather a couple small layouts.
View full answer

1 Reply

Avatar
The issue was that I didn't have a root layout but rather a couple small layouts.
Answer