joebobmiles / zustand-middleware-yjs

Zustand middleware that enables sharing of state between clients via Yjs.
MIT License
103 stars 10 forks source link

Fix Compatibility with Immer Middleware #54

Open joebobmiles opened 1 year ago

joebobmiles commented 1 year ago

See #53.

Immer invokes Object.freeze on non-primitive values such as arrays and objects. This is how it achieves immutability. This presents two problems for the Yjs middleware:

  1. Client updates must obey Immer's rules for modifying objects and arrays (annoying but doable).
  2. State updates triggered on the client by a peer need to either: a. Invoke Immer's produce function (unfavorable coupling), or b. Detect if the object to modify is frozen or otherwise inextensible and treat it as immutable.