solid-toast icon indicating copy to clipboard operation
solid-toast copied to clipboard

[SSR] Library isn't compatible with SSR and shares its state between all the clients

Open mattersj opened this issue 2 years ago • 1 comments

Solid-toast creates a store in global scope which is literally just a global variable that's created only once on the server and being shared across all the clients afterwards: https://github.com/ardeora/solid-toast/blob/9d2ce4f76c83ebe5d64602cf8164f60556615b68/src/core/store.ts#L4

Reproduction: https://stackblitz.com/edit/solid-ssr-vite-n1tsrb?file=src%2Froutes%2Findex.tsx,src%2Froot.tsx

  1. Open reproduction and wait till a toast is popped up.
  2. Update the page after this.

As you can see, a toast pops up immediately even though we have a timer set up for this. A toast will still be there even if you comment out this timer and update the page one more time.

I think it makes sense to leverage Context API here and create independent store for every provider, but probably this would require some breaking changes.

mattersj avatar Jul 16 '23 14:07 mattersj

just stumbled over a similar issue. Are there any news about a possible fix in combination with SSR?

matthiasbaldi avatar Feb 07 '24 19:02 matthiasbaldi