siyuan-note/siyuan · error

the document used to render the template has changed

Error message

the document used to render the template has changed

What it means

The plan also snapshots the root document's path and human path at render time. When attaching, the kernel reloads the tree by root ID and compares Box, Path, and HPath with the snapshot. If the document was renamed, moved between notebooks, deleted, or changed path since rendering, the plan no longer matches disk state and the commit is rejected to avoid corrupting a moved document.

Solutions

  1. Re-render the template after any rename/move of the root document and commit with the fresh plan
  2. Avoid renaming or moving the source document while a template plan is pending
  3. If the document was deleted, recreate it or abort the template application

Example fix

// before
renderTemplate(doc); renameDoc(doc, "new-name"); commit(planID) // path changed
// after
renderTemplate(doc); commit(planID); renameDoc(doc, "new-name")
Defensive patterns

Strategy: retry

Validate before calling

const cur = await loadTreeByBlockId(plan.rootId); if (!cur || cur.path !== plan.rootPath || cur.hPath !== plan.rootHPath) { planId = await renderTemplateDocTree(); }

Type guard

null

Try / catch

try { commit(txWith(planId)) } catch (e) { if (String(e).includes('render the template has changed')) { planId = await renderTemplateDocTree(); commit(txWith(planId)) } else { throw e } }

Prevention

When it happens

Trigger: User renames or moves the root document (or its ancestors) between rendering the template and committing the transaction; the document is deleted; sync changes the tree concurrently.

Common situations: Long delay between render and commit during which the doc tree is edited; another device syncs a rename; a plugin programmatically moves the document mid-flow.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/template_doc_tree.go:494

	}

	planID := target.TemplateDocTreePlanID
	target.TemplateDocTreePlanID = ""
	value, loaded := templateDocTreePlans.LoadAndDelete(planID)
	if !loaded {
		return false, errors.New("template document tree plan is missing or has expired")
	}
	plan, ok := value.(*templateDocTreePlan)
	if !ok || plan.id != planID || time.Now().After(plan.expiresAt) {
		return false, errors.New("template document tree plan is invalid or has expired")
	}
	if !transactionTargetsTemplateRoot(target, plan.rootID, plan.boxID) {
		return false, errors.New("template document tree plan does not match the edited document")
	}
	rootTree, loadErr := LoadTreeByBlockID(plan.rootID)
	if nil != loadErr || nil == rootTree || rootTree.Box != plan.boxID || rootTree.Path != plan.rootPath ||
		rootTree.HPath != plan.rootHPath {
		return false, errors.New("the document used to render the template has changed")
	}
	target.templateDocTreeRootSnapshot = rootTree
	box := Conf.Box(plan.boxID)
	if nil == box {
		return false, ErrBoxNotFound
	}
	for _, tree := range plan.trees {
		if nil == tree || nil == tree.Root || tree.ID != tree.Root.ID || tree.Box != plan.boxID || box.Exist(tree.Path) {
			return false, errors.New("template document tree plan contains an invalid document snapshot")
		}
	}

	for _, tree := range plan.trees {
		target.DoOperations = append(target.DoOperations, &Operation{
			Action:                "restoreCreatedDoc",
			ID:                    tree.ID,
			Tree:                  tree,
			templateDocTreeRootID: plan.rootID,

View on GitHub (pinned to 9f775e8a12)