why is it possible to use singletons in astro but not solid-start?

when ssr'ing solid with solid-start it's advised not to simply import and export signals/stores, aka singletons, since this could create shared state on the server. With astro on the other hand, this is a pattern that's being used with p.ex nanostores and the like. Is this potential bug of shared server state simply not possible in astro? Will we be able to share global state with singletons once solid-astro makes the move to astro?
3 Replies
thetarnav
thetarnav16mo ago
Both are “bad” for the same single reason. If you mutate the state in the server, it persists for future requests, and may lead to hydration errors since html generated in the request will be different from what client bundle expects when hydrating. So as long as you don’t mutate the global state until the hydration is complete, you’re good Using context is just a convenient way of scoping the state to the request, so leaking state between subsequent request is not possible. But the issue with hydration can still be “achieved”. Issues with hydration are actually easier to achieve in island architecture then in classical ssr, because islands can hydrate at different times, when the global state has already been mutated by a different island.
thetarnav
thetarnav16mo ago
here’s a good issue that illustrates that: https://github.com/solidjs-community/solid-primitives/issues/310
GitHub
Hydration issue · Issue #310 · solidjs-community/solid-primitives
Following withastro/astro#6140 Hello, I have a simple Solid component with a usePrefersDark. I expect the component to render with the default value and then hydrate with the correct value. It'...
bigmistqke
bigmistqkeOP16mo ago
thanks for the clarification 👍
Want results from more Discord servers?
Add your server