{"record":{"id":"2950596a0d500c38","repo":"siyuan-note/siyuan","slug":"template-document-tree-plan-does-not-match-the-edi","errorCode":null,"errorMessage":"template document tree plan does not match the edited document","messagePattern":"template document tree plan does not match the edited document","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":489,"sourceCode":"\t}\n\tfor _, operation := range append(append([]*Operation{}, target.DoOperations...), target.UndoOperations...) {\n\t\tif nil != operation && (\"restoreCreatedDoc\" == operation.Action || \"removeCreatedDoc\" == operation.Action) {\n\t\t\treturn false, errors.New(\"template document tree transaction contains a reserved operation\")\n\t\t}\n\t}\n\n\tplanID := target.TemplateDocTreePlanID\n\ttarget.TemplateDocTreePlanID = \"\"\n\tvalue, loaded := templateDocTreePlans.LoadAndDelete(planID)\n\tif !loaded {\n\t\treturn false, errors.New(\"template document tree plan is missing or has expired\")\n\t}\n\tplan, ok := value.(*templateDocTreePlan)\n\tif !ok || plan.id != planID || time.Now().After(plan.expiresAt) {\n\t\treturn false, errors.New(\"template document tree plan is invalid or has expired\")\n\t}\n\tif !transactionTargetsTemplateRoot(target, plan.rootID, plan.boxID) {\n\t\treturn false, errors.New(\"template document tree plan does not match the edited document\")\n\t}\n\trootTree, loadErr := LoadTreeByBlockID(plan.rootID)\n\tif nil != loadErr || nil == rootTree || rootTree.Box != plan.boxID || rootTree.Path != plan.rootPath ||\n\t\trootTree.HPath != plan.rootHPath {\n\t\treturn false, errors.New(\"the document used to render the template has changed\")\n\t}\n\ttarget.templateDocTreeRootSnapshot = rootTree\n\tbox := Conf.Box(plan.boxID)\n\tif nil == box {\n\t\treturn false, ErrBoxNotFound\n\t}\n\tfor _, tree := range plan.trees {\n\t\tif nil == tree || nil == tree.Root || tree.ID != tree.Root.ID || tree.Box != plan.boxID || box.Exist(tree.Path) {\n\t\t\treturn false, errors.New(\"template document tree plan contains an invalid document snapshot\")\n\t\t}\n\t}\n\n\tfor _, tree := range plan.trees {","sourceCodeStart":471,"sourceCodeEnd":507,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L471-L507","documentation":"The plan records the root document (rootID and boxID) it was rendered against. On attach, transactionTargetsTemplateRoot checks that the transaction's operations actually target that same root document in that notebook. If the transaction edits a different document or notebook, the plan cannot be applied and this error is thrown.","triggerScenarios":"The client renders a template in document A but attaches the plan ID to a transaction whose operations touch document B, or moves the operations to another notebook before committing.","commonSituations":"Frontend loses track of which document initiated the template; user switches documents while a template plan is pending; plugin sends a generic transaction with a stale plan ID.","solutions":["Attach the plan ID only to the transaction that modifies the root document it was rendered from","Re-render the template after switching documents so the plan matches the new target","Verify the transaction's operation IDs reference blocks under plan.rootID/plan.boxID before commit"],"exampleFix":"// before\nrenderIn(docA); commit(planID, txTargeting(docB))\n// after\nrenderIn(docA); commit(planID, txTargeting(docA))","handlingStrategy":"validation","validationCode":"assert(tx.operations.every(op => op.box === plan.boxId && belongsToDoc(op.id, plan.rootId)), 'transaction must target the plan root document')","typeGuard":"null","tryCatchPattern":"try { commit(txWith(planId)) } catch (e) { if (String(e).includes('does not match the edited document')) { rebindPlanToCurrentDoc(); commit(txWith(planId)) } else { throw e } }","preventionTips":["Track the source document of a rendered template and commit only against it","Re-render when the active document changes","Assert operation IDs belong to the plan root before sending"],"tags":["transaction","document-mismatch","template"],"backgroundTag":"invalid-argument-value","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"}