Turn SSR off and use Pinia store as recommended #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After further experimentation, it is clear there is an issue with Pinia and (client side) hydration.
During SSR, our store returns default values because local storage state is local to the server, and these values are serialized and rendered and sent to the client. The client is not hydrating with store values derived from its own local storage but is rather using the server-provided values.
While Pinia supports SSR, it is not guaranteed to work well when server and client state differ, e.g. with local storage. This scenario may be better supported in the future. (See "Advanced SSR" here.)
To fix the hydration issue, we turn SSR off in this PR (
ssr: false
). Though SSR is one of Nuxt's primary selling points, not all modules support universal rendering, and using local storage complicates that even more.The fortunate news is
ssr: false
allows us to implement the Pinia app settings store as recommended by the main Pinia dev. That is, we usecomputed()
state props so we can control writes and persist changes to the local storage. This simplification makes two-way binding easier to set up in Vue templates and components are refactored as necessary.We should also still be able to statically render the app in a client-side render only mode with this change (and make continued use free static site hosting).