{"record":{"id":"0258198c8d21b1eb","repo":"siyuan-note/siyuan","slug":"attribute-view-drop-target-changed-retry-the-drag","errorCode":null,"errorMessage":"attribute view drop target changed; retry the drag","messagePattern":"attribute view drop target changed; retry the drag","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/attribute_view_row_sort.go","lineNumber":202,"sourceCode":"\t\t}\n\t}\n\tif len(moved) != len(selectedIDs) {\n\t\treturn nil, errors.New(\"attribute view rows changed; retry the drag\")\n\t}\n\tif selectedIDs[nextID] || (\"\" == nextID && selectedIDs[previousID]) {\n\t\treturn slices.Clone(ordered), nil\n\t}\n\tindex := 0\n\tif \"\" != nextID {\n\t\tindex = slices.Index(remaining, nextID)\n\t} else if \"\" != previousID {\n\t\tindex = slices.Index(remaining, previousID)\n\t\tif index >= 0 {\n\t\t\tindex++\n\t\t}\n\t}\n\tif index < 0 {\n\t\treturn nil, errors.New(\"attribute view drop target changed; retry the drag\")\n\t}\n\tret := append([]string{}, remaining[:index]...)\n\tret = append(ret, moved...)\n\treturn append(ret, remaining[index:]...), nil\n}\n\n// mergeAttributeViewRowOrder 保留当前尚未参与渲染的项目 ID，避免用页面数据覆盖完整列表。\nfunc mergeAttributeViewRowOrder(original, ordered []string) []string {\n\tret := append([]string{}, ordered...)\n\tseen := map[string]bool{}\n\tfor _, id := range ordered {\n\t\tseen[id] = true\n\t}\n\tfor _, id := range original {\n\t\tif !seen[id] {\n\t\t\tret = append(ret, id)\n\t\t\tseen[id] = true\n\t\t}","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_row_sort.go#L184-L220","documentation":"After extracting the remaining (unselected) rows, moveAttributeViewSortedRows locates the drop target: nextID (or previousID when dropping at the end) must still exist in the remaining list. If neither anchor row is found (index < 0), the drop target row vanished or moved out of the remaining set since the drag started, so the move is rejected and the client is told to retry.","triggerScenarios":"Dropping rows whose nextID/previousID anchor was deleted or itself moved (e.g. it was part of another concurrent drag) between when the drag order was captured and when the move is applied; passing an anchor ID that is one of the selected rows in a mismatched way; sending empty anchors when the previous logic expected one.","commonSituations":"Collaborative editing where another user removes the row you dropped next to; a UI that cached neighbor row IDs before a filter/sort change; automated tests replaying recorded drags against a mutated view.","solutions":["Re-read the current row order and retry the drag with fresh anchor IDs.","Check that nextID/previousID refer to rows present in the current (non-selected) view rows.","Discard the stale drag operation in the client and recompute anchors from the latest render.","Avoid applying drags after any view mutation (filter, sort, delete) without first refreshing the preview."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const remaining = currentRowIds.filter(id => !selected.includes(id));\nif ((nextID && !remaining.includes(nextID)) || (!nextID && previousID && !remaining.includes(previousID))) {\n  // anchors stale: refresh the view before submitting\n}","typeGuard":null,"tryCatchPattern":"try {\n  await commitRowDrag(payload);\n} catch (e) {\n  if (String(e.msg).includes(\"drop target changed\")) {\n    await refreshView(); // recompute nextID/previousID from the fresh render\n  }\n}","preventionTips":["Recompute drop anchors (nextID/previousID) from the latest render at drop time, not drag start","Refresh the view after any filter/sort/delete before applying a queued drag"],"tags":["go","attribute-view","drag-and-drop","stale-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}