blacksmithgu / obsidian-dataview

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

Table contents not refreshed when switch notes in live preview mode #982

Open xshuai1006 opened 2 years ago

xshuai1006 commented 2 years ago

What happened?

Table contents of a note (in live preview mode): image Switch to b note (still in live preview mode): table content is the same with a note above image And this is the real table content of b note (switch to preview mode): image

DQL

No response

JS

No response

Dataview Version

0.4.26

Obsidian Version

0.14.2

OS

Windows

harmonify commented 2 years ago

Do you also happen to use something like [[]] or [[#]] in your queries? This also happened to me. I think it has something to do with Dataview's caching mechanism, where it will cache the result of same query statements.

blacksmithgu commented 2 years ago

Dataview doesn't cache - it's Obsidian doing this in this case. Codeblocks with exactly the same contents are cached by the Obsidian markdown renderer to be the same view.

You can fix this by adjusting one codeblock - reference a file by name, insert spaces, adjust names, adjust titles, and so on. It's very frustrating, but I haven't found a good fix for it yet sadly.

harmonify commented 2 years ago

Dataview doesn't cache - it's Obsidian doing this in this case. Codeblocks with exactly the same contents are cached by the Obsidian markdown renderer to be the same view.

You can fix this by adjusting one codeblock - reference a file by name, insert spaces, adjust names, adjust titles, and so on. It's very frustrating, but I haven't found a good fix for it yet sadly.

Oh that's great to know

QuaCKeReD commented 2 years ago

@blacksmithgu Brilliant! ๐Ÿ˜›

Is there a way to dynamically make the code blocks different, for js blocks?

I have requirement where the same code block runs on pages, but the result depend on the attributes on the page - if I could make each different as part of the data view js code, that would be AMAZING!

AB1908 commented 2 years ago

Check out dv.view() from the documentation.

QuaCKeReD commented 2 years ago

Check out dv.view() from the documentation.

Ooo ๐Ÿ˜€ is this same script format as standard templater scripts?

I assume Obsidian canโ€™t cache code blocks using scripts?

AB1908 commented 2 years ago

Not sure what you mean by caching code blocks but the view.js is standard JS.

QuaCKeReD commented 2 years ago

Not sure what you mean by caching code blocks but the view.js is standard JS.

Caching, as in comment above;

Dataview doesn't cache - it's Obsidian doing this in this case. Codeblocks with exactly the same contents are cached by the Obsidian markdown renderer to be the same view.

AB1908 commented 2 years ago

Oh my, I think I've completely misunderstood the original ask. In this case, you probably want to listen on an event. You can use that event to trigger a refresh using dv.index.touch(). You can get the currently active file via app.workspace.getActiveLeaf() or something related. Hopefully, this gives you enough ideas to go looking but I'd need some time to figure out what this use case properly looks like.

s-blu commented 1 year ago

Hello, sorry to come back to you so late. I currently go through older issues to see which are stale or already solved.

Does AB1908 suggestion fix the use case for you?