a-type / verdant

🌿 Storage, sync & realtime for local-first web apps. Build an app in minutes, deploy as a static page, and add sync with a few lines.
https://verdant.dev
GNU Affero General Public License v3.0
188 stars 4 forks source link

list.move() not working #416

Closed a-type closed 1 month ago

a-type commented 1 month ago

Something is up with the view computation and caching.

Move operations appear correctly applied/stored on Entity.

Entity list retains original ordering (I think?)

If I call invalidateCachedView() the immediate view value is correct to the reoredered list.

Running this

items.invalidateCachedView(); items.emit('change'); setTimeout(() => { console.log(items.rawView[0]); }); items.rawView[0]

Shows that rawView is the same now and after the task fires.

But running this

items.invalidateCachedView(); items.emit('change'); setTimeout(() => { console.log(items.cachedView[0].rawView); }); items.cachedView[0].rawView

Shows that cachedView reverts after the task fires.

So something running in a task / microtask is reverting the cached view???

a-type commented 1 month ago

Ugh, it was application code mutating the return of useWatch. Oops. Should... maybe fix that?