Practice of handling application globals in Solid(Start) symmetrically across client and server?

Example: In the CSR-only days it was idiomatic to store context value as a module-global value:
// file: counter.jsx
import { createSignal, createContext, useContext } from "solid-js";

// **This is a module global**
const CounterContext = createContext();

export function CounterProvider(props) {
const [count, setCount] = createSignal(props.count || 0),
counter = [
count,
{
increment() {
setCount(c => c + 1);
},
decrement() {
setCount(c => c - 1);
}
}
];

return (
<CounterContext.Provider value={counter}>
{props.children}
</CounterContext.Provider>
);
}

export function useCounter() { return useContext(CounterContext); }
// file: counter.jsx
import { createSignal, createContext, useContext } from "solid-js";

// **This is a module global**
const CounterContext = createContext();

export function CounterProvider(props) {
const [count, setCount] = createSignal(props.count || 0),
counter = [
count,
{
increment() {
setCount(c => c + 1);
},
decrement() {
setCount(c => c - 1);
}
}
];

return (
<CounterContext.Provider value={counter}>
{props.children}
</CounterContext.Provider>
);
}

export function useCounter() { return useContext(CounterContext); }
In SolidStart's SSR processing modules are reused across multiple concurrent requests so that CounterContext module global gets constantly overwritten (last one wins). Now this can be mitigated through use of isServer and getRequestEvent.localsbut it seems an approach with client/server symmetry would be beneficial. Seems the Svelte community had a discussion about this two years ago Safe SvelteKit Stores for SSR
GitHub
Sharing a global variable across multiple requests is unsafe in SSR...
Describe the bug In adopting Svelte for our chat+communities app, we are trying to utilize the Store for our complex state needs. In this process, we came across semantic differences between stores...
DEV Community
Safe SvelteKit Stores for SSR
One of my favourite things about Svelte is the simplicity of svelte/store for state management -...
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server