Refactor Week of 2025: Refactoring My Obsidian Plugins
Recently, I've dedicated a refactoring week to thoroughly revamp my early Obsidian plugins. Current progress:
Why Refactor?
When reviewing my initial Obsidian plugins, I discovered numerous areas for improvement:
- Unclear code structure: For example, in Task Progress Bar, the rendering components weren't properly separated, making it difficult to locate core issues
- Inelegant implementation approaches: New bullet with time was full of technical debt, such as incorrectly using Codemirror's update monitoring method to monitor keydown behavior
- Lack of proper error handling throughout the codebase
- Significant performance optimization opportunities: Daily Notes Editor often failed to properly unload daily note instances
- Incomplete documentation
- Outdated APIs and patterns (present in almost all plugins)
With the evolution of the Obsidian API and my improved programming skills, it was time to breathe new life into these plugins.
Discoveries During Refactoring
Technical Debt Everywhere
Code developed quickly initially often accumulates technical debt, and since my TypeScript and React skills were still developing in 2022, the technical debt was significantly amplified. When working with code I wrote three years or even one year ago, I often found myself thinking, "What was I thinking?" - facing code that was difficult to understand, filled with incorrectly used methods, and lacking any comments. Sometimes I could only understand the purpose of certain code sections by using console.log to see what data was being processed.
TypeScript as a Friend
Fortunately, I started with TypeScript, which provided many type references during refactoring. However, I also discovered numerous incorrect type usages and naming errors.
Importance of Modular Design
Breaking large features into small, testable modules greatly improved code quality. This approach made:
- Testing simpler
- Though Obsidian still lacks convenient automated testing solutions
- Feature extensions more flexible
- This isn't an issue in smaller plugins but can easily accumulate during later feature expansions
- Code reuse easier (although I didn't find much code suitable for reuse between different plugins)
Specific Improvements
For each plugin, I implemented the following improvements:
- Code Restructuring: Adopted clearer file organization and modular design
- Performance Optimization: Reduced unnecessary operations, optimized rendering and data processing
- Test Coverage: Added unit tests and integration tests (unfortunately, coverage remains low, something I may enhance later)
- Documentation Updates: Improved both user and developer documentation
- Modernized API Usage: Leveraged Obsidian's latest API features
Lessons Learned
This refactoring experience taught me:
- Value of Continuous Refactoring: Regular code review and improvement is key to maintaining project health
- Importance of User Feedback: Various edge cases come from users, who are the greatest driving force behind product advancement
- Test-Driven Development: Using tests to guide the refactoring process and feature updates
Next Steps
After completing the refactoring, I have clearer plans for future plugin development:
- Establish a more consistent user experience, references: Obsidian Projects
When developing any software, you are often faced with difficult choices. To help guide design decisions, this project adheres to the following principles:
- Leave no trace: The plugin must not leave any plugin-specific configuration in the notes, such as custom front matter properties. Notes may be shared with colleagues and teams who don't use Obsidian. If the user stops using this plugin, they shouldn't have to clean up all their notes.
- Keep it native: The plugin should look and feel like it's native to Obsidian. The plugin should also prefer native Web APIs over custom components whenever possible.
- Stability over features: This plugin is geared towards professionals with high demands on reliability. Any bug reports and usability issues will be prioritized over new features.
- Add more unit tests
- Explore ways for plugins to work together
- Develop innovative features using new Obsidian API capabilities
Of course, dozens of plugins are still waiting for my refactoring attention. These plugins are integral parts of many users' daily workflows, so I hope to complete all refactoring actions soon!