Skip to content

Conversation

@chhoumann
Copy link
Owner

@chhoumann chhoumann commented Jan 28, 2026

Summary

Fixes Capture Choices crashing with Cannot convert undefined or null to object when Templater 2.18.0 is installed.

Closes #1085
Closes #1086

Root Cause

Templater 2.18.0 (commit db9a91e) added frontmatter merging support for tp.file.include. This introduced a breaking change to the parse_template API:

Before (2.17.x):

type RunningConfig = {
    template_file?: TFile;
    target_file: TFile;
    run_mode: RunMode;
    active_file?: TFile | null;
};

After (2.18.0):

type RunningConfig = {
    template_file?: TFile;
    target_file: TFile;
    run_mode: RunMode;
    active_file?: TFile | null;
    frontmatter: Record<string, unknown>;  // NEW - required
};

QuickAdd called parse_template with:

{ target_file: targetFile, run_mode: 4 }

Templater 2.18.0's parse_template now executes:

merge_objects(frontmatter, config.frontmatter);  // config.frontmatter = undefined

And merge_objects immediately calls:

if (Object.keys(source).length === 0) return;  // Object.keys(undefined) → throws

Fix

  1. Prefer create_running_config() when available (Templater 2.18.0+). This factory method returns a properly initialized config with all required fields, including any future additions.

  2. Fallback to manual config with frontmatter: {} for older Templater versions that don't expose create_running_config.

const createConfig = templater.create_running_config;
const config =
    typeof createConfig === "function"
        ? createConfig.call(templater, undefined, targetFile, 4)
        : { target_file: targetFile, run_mode: 4, frontmatter: {} };

Why This Is Safe

  • Empty frontmatter: {} matches Templater's internal default from create_running_config()
  • merge_objects({}, source) is a no-op (returns immediately when source is empty)
  • Template content flows through unchanged; no data modification occurs
  • The fix actually enables Templater 2.18.0's new frontmatter merging feature for tp.file.include in QuickAdd templates

Compatibility

Templater Version Behavior
< 2.18.0 Uses fallback config (no create_running_config)
2.18.0+ Uses create_running_config() for proper initialization
Future create_running_config() handles new required fields automatically

Test Plan

  • Capture Choice with simple format works
  • Capture Choice with Templater syntax works
  • Template Choice works
  • tp.file.include in QuickAdd templates merges frontmatter correctly
  • Works with Templater < 2.18.0 (if available for testing)

Open with Devin

Summary by CodeRabbit

  • New Features
    • Enhanced template plugin API to support frontmatter data in templates
    • Introduced improved configuration system for template processing with better forward compatibility

✏️ Tip: You can customize this high-level summary in your review settings.

Templater 2.18.0 introduced a breaking change in its `parse_template` API.
The `RunningConfig` type now requires a `frontmatter` field, which QuickAdd
was not providing. This caused `Object.keys(undefined)` to throw when
Templater's `merge_objects` attempted to process the missing field.

Root cause: Templater commit db9a91e added frontmatter merging support for
`tp.file.include`. The new code path calls `merge_objects(frontmatter,
config.frontmatter)` unconditionally, but QuickAdd passed only
`{ target_file, run_mode }`.

Fix:
- Use `create_running_config()` when available (Templater 2.18.0+) to get
  a properly initialized config with all required fields
- Fall back to manual config with `frontmatter: {}` for older versions

This approach is forward-compatible: future Templater releases that add
new required fields to RunningConfig will be handled automatically via
`create_running_config()`.

Closes #1085
Closes #1086
@vercel
Copy link

vercel bot commented Jan 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
quickadd Ready Ready Preview Jan 28, 2026 3:18pm

@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

This PR updates QuickAdd's Templater integration to support the new API introduced in Templater v2.18.0. The parse_template method signature is extended to accept an optional frontmatter field, and a new create_running_config hook is leveraged when available to construct the config object for template parsing.

Changes

Cohort / File(s) Summary
Templater API compatibility
src/utilityObsidian.ts
Extended TemplaterPluginLike.templater.parse_template to accept optional frontmatter?: Record<string, unknown>. Added new optional hook create_running_config that returns config with frontmatter. Updated templaterParseTemplate to call create_running_config if available, else fall back to manual config with frontmatter: {}.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A templater dance, now in perfect sync,
With frontmatter dreams and modal forms that don't break,
QuickAdd and Templater, hand in paw we ink,
Compatibility fixed, for goodness sake! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change—restoring compatibility with Templater 2.18.0—which matches the primary objective of the PR.
Linked Issues check ✅ Passed The changes implement the required fix for issues #1085 and #1086 by updating parse_template to accept frontmatter and providing fallback config initialization.
Out of Scope Changes check ✅ Passed All changes are directly related to resolving the Templater 2.18.0 compatibility issue; no out-of-scope modifications detected.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional flags.

Open in Devin Review

@chhoumann chhoumann merged commit 04cc920 into master Jan 28, 2026
4 checks passed
@chhoumann chhoumann deleted the fix/templater-2.18-compatibility branch January 28, 2026 15:33
@github-actions
Copy link

🎉 This PR is included in version 2.10.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Capture choice crashes with error due to Templater's recent update [BUG] modal forms break with quickadd ALSO with is own code!

2 participants