{"record":{"id":"c3a426fe8802cda1","repo":"siyuan-note/siyuan","slug":"target-id-s-is-not-in-the-current-order","errorCode":null,"errorMessage":"target ID [%s] is not in the current order","messagePattern":"target ID \\[(.+?)\\] is not in the current order","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":2812,"sourceCode":"\nfunc mergeRequestedSortOrder(currentIDs, requestedPaths []string) (ret []string) {\n\trequestedIDs := make([]string, 0, len(requestedPaths))\n\tfor _, requestedPath := range requestedPaths {\n\t\trequestedIDs = append(requestedIDs, util.GetTreeID(requestedPath))\n\t}\n\treturn mergeRequestedIDOrder(currentIDs, requestedIDs)\n}\n\nfunc reorderIDSequence(currentIDs, sourceIDs []string, targetID, position string) (ret []string, changed bool, err error) {\n\tif err = validateReorderArgs(sourceIDs, targetID, position); nil != err {\n\t\treturn\n\t}\n\tcurrentSet := make(map[string]struct{}, len(currentIDs))\n\tfor _, id := range currentIDs {\n\t\tcurrentSet[id] = struct{}{}\n\t}\n\tif _, exists := currentSet[targetID]; !exists {\n\t\treturn nil, false, fmt.Errorf(\"target ID [%s] is not in the current order\", targetID)\n\t}\n\tsourceSet := make(map[string]struct{}, len(sourceIDs))\n\tfor _, sourceID := range sourceIDs {\n\t\tif _, exists := currentSet[sourceID]; !exists {\n\t\t\treturn nil, false, fmt.Errorf(\"source ID [%s] is not in the current order\", sourceID)\n\t\t}\n\t\tsourceSet[sourceID] = struct{}{}\n\t}\n\tremaining := make([]string, 0, len(currentIDs)-len(sourceIDs))\n\tfor _, id := range currentIDs {\n\t\tif _, source := sourceSet[id]; !source {\n\t\t\tremaining = append(remaining, id)\n\t\t}\n\t}\n\ttargetIndex := -1\n\tfor i, id := range remaining {\n\t\tif id == targetID {\n\t\t\ttargetIndex = i","sourceCodeStart":2794,"sourceCodeEnd":2830,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file.go#L2794-L2830","documentation":"When applying a custom sort, the function validates that the targetID (the block the dragged items are dropped before/after) exists in the current sibling order list. If targetID is absent from currentIDs, it refuses with \"target ID [%s] is not in the current order\". This guards against moving items relative to a sibling that no longer exists or was never part of this parent.","triggerScenarios":"Calling the sort-application API with a targetID that is not among currentIDs — e.g. the target document was deleted or moved to another parent after the frontend built the sort request, or the targetID belongs to a different parent directory's order.","commonSituations":"Stale UI state: user sorted a second list view while the first request's target was deleted; concurrent edits in two windows; frontend passes a block ID (heading/child) instead of the root document ID; IDs from an old snapshot after syncing.","solutions":["Reload the sibling order from the backend and retry the sort with a fresh currentIDs list and targetID","Confirm the targetID is the root document ID of a sibling in the same parent (see error 1399's stricter checks)","Remove stale sort requests in the frontend after document deletion/move operations"],"exampleFix":"// before: stale targetID from cached UI\nMoveDocsSort(sourceIDs, staleTargetID, pos)\n// after: validate target is still a current sibling\ncurrentIDs, _ := loadSiblingCustomOrder(boxID, parentPath, nil)\nif !slices.Contains(currentIDs, targetID) {\n    targetID = currentIDs[len(currentIDs)-1] // fall back to last sibling\n}\nMoveDocsSort(sourceIDs, targetID, pos)","handlingStrategy":"validation","validationCode":"const currentIDs = await api.getChildDocs(parentID);\nif (!currentIDs.includes(targetID)) throw new Error('stale targetID');","typeGuard":"const isValidTarget = (id, currentIDs) => typeof id === 'string' && currentIDs.includes(id);","tryCatchPattern":"try { await api.sortDocs(sources, targetID, pos); } catch (e) { if (String(e).includes('not in the current order')) { await refreshSortModel(); retry(); } else { throw e; } }","preventionTips":["Refresh the sibling list after every delete/move before issuing a sort","Always pass document root IDs, never inner block IDs","Drop queued sort operations when their target document is deleted"],"tags":["go","validation","sorting","stale-state"],"backgroundTag":"resource-not-found","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"}