Deletions mutations have incorrect `original` and `changes` if they were previously updated
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 52/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- typescript
- 領域
- data
研究方向
Start at Transaction.applyMutations, where pending mutations are merged and where delete mutations get original, modified and changes all set to the deletion-time row. Read how PendingMutation is built for deletes and what collection._state.syncedData holds, using the update-then-delete sandbox to reproduce. Done means a delete after an update reports original from before the transaction, modified from just before deletion, and changes as their diff, with a regression test covering bulk updates plus a delete.
由索引模型根據 Issue 內容生成。
描述
- I've validated the bug against the latest version of DB packages
Describe the bug
Deletion mutations have incorrect original and changes if they were previously updated.
To Reproduce
Steps to reproduce the behavior:
- Go to https://codesandbox.io/p/sandbox/yxwtgj
- Click on 'Update'
- Click on 'Delete'
- Observe that
originalandchangesare incorrect
Expected behavior
originalshould be the data since before the current transaction started,modifiedshould be the data before the deletion (might be the same asoriginalif no updates occurred during the transaction), andchangesshould be the difference betweenoriginalandmodified.
Additional context
I run the following fixDeletions workaround in Transaction.applyMutations, which I've monkey-patched:
function fixDeletions(
this: Transaction<any>,
mutations: PendingMutation<any>[],
): void {
// Merge via a globalKey-keyed map rather than a findIndex scan per
// mutation, which is O(n²) for bulk operations (e.g. inserting many rows
// in one call). Map preserves insertion order, matching the previous
// replace-in-place / remove / append semantics.
const merged = new Map<string, PendingMutation<any>>()
for (const mutation of this.mutations) {
merged.set(mutation.globalKey, mutation)
}
for (const newMutation of mutations) {
const { globalKey } = newMutation
if (newMutation.type !== 'delete') {
merged.set(globalKey, newMutation)
continue
}
// Deletions have `original`, `modified`, and `changes` set to the
// state at deletion time.
// `original` should be the actual original, `changes` should be the
// changes between `original` and `modified`
const original =
newMutation.collection._state.syncedData.get(newMutation.key) ?? newMutation.original
const { modified } = newMutation
const keys = new Set([...Object.keys(original), ...Object.keys(modified)])
const changes: Partial<Record<string, unknown>> = {}
for (const key of keys) {
if (
Object.hasOwn(original, key) !== Object.hasOwn(modified, key)
|| !sameRowValue(original[key], modified[key])
) {
changes[key] = modified[key]
}
}
merged.set(globalKey, {
...newMutation,
original,
changes,
})
}
// Rebuild in place to preserve the array's identity for external holders
this.mutations.length = 0
for (const mutation of merged.values()) {
this.mutations.push(mutation)
}
}
- 主要語言
- TypeScript
- 星號
- 4k
- 分支
- 286
- 平均合併
- 1 天 8 小時
- 30 天內合併 PR
- 105
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
TanStack/db 的其他 Issue
-
extractSimpleComparisons returns value: null when the right side of a comparison isn't a literal未關閉
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
`avg`, `min`, `max` and `sum` treat `null` values as `0`可能已有人在做 @oyobbeb 於 11 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
`Collection.currentStateAsChanges` JSDoc examples don’t match `CurrentStateAsChangesOptions`可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 1/5 1-3 小時 新手友好度 88/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
Two @tanstack/db tests time out under CPU load because a cold module import counts against the 5 s default timeout可能已有人在做 @jp-knj 於 23 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
相似的 Issue
-
inference/go type/feature
難度 1/5 1-3 小時 新手友好度 72/100
anomalyco/opencode#65148 · 1 則留言 ·
維護者通常 1 天內回覆
-
truapi-release
難度 2/5 1-3 小時 新手友好度 72/100
paritytech/product-sdk#529 ·
維護者通常 1 天內回覆
-
Add: Mansudae TV未關閉approved check:passed streams:add
難度 2/5 1-3 小時 新手友好度 64/100
維護者通常 1 天內回覆
-
[Perf] Canvas layer composition is quadratic: splitRenderLayers re-copies the node array per node未關閉
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 77/100
devlikeapro/waha#2369 ·
維護者通常 5 天內回覆