#Nanostores used in SSR

17 messages · Page 1 of 1 (latest)

azure sable
#

Are nanostores safe to use in the server during SSR ?
Recently this post about zustand for RSC and SSR got a lot of traction.https://github.com/pmndrs/zustand/discussions/2200
And I'm wondering if nanostores have the same issues.

Will the stores be cached due to "hot" serverless functions, resulting is users receiving the wroung UI ?

GitHub

PSA: There's no such thing as state on server. It's unwise to do anything that assumes there is. I feel like there's a lot of people who believe we can use Zustand to add state manageme...

deep pulsar
drifting ingot
#

You can use them in .astro but the question about if they are cached in hot functions is valid, and I'd gues they would be

#

thats some good insight

#

a clientside nanostore wouldnt have this issue though and I think thats the typical use

azure sable
#

I mostly care about the "hot functions" issue. Here's what i have.

  1. Middleware populates locals.user with {userId: '1'}
  2. In a top level layout i read from locals.user and sto $store.set(locals.user)
  3. Somewhere nested inside this page a React component exists that will read the user from the store during SSR by doing useStore($store)
  4. Later I do something similar for client side but this should not matter.

So my question is if 2. and 3 are affected due to hot functions because the store is a global variable

umbral quest
drifting ingot
#

<@&1129102257422610512> anyone have any insight?

normal kiln
#

Within Node and Bun you wouldn't even need to pass a scope around or anything. That is built into the runtime propagating across every function boundary

umbral quest
normal kiln
#

No, that means you can implement a store that is safe to use on SSR that has all the same API, without having to pass around a scope or reference as proposed on the issue

azure sable
#

Any hints on how to implement a contextual store ? Will AsyncLocalStorage be an appropriate solution ?

azure sable
normal kiln
#

Just to be sure that you are aware of it. This restricts the possible runtimes that can use your library to just Node and Bun, possibly just Node.

#

If that is fine to you, go ahead 🙂