-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Prevent unsafe server-side store updates #9270
Conversation
Damn, that's a smart way to implement this. I think it needs to be configurable/opt-in and/or a warning though.
|
Downgrading it to a warning could work. There's a more immediate practical concern though — using |
Also, the virtual modules are getting out of hand, I'm going to add a dedent utility in a separate PR. We have |
Doesn't |
Hi, this would start breaking our production application. We have a custom wrapper on top of svelte store to make it not accidentally share state on server for different requests, but this change throwing out error is basically going to force us and probably others into looking at other state management libraries instead of using Svelte stores. I think a configurable warning is much better alternative. |
In that case — and since this somewhat complex addition only prevents one specific kind of unwanted side-effect, namely those that happen to use |
Sounds good to me 👍 |
Would it be a good idea to put a After reading all related threads, I found the hardest part, how to test / detect server-side store updates. There's somehow no feedback loop telling instantly, hey, this is wrong (or is there?). Hence, the aforementioned idea. Moreover, Svelte stores are one of the best state management systems where you just code complex state without mental drainage, I just wonder if I can keep this flow also with |
This aliases
svelte/store
to a virtual module that intercepts calls towritable
and overwrites theset
andupdate
methods to throw an error if you try to use them on the server. This means that something like this......would throw an error in development.
We don't want this to apply for stores that were created during load or render, so we track whether that's currently happening and only apply the override when it's not. (Due to the async nature of data loading there's a very small chance of harmless false negatives.)
Needs tests
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.