Fix: Move onChange call before docCache update to detect local changes

Co-authored-by: naielv <109038805+naielv@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-21 12:11:18 +00:00
parent ea54dc5471
commit 492889b9e1

View File

@@ -134,11 +134,12 @@ var DB = (function () {
if (existing) doc._rev = existing._rev;
await local.put(doc);
try { docCache[_id] = typeof doc.data === 'string' ? doc.data : JSON.stringify(doc.data); } catch (e) {}
// FIX: manually trigger map() callbacks for local update
// Call onChange BEFORE updating docCache so that onChange can detect the change
onChange({ doc: doc });
try { docCache[_id] = typeof doc.data === 'string' ? doc.data : JSON.stringify(doc.data); } catch (e) {}
} catch (e) {
console.error('DB.put error', e);
}