{"record":{"id":"a7426a6148766793","repo":"siyuan-note/siyuan","slug":"document-versions-do-not-belong-to-the-same-docume","errorCode":null,"errorMessage":"document versions do not belong to the same document","messagePattern":"document versions do not belong to the same document","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history_diff.go","lineNumber":163,"sourceCode":"\t\treturn \"\", fmt.Errorf(\"unsupported document version type [%s]\", ref.Type)\n\t}\n}\n\n// DiffDocVersions 比较同一文档的两个版本，并返回带临时差异标记的只读块 DOM。\nfunc DiffDocVersions(leftRef, rightRef *DocVersionRef) (ret *DocVersionDiffResult, err error) {\n\tif (nil != leftRef && docVersionCurrent == leftRef.Type) || (nil != rightRef && docVersionCurrent == rightRef.Type) {\n\t\tFlushTxQueue()\n\t}\n\tleft, err := loadDocVersion(leftRef)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tright, err := loadDocVersion(rightRef)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif \"\" != left.rootID && \"\" != right.rootID && left.rootID != right.rootID {\n\t\treturn nil, errors.New(\"document versions do not belong to the same document\")\n\t}\n\n\tret = &DocVersionDiffResult{\n\t\tDifferences:   []*DocVersionDifference{},\n\t\tLarge:         left.large || right.large,\n\t\tTitleModified: left.title != right.title,\n\t}\n\tif nil == left.tree || nil == right.tree {\n\t\tret.Fallback = true\n\t\tret.Message = docVersionFallbackMessage(left, right)\n\t\tret.TitleModified = false\n\t\tret.Left = renderFallbackDocVersion(left)\n\t\tret.Right = renderFallbackDocVersion(right)\n\t\treturn\n\t}\n\tif ret.TitleModified {\n\t\tret.Differences = append(ret.Differences, &DocVersionDifference{\n\t\t\tID:       left.tree.Root.ID,","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history_diff.go#L145-L181","documentation":"DiffDocVersions loads both version references; if both sides resolved to non-empty root IDs that differ, the two versions cannot belong to the same document and the diff is refused with this error. Comparing versions of two different documents is not a defined operation.","triggerScenarios":"DiffDocVersions(leftRef, rightRef) is called where left.rootID != right.rootID and both are non-empty - e.g. user selected two history entries of different docs, or a client passed a current-doc ref and a history/snapshot ref belonging to another document.","commonSituations":"Frontend diff UI state stale after the user switched documents; IDs mixed up in a custom script; a document was deleted and recreated (new root ID) and an old history ref is paired with the new current ref; sync replaced the document with different ID.","solutions":["Ensure both DocVersionRefs reference the same document's versions.","Refresh the client's version list for the currently open document before diffing.","If the document was deleted and recreated, diff against the old doc's history entries only (both sides from history), not the new current doc.","Check sync history: a document ID change means old and new are different documents."],"exampleFix":"// before\ndiff, err := model.DiffDocVersions(refOfDocA, refOfDocB)\n// after\nif rootIDOf(refOfDocA) != rootIDOf(refOfDocB) {\n    return fmt.Errorf(\"cannot diff versions of different documents\")\n}\ndiff, err := model.DiffDocVersions(refOfDocA, refOfDocA2)","handlingStrategy":"validation","validationCode":"// resolve both refs first and compare root IDs\ntype rooter interface{ RootID() string }\nif a, b := rootIDOf(leftRef), rootIDOf(rightRef); a != \"\" && b != \"\" && a != b {\n    return fmt.Errorf(\"refs point to different documents: %s vs %s\", a, b)\n}\ndiff, err := model.DiffDocVersions(leftRef, rightRef)","typeGuard":null,"tryCatchPattern":"diff, err := model.DiffDocVersions(leftRef, rightRef)\nif err != nil && strings.Contains(err.Error(), \"do not belong to the same document\") {\n    return fmt.Errorf(\"refresh version list: selection mixed documents\")\n}","preventionTips":["Re-fetch the version list when the open document changes","Never mix refs captured for different documents","Treat deleted-and-recreated docs as different documents"],"tags":["validation","document-history","diff","identifier"],"backgroundTag":"incompatible-source-type","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"}