basic progressively enhanced counter not working
In my project I was running into an issue where I was getting the initial state of a variable so I made a minimal reproduction
when javascript is disabled it always displays "0" and when javascript is enabled, it initially shows "0" and then becomes the number it's supposed to be after being clicked
I looked into the produced code and for some reason the
count
variable is duplicated and in some cases the first one is used and in other cases the duplicate is being used4 Replies
I assume this is a bug, though I might also be using the api wrong
here's a repro repo https://github.com/samualtnorman/solid-start-bug.git
global state in SSR is not recommended because then every request regardless of which devices uses the same state, aka global state pollution, to make thr matter worse, now it spans across every request
if you want to persist data, any kind of storage, kv, relational exists and that state can be shared via a context
if you really want it that way, extract it into module, so the server compilation uses the same reference even after bundling
e.g
congrats, you have an server app that works across requests (i dont have a clue how this'd work in a cloud function platform though)
this is running on a good old fashioned self hosted server
I ran into this during development before I set up a real db I thought for development it'd be good enough to temporarily use global state to simulate a db
how come putting the global state into a module forces the same variable to be used but not causes the variable to be duplicated?
routeData is extracted into its own module (hoisted for eager data loading which file system router uses it for setting up routes) and every identifier it uses comes along with it when bundled causes duplication
maybe routeData could also live inside the original route module as an export but i'm not sure about the interop if the module has side effects