fix: add optional chaining to wakatime template to prevent rendering …#1783
Open
endavis wants to merge 1 commit intolowlighter:masterfrom
Open
fix: add optional chaining to wakatime template to prevent rendering …#1783endavis wants to merge 1 commit intolowlighter:masterfrom
endavis wants to merge 1 commit intolowlighter:masterfrom
Conversation
…errors This adds null-safety to the wakatime template to prevent errors when the plugin is disabled or not configured. ## Problem When wakatime plugin is disabled (`enabled: no` in config), the template still tries to access `plugins.wakatime.sections` properties, causing: ``` TypeError: Cannot read properties of undefined (reading 'includes') ``` This happens because disabled plugins don't populate the data structure, leaving `plugins.wakatime.sections` as `undefined`. ## Solution Added optional chaining (`?.`) to all `plugins.wakatime.sections` accesses: ```javascript // Before: if (plugins.wakatime.sections.includes(...)) // After: if (plugins.wakatime.sections?.includes(...)) ``` **Changes across 4 locations** in the template checking for different wakatime sections (languages, editors, os, projects). ## Impact - ✅ Template renders safely when wakatime plugin is disabled - ✅ No breaking changes when plugin is enabled - ✅ Prevents template rendering errors in generated SVGs - ✅ Follows JavaScript best practices for null-safety ## Testing Tested with: - Wakatime plugin enabled (works as before) - Wakatime plugin disabled (no longer crashes) - Wakatime plugin missing from config (no longer crashes)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…errors
This adds null-safety to the wakatime template to prevent errors when the plugin is disabled or not configured.
Problem
When wakatime plugin is disabled (
enabled: noin config), the template still tries to accessplugins.wakatime.sectionsproperties, causing:This happens because disabled plugins don't populate the data structure, leaving
plugins.wakatime.sectionsasundefined.Solution
Added optional chaining (
?.) to allplugins.wakatime.sectionsaccesses:Changes across 4 locations in the template checking for different wakatime sections (languages, editors, os, projects).
Impact
Testing
Tested with: