nuxt-community / universal-storage-module

Universal Storage Utilities for Nuxt 2
MIT License
276 stars 15 forks source link

Module overwrites local state in generate mode #75

Closed bdrtsky closed 3 years ago

bdrtsky commented 4 years ago

When in development everything works perfectly. But after I build app with npm run generate it ignores local state and overwrite it with initialState.

I made reproduction - https://github.com/bdrtsky/universal-module-issue

If you change theme in select, then in dev when you refresh the page previous selection preserved, like it's expected. But in prod with generate theme overwritten by initialState.

pi0 commented 4 years ago

Hi @bdrtsky. Thanks for the issue and PR. I think using universal storage for SSG handling is probably not the best way because the SSR version is already rendered with either white or dark. Plugin executes on Client-side which is too late and causes a screen-flash/re-render to change the theme. Probably it would be better using a sync script to inject data-theme class to the body :)