{"record":{"id":"6a0385f11c45057d","repo":"siyuan-note/siyuan","slug":"active-tab-s-is-not-a-direct-child-of-s","errorCode":null,"errorMessage":"active tab [%s] is not a direct child of [%s]","messagePattern":"active tab \\[(.+?)\\] is not a direct child of \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/treenode/tabs.go","lineNumber":69,"sourceCode":"\t\tvalue = strings.TrimSpace(util.RemoveInvalidRetainCtrl(value))\n\t\tif \"\" == value {\n\t\t\tcontinue\n\t\t}\n\t\tif TabsPositionAttr == name {\n\t\t\tif \"top\" != value && \"left\" != value {\n\t\t\t\treturn fmt.Errorf(\"invalid tabs position [%s]\", value)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tfound := false\n\t\tfor item := node.FirstChild; nil != item; item = item.Next {\n\t\t\tif ast.NodeTabItem == item.Type && item.ID == value {\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif !found {\n\t\t\treturn fmt.Errorf(\"active tab [%s] is not a direct child of [%s]\", value, node.ID)\n\t\t}\n\t}\n\treturn nil\n}\n\n// NormalizeTabs 修复空页和无效选中项，保留所有已有内容及块标识。\nfunc NormalizeTabs(root *ast.Node) (changed bool) {\n\tif nil == root {\n\t\treturn\n\t}\n\tast.Walk(root, func(node *ast.Node, entering bool) ast.WalkStatus {\n\t\tif entering {\n\t\t\treturn ast.WalkContinue\n\t\t}\n\t\tif ast.NodeTabItem == node.Type {\n\t\t\tif !hasContentChild(node) {\n\t\t\t\tnode.AppendChild(NewParagraph(\"\"))\n\t\t\t\tchanged = true","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/treenode/tabs.go#L51-L87","documentation":"The custom-tabs-active-id attribute must reference a TabItem node that is a direct child of the tabs container. This error is returned when the given active-tab ID does not match any direct child TabItem of the container identified by node.ID.","triggerScenarios":"Setting custom-tabs-active-id to a block ID that is not a direct TabItem child — e.g. an ID of content inside the tab, a tab from another container, or a tab that was deleted.","commonSituations":"Plugins remembering a tab ID across document edits after the tab was removed; copying attribute values between different tab containers; stale IDs after sync merges.","solutions":["Use the ID of an existing direct TabItem child of the same tabs container","Re-read the tabs container's children and pick a valid tab ID before setting","Clear the custom-tabs-active-id attribute if the target tab no longer exists","Let NormalizeTabs fix stale selections by reloading the document"],"exampleFix":"// before\nsetNodeAttrs(tabsID, {\"custom-tabs-active-id\": \"20240101120000-abc\"}) // id from another container\n// after\nconst tab = tabs.children.find(t => t.id === wantId);\nif (tab) setNodeAttrs(tabsID, {\"custom-tabs-active-id\": wantId})","handlingStrategy":"validation","validationCode":"const tabs = await getBlockByID(tabsID);\nconst ok = tabs.children.some(c => c.type === \"tab-item\" && c.id === activeID);\nif (!ok) throw new Error(\"active tab is not a direct child\");","typeGuard":"function isActiveTabValid(tabs, activeID) {\n  return tabs.children.some(c => c.id === activeID);\n}","tryCatchPattern":null,"preventionTips":["Re-read the container's children before setting active-id","Clear the attribute when the referenced tab is deleted","Never reuse tab IDs across containers","Handle sync merges that may remove tabs"],"tags":["validation","tabs","reference"],"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"}