siyuan-note/siyuan · error

template source is too large

Error message

template source is too large

What it means

PreviewTemplateSource rejects template sources larger than maxTemplateSourceSize (8 MiB) before parsing, to bound memory and CPU spent on preview rendering. The content string passed by the editor exceeded this hard limit.

Source

Thrown at kernel/model/template.go:743

	mdTableHead.AppendChild(mdTableHeadRow)
	for _, col := range table.Columns {
		cell := &ast.Node{Type: ast.NodeTableCell}
		cell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(col.Name)})
		mdTableHeadRow.AppendChild(cell)
	}
	node.InsertBefore(mdTable)
	return mdTable
}

func RenderTemplateWithMode(p, id string, mode TemplateRenderMode) (tree *parse.Tree, dom string,
	summary *TemplateDocTreePlanSummary, err error) {
	return renderTemplateSource(p, id, mode, nil)
}

// 编辑器预览使用未保存的源码,文件路径仅用于解析同包子模板。
func PreviewTemplateSource(p, id, content string) (tree *parse.Tree, dom string, summary *TemplateDocTreePlanSummary, err error) {
	if len(content) > maxTemplateSourceSize {
		return nil, "", nil, errors.New("template source is too large")
	}
	return renderTemplateSource(p, id, TemplateRenderModePreview, &content)
}

func renderTemplateSource(p, id string, mode TemplateRenderMode, content *string) (tree *parse.Tree, dom string,
	summary *TemplateDocTreePlanSummary, err error) {
	if TemplateRenderModeContent != mode && TemplateRenderModePreview != mode && TemplateRenderModeEditorInsert != mode {
		err = fmt.Errorf("unsupported template render mode [%s]", mode)
		return
	}
	preview := TemplateRenderModePreview == mode
	tree, err = LoadTreeByBlockID(id)
	if err != nil {
		return
	}
	sourceTree := tree

	node := treenode.GetNodeInTree(tree, id)

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Reduce the template source below 8 MiB — split it into multiple templates or use sub-template includes
  2. Trim pasted content to the needed snippet before previewing
  3. If handling large documents, render them via document-tree mechanisms (createDocTree) instead of inlining everything in one template

Example fix

// before: previewing full 20 MB content
PreviewTemplateSource(box, id, hugeContent)
// after: guard before calling
if len(content) <= 8*1024*1024 { PreviewTemplateSource(box, id, content) }
Defensive patterns

Strategy: validation

Validate before calling

const maxTemplateSourceSize = 8 * 1024 * 1024
if len(content) > maxTemplateSourceSize {
    return errors.New("template content exceeds 8 MiB preview limit")
}

Try / catch

tree, dom, summary, err := PreviewTemplateSource(p, id, content)
if err != nil && strings.Contains(err.Error(), "too large") {
    // truncate or split the source before retrying
}

Prevention

When it happens

Trigger: Calling PreviewTemplateSource with a content string longer than 8*1024*1024 bytes; pasting a huge document into the template editor and triggering preview.

Common situations: Pasting an entire large notebook export into a template; a plugin generating enormous template content programmatically; binary data accidentally embedded in the template text.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/49ed9dfe09c4c9c5. Report an issue: GitHub.