You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Dexie's immutable cache and useLiveQuery, unchanged items do not retain their references under certain conditions, specifically when using .reverse() or when updating a single item within a transaction.
Using .reverse():
constdb=newDexie("database",{cache: "immutable",});// Always gives a new referenceconstitems=useLiveQuery(async()=>{constitems=awaitdb.items2.reverse().toArray();returnitems;});// Keeps references for unchanged itemsconstitems=useLiveQuery(async()=>{constitems=awaitdb.items.toArray();return[].concat(items).reverse();});// Later...awaitdb.items2.update(item.id,{isActive: !item.isActive});
In the first example, using .reverse() directly on the query results in new references being created, even if the items themselves haven't changed. Conversely, reversing an array after retrieval preserves the references for unchanged items.
Using Transactions:
// useLiveQuery will refresh references even without using .reverse()awaitdb.transaction("rw",item2 ? db.items2 : db.items,async()=>{awaitdb.items.update(item.id,{isActive: !item.isActive});});Whenupdatingasingleitemwithinatransaction,referencesarelost,resultinginnewreferencesforallitemsinthequery,despiteonlyoneitembeingupdated.
Expected Behavior:
Unchanged items should retain their references to avoid unecessary rerenders.
When using Dexie's immutable cache and useLiveQuery, unchanged items do not retain their references under certain conditions, specifically when using .reverse() or when updating a single item within a transaction.
In the first example, using .reverse() directly on the query results in new references being created, even if the items themselves haven't changed. Conversely, reversing an array after retrieval preserves the references for unchanged items.
Expected Behavior:
Unchanged items should retain their references to avoid unecessary rerenders.
Reproducible Example: (open console)
CodeSandbox link
The text was updated successfully, but these errors were encountered: