obsidian-dataview icon indicating copy to clipboard operation
obsidian-dataview copied to clipboard

Issue related to using await in live preview

Open holroy opened this issue 1 year ago • 15 comments

What happened?

Using Obsidian 1.5.12 and Dataview 0.5.66, it seems like dv.view() fails to render in live preview, but they're working just as normal in reading mode. This is tested in the Sandbox vault with no other plugins installed on Mac Os Catalina. It just shows the - indicator, and no error messages.

DQL

`$= await dv.view("js/test") `

JS

// in the file "js/test.js"

dv.header(2, "test")

Dataview Version

0.5.66

Obsidian Version

Present in 1.5.11 and 1.5.12

OS

MacOS

holroy avatar Apr 09 '24 18:04 holroy

can confirm. inline seems to be broken somewhat.

GottZ avatar Apr 11 '24 20:04 GottZ

For me, the issue was coming from the latest iconize version, I had to disable the plugin to make them work again.

pierremouchan avatar Apr 12 '24 06:04 pierremouchan

true but still. I'm not using iconize and have noticed a hard to reproduce related bug with inline queries.

GottZ avatar Apr 12 '24 08:04 GottZ

In my case it triggers immediately when I add await ... in front of the dv.view() called. So I guess it's related to some asynchronous issue. And no I don't have Iconize plugin installed, so that is not part of my use case. (In either case, I triggered this bug in the Sandbox vault with no other plugins except Dataview.

holroy avatar Apr 12 '24 11:04 holroy

I can confirm a similar bug that occurred recently. For my test, I disabled all community plugins, except Obsidian DataView.

When I write $= dv.list(dv.pages()), the Live Preview mode displays <Promise>, while a Reading mode works well.

josephgarnier avatar Apr 13 '24 07:04 josephgarnier

@josephgarnier , neither dv.list() nor dv.pages() by themselves should produce a promise. What else do you do in that query?

In general whenever you get a <promise> return you'll need to add await in front of that call. In your case you might need to use Promise.all().

In any case a promise is not a bug, but when/if the result disappear after adding the await then that's a bug.

holroy avatar Apr 13 '24 12:04 holroy

@holroy Just to check, I've just tested a new vault with all default settings and only the "dataview" community plugin. As you can see on the screen below, the instruction $= dv.list(dv.pages()) is displayed <promise> in Live Preview mode only, whereas in Reading mode the instruction works. Furthermore, there are no errors in the console.

Live Preview mode : image

Reading mode : image

Now, with the $= await dv.list(dv.pages()) instruction, the display changes, but the result is not as expected: there is no list of files, only one item :

image

edit : actually, the problem persists even with all core plugins deactivated.

josephgarnier avatar Apr 14 '24 06:04 josephgarnier

@josephgarnier , that is indeed very wrong. Something strange has happened in one of the last updates. Neither response is correct when in live preview did that query.

This surely needs more attention and investigation.

holroy avatar Apr 14 '24 07:04 holroy

tomorrow I'm back in my usual debug environment and will try to fix this.

GottZ avatar Apr 14 '24 18:04 GottZ

Do you have any idea what causes this, @GottZ ?

holroy avatar Apr 14 '24 22:04 holroy

Increasing the compile target to es2022 might have broken code with bad structure. it also broke that server version check earlier.

I got confirmation from an obsidian employee, that es2022 is the correct target these days tho.

I suspect I'll have to do a little housekeeping and re-implenent a few pieces here and there to make sure the code is up to current standards.

GottZ avatar Apr 15 '24 04:04 GottZ

In other words, the code is going to be unstable for a version of two while working out those kinks? This should then possibly have not been a minor version raise , aka from 0.5.65 to 0.5.66, but rather have gone to something like 0.6.0. This change has caused breakage in many vaults, without been given a proper warning.

This change, alongside with that strange(?) live preview changes/bug in #2216, have broken two of the main use cases in my personal vault so I'm having issues on how to proceed.

And I guess the tests should possibly be extended to catch either of these

holroy avatar Apr 15 '24 07:04 holroy

@GottZ should we roll back to previous stable version while we explore fix in beta release?

AB1908 avatar Apr 15 '24 23:04 AB1908

@GottZ should we roll back to previous stable version while we explore fix in beta release?

If we go down that route, which I'm in favor of, should we then also include all the stuff related to #2216 since there isn't any easy fix to that issue, and since it's not very clear which issue was resolved introducing that code at all?

holroy avatar Apr 17 '24 18:04 holroy

I have run into this issue and find a fix in following PR. Validated working locally

https://github.com/blacksmithgu/obsidian-dataview/pull/2634

halfjuice avatar Oct 15 '25 23:10 halfjuice