pmndrs / valtio

🧙 Valtio makes proxy-state simple for React and Vanilla
https://valtio.dev
MIT License
9.02k stars 251 forks source link

There is a defect in the ref in proxyWithHistory #724

Closed 18613109040 closed 1 year ago

18613109040 commented 1 year ago

An error was reported when a ref property was recovered using the proxyWithHistory component

Please include a minimal reproduction. For details, go to add -> undo -> redo

18613109040 commented 1 year ago

deepClone in proxyWithHistory wants keywords for ref not to be converted to a proxy structure

const deepClone = (obj: T): T => { if (!isObject(obj)) { return obj } const baseObject: T = Array.isArray(obj) ? [] : Object.create(Object.getPrototypeOf(obj)) Reflect.ownKeys(obj).forEach((key) => { if (key === 'ref') { baseObject[key as keyof T] = Reflect.get(obj, key); } else { baseObject[key as keyof T] = deepClone(obj[key as keyof T]); } }) return baseObject }