Skip to content

Fix Dataview API load-order crash + null safety guards#55

Open
dial481 wants to merge 7 commits intonatefrisch01:masterfrom
dial481:master
Open

Fix Dataview API load-order crash + null safety guards#55
dial481 wants to merge 7 commits intonatefrisch01:masterfrom
dial481:master

Conversation

@dial481
Copy link
Copy Markdown

@dial481 dial481 commented Apr 13, 2026

Problem

The plugin crashes on load when Dataview initializes after Graph-Link-Types.
getAPI() is called as a class field initializer (construction time), before
Dataview has registered its API. onload() finds null, prints "Dataview plugin
is not available", and returns. The plugin is dead on arrival regardless of
load order settings.

Fix

src/main.ts:

  • api field initialized to null instead of calling getAPI() at construction
  • onload() tries getAPI() first; if null, listens for dataview:api-ready
    event and initializes when Dataview is ready
  • Event handlers extracted to initEventHandlers() to avoid duplication
    between the two initialization paths
  • Null guard on renderer.links.forEach — links with null source/target
    (broken wikilinks) no longer crash the render loop
  • dataview:api-ready callback only renders if a graph view is already open
  • waitForRenderer() times out after 10s instead of polling forever

src/linkManager.ts:

  • api field initialized to null (set from main.ts after Dataview is ready)
  • Removed unused getAPI import

package-lock.json:

  • Synced version from 0.1.2 to 0.3.3 to match package.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.

dial481 and others added 7 commits April 13, 2026 22:24
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.
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.

1 participant