API: "active-leaf-change" event is sometimes triggered twice

Steps to reproduce

I wrote this small test plugin:

'use strict';

var obsidian = require('obsidian');

class MyPlugin extends obsidian.Plugin {

	async onload() {
		this.app.workspace.on("active-leaf-change", () => {
			console.log("Active leaf changed!")
			new obsidian.Notice("Active leaf changed!");
		})
	}
}

module.exports = MyPlugin;

With this plugin enabled, try to switch between different files in the navigation menu. In addition to switching between markdown files, try also swithing to images and audio files.

Expected result

The event should be triggered only once. I.e. my test plugin should display only one “Active leaf changed!” Notice.

Actual result

The event is sometimes triggered twice. I.e. my test plugin displays “Active leaf changed!” Notice twice.

Also, every time I start (or restart) Obsidian, the event is triggered twice instead of once.

Environment

  • Operating system: Windows 10
  • Debug info:
    SYSTEM INFO:
    Obsidian version: v0.13.23
    Installer version: v0.13.23
    Operating system: Windows 10 Home 10.0.19044
    Login status: logged in
    Catalyst license: none
    Insider build toggle: off
    Live preview: on
    Legacy editor: off
    Base theme: dark
    Community theme: none
    Snippets enabled: 0
    Safe mode: off
    Plugins installed: 1
    Plugins enabled: 1
    1: Test plugin

RECOMMENDATIONS:
Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the help vault or disable community plugins.


Additional information

I recorded a video about this: Obsidian active leaf change bug - YouTube

(It’s unlisted on YouTube, so it can only be found via the link).

Thank you for your support! :sunglasses:

thanks

1 Like