blacksmithgu / obsidian-dataview

A data index and query language over Markdown files, for https://obsidian.md/.
https://blacksmithgu.github.io/obsidian-dataview/
MIT License
6.94k stars 411 forks source link

dv.current() is undefined during initial dataviewjs rendering #584

Open vitaly opened 2 years ago

vitaly commented 2 years ago

Tested in empty, clean vault, with just dataview installed.

blacksmithgu commented 2 years ago

Dataview initializes immediately now before actually loading any page data, so queries run immediately. dv.current() may return undefined in the first few seconds until the page is actually asynchronously loaded in the background.

blacksmithgu commented 2 years ago

I'll need to add an asynchronous wait to the renderers which verifies the current page has been indexed before trying to render anything.

charleshan commented 1 year ago

Have you had a chance to take a look at this? I've been using Hover Editor with Dataview, which lets me edit files by hovering over them. The problem is that when I edit the files, Obsidian re-renders the file and loses the scroll position. I turned off Automatic View Refreshing to prevent this but I came across other problems, such as this one.

Dataview initializes immediately now before actually loading any page data, so queries run immediately.

dv.current() and any code that uses customJS don't work if Automatic View Refreshing is togged off.

senaev commented 4 months ago

Still encountering this problem, my fix is

    let attempts = 100;
    while (!dv.current() || attempts-- < 0) {
        await new Promise((resolve) => {
            setTimeout(resolve, 100);
        });
    }