BUG : Custom views are not detected while opening Obsidian in `onLayoutReady` callback

Hello Everyone!

I am not sure if this used to work earlier, or I never tested this. But say, I have my custom leaf opened and its not in active state right now → Then I closed the Obsidian → Then opened Obsidian again. Now, when my plugin tries to get the leaf using getLeavesOfType(), it receives leaves = []. I am calling it inside onLayoutReady().

Here is where I added a debugger :

Here is an image for more context :

image

Another approach I was thinking is by using the getLeafById(), but for that I will need to store the leaf ID . Ill think about this approach…

But, is there anything wrong with the current approach and why I am not able to retrieve the leaf?

You should register VIEW_TYPE_TASKBOARD directly in plugin.onload instead of in workspace.onLayoutReady.

plugin.registerView will replace all existing Views of this type with EmptyView

1 Like

I cant believe it!:upside_down_face::rofl:

I knew the Obsidian architecture, but never thought of that, I wish I could have looked my own code a little closer.

Thank you for the solution, its working👍