Skip to content

Theme Flicker Problem - localStorage not available on server #64391

Answered by lindjacob
lindjacob asked this question in App Router
Discussion options

You must be logged in to vote

Thank you for your answer.

I actually found a logical solution that was right in front of my eyes.

All I needed to do, was to insert the following line above the return statement in my theme-context.tsx file:
if (!theme) return null;

This prevents the page's content from loading until the correct theme has been retrieved from the local storage on the client side.
Optionally you can add a fade in animation to make the loading transition more smooth.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@lindjacob
Comment options

Answer selected by lindjacob
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants