Fix Dataview API load-order crash + null safety guards#55
Open
dial481 wants to merge 7 commits intonatefrisch01:masterfrom
Open
Fix Dataview API load-order crash + null safety guards#55dial481 wants to merge 7 commits intonatefrisch01:masterfrom
dial481 wants to merge 7 commits intonatefrisch01:masterfrom
Conversation
fix: getMetadataKeyForLink bails on first non-link frontmatter field The default case in the switch at linkManager.ts:463 returns null when it encounters a String or Other type entry (e.g. title, type, tags). This kills the for loop before it reaches any link/array entries below it in the frontmatter. Notes with any non-link frontmatter field before their relationship keys never render type labels or colored edges.
Both src/main.ts and src/linkManager.ts called getAPI() as class field initializers. Class field initializers run at construction time, before any lifecycle method. If Dataview loads after this plugin (which is common), getAPI() returns null, onload() checks this.api, finds null, prints "Dataview plugin is not available", and returns. Plugin is dead. Load order doesn't matter because the bug is in construction, not in load sequence. Fix: - src/main.ts line 70: api field initialized to null instead of calling getAPI() at construction - src/main.ts onload(): tries getAPI() first. If null, registers for the dataview:api-ready event and initializes when Dataview is ready. Event handlers moved to initEventHandlers() so they can be called from either path. - src/linkManager.ts line 11: api field initialized to null. Gets set from main.ts after Dataview is ready.
… make)" This reverts commit 503211d.
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.
Problem
The plugin crashes on load when Dataview initializes after Graph-Link-Types.
getAPI()is called as a class field initializer (construction time), beforeDataview has registered its API.
onload()finds null, prints "Dataview pluginis not available", and returns. The plugin is dead on arrival regardless of
load order settings.
Fix
src/main.ts:
apifield initialized to null instead of callinggetAPI()at constructiononload()triesgetAPI()first; if null, listens fordataview:api-readyevent and initializes when Dataview is ready
initEventHandlers()to avoid duplicationbetween the two initialization paths
renderer.links.forEach— links with null source/target(broken wikilinks) no longer crash the render loop
dataview:api-readycallback only renders if a graph view is already openwaitForRenderer()times out after 10s instead of polling foreversrc/linkManager.ts:
apifield initialized to null (set from main.ts after Dataview is ready)getAPIimportpackage-lock.json:
Testing
Tested in Obsidian 1.12.7 (Installer 1.8.4) with Dataview loading both before and after this
plugin. Graph view renders typed relationship labels correctly in both cases.