Skip to content

fix: safe access for potentially missing canvas index and caches#161

Merged
GamerGirlandCo merged 5 commits intoblacksmithgu:masterfrom
beto-group:fix/canvas-undefined-error
Mar 15, 2026
Merged

fix: safe access for potentially missing canvas index and caches#161
GamerGirlandCo merged 5 commits intoblacksmithgu:masterfrom
beto-group:fix/canvas-undefined-error

Conversation

@beto-group
Copy link
Contributor

@beto-group beto-group commented Feb 19, 2026

Summary

This PR fixes a TypeError: Cannot read properties of undefined (reading 'canvas') that occurs during background file reloading and improves type safety by removing any casts.

The Problem

The plugin assumed this.fileManager.linkUpdaters.canvas always existed. In some environments, this path is undefined, causing a crash during file import.
The code relied on as any casting to access internal Obsidian APIs, hiding potential type issues.

The Fix

Runtime Safety: Added optional chaining (?.) and fallback objects in src/index/web-worker/importer.ts and src/index/import/canvas.ts.
Type Safety: Extended src/typings/obsidian-ex.d.ts to correctly type the internal linkUpdaters structure, removing the need for as any casting.
This ensures the plugin handles missing internal API data gracefully and adheres to better TypeScript practices.

Use this updated description when you update the PR on GitHub! Make sure you pushed the commits first.

Once you're done with the fix branch, we can switch back to feature/quick-launch to finish verifying that feature.

@roman-balzer
Copy link

Since Version 1.12.2 of Obsidian this bug rendered Datacore completely broken. Workaround was disabling "canvas" from INDEXABLE_EXTENSIONS

@GamerGirlandCo
Copy link
Collaborator

what if we were to simply delay canvas indexing until the caches have been loaded? maybe we could see if the linkupdater class emits any useful events?

@beto-group
Copy link
Contributor Author

adding main.js file you all would need to generate yourself until more permanent fix
since #163 asked

main.js

Copy link
Collaborator

@GamerGirlandCo GamerGirlandCo left a comment

Choose a reason for hiding this comment

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

just tested, and it looks like it works. will merge and release ✨

@GamerGirlandCo GamerGirlandCo merged commit 496b607 into blacksmithgu:master Mar 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants