siyuan-note/siyuan · error

active tab [ ] is not a direct child of [ ]

Error message

active tab [%s] is not a direct child of [%s]

What it means

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.

Solutions

  1. Use the ID of an existing direct TabItem child of the same tabs container
  2. Re-read the tabs container's children and pick a valid tab ID before setting
  3. Clear the custom-tabs-active-id attribute if the target tab no longer exists
  4. Let NormalizeTabs fix stale selections by reloading the document

Example fix

// before
setNodeAttrs(tabsID, {"custom-tabs-active-id": "20240101120000-abc"}) // id from another container
// after
const tab = tabs.children.find(t => t.id === wantId);
if (tab) setNodeAttrs(tabsID, {"custom-tabs-active-id": wantId})
Defensive patterns

Strategy: validation

Validate before calling

const tabs = await getBlockByID(tabsID);
const ok = tabs.children.some(c => c.type === "tab-item" && c.id === activeID);
if (!ok) throw new Error("active tab is not a direct child");

Type guard

function isActiveTabValid(tabs, activeID) {
  return tabs.children.some(c => c.id === activeID);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/6a0385f11c45057d. Report an issue: GitHub.

Appendix: source

Thrown at kernel/treenode/tabs.go:69

		value = strings.TrimSpace(util.RemoveInvalidRetainCtrl(value))
		if "" == value {
			continue
		}
		if TabsPositionAttr == name {
			if "top" != value && "left" != value {
				return fmt.Errorf("invalid tabs position [%s]", value)
			}
			continue
		}
		found := false
		for item := node.FirstChild; nil != item; item = item.Next {
			if ast.NodeTabItem == item.Type && item.ID == value {
				found = true
				break
			}
		}
		if !found {
			return fmt.Errorf("active tab [%s] is not a direct child of [%s]", value, node.ID)
		}
	}
	return nil
}

// NormalizeTabs 修复空页和无效选中项,保留所有已有内容及块标识。
func NormalizeTabs(root *ast.Node) (changed bool) {
	if nil == root {
		return
	}
	ast.Walk(root, func(node *ast.Node, entering bool) ast.WalkStatus {
		if entering {
			return ast.WalkContinue
		}
		if ast.NodeTabItem == node.Type {
			if !hasContentChild(node) {
				node.AppendChild(NewParagraph(""))
				changed = true

View on GitHub (pinned to 9f775e8a12)