xeoneux / next-dark-mode

🌑 Enable dark mode for Next.js apps
https://next-dark-mode.vercel.app
MIT License
218 stars 8 forks source link

Automatic static optimization automatic opt-out problem. #10

Closed amiroff closed 3 years ago

amiroff commented 3 years ago

Thanks for the great library.

Using next-dark-mode causes Next.js app to render pages server-side, thus significantly slowing down first content render by implementing getInitialProps. Is there a way to avoid it?

Here's the build output:

$ next build
info  - Loaded env from D:\Code\NextBook\.env.local
info  - Creating an optimized production build
info  - Compiled successfully 
Warning: You have opted-out of Automatic Static Optimization due to `getInitialProps` in `pages/_app`. This does 
not opt-out pages with `getStaticProps`
Read more: https://err.sh/next.js/opt-out-auto-static-optimization

Usage example: NextBook

amiroff commented 3 years ago

Sorry for not checking this upfront, it has already been discussed to no avail. Closing this ticket now.

xeoneux commented 3 years ago

Hi @amiroff Would you like this library to have an option of using local storage for storing dark mode preferences so that it can be used with automatic static optimisation?

amiroff commented 3 years ago

Hello @xeoneux , that would be perfect tbh, but a mention in docs/readme warning that it could break static builds would prevent surprises 🥇