Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn SSR off and use Pinia store as recommended #3

Merged
merged 4 commits into from
Sep 7, 2023
Merged

Conversation

krazkidd
Copy link
Owner

@krazkidd krazkidd commented Sep 7, 2023

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 use computed() 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).

@krazkidd krazkidd self-assigned this Sep 7, 2023
@krazkidd krazkidd merged commit 36bf537 into main Sep 7, 2023
@krazkidd krazkidd deleted the pinia-two branch September 7, 2023 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant