DataVewJS will not update if opening a new page with an identical query
See original GitHub issueWhat happened?
I have a daily note with some custom dataviewjs to navigate to my next and previous notes. I do this because I will have gaps for weekends and days off, but I still enjoy having a navigation between days.
The issue is in live preview, where if I open up a different daily note, the navigation query stays as though I was on the previous note. This happens both if I click the link, or open the file by any other way (file tree, tag panel, wiki link). The bug is not present in reading mode, only live-preview
If I edit the query or load a different file then the query works just fine.
What I believe is happening is that because the query is identical between files, a reload isn’t triggered despite being in relation to a new file now. I have a workaround by using templater to insert today’s date as an unused variable, but I feel this is a deeper bug.
DQL
No response
JS
/*
previous/next note by date for Daily Notes
Also works for other files having a `date:` YAML entry.
MCH 2021-06-14
*/
var offset = '<% tp.date.now() %>'; // Makes each day's query unique to fix loading
var none = '(none)';
var opt = app['internalPlugins']['plugins']['daily-notes']['instance']['options']['folder']
var p = dv.pages('"' + opt + '"').where(p => p.file.day).map(p => [p.file.name, p.file.day.toISODate()]).sort(p => p[1]);
var t = dv.current().file.day ? dv.current().file.day.toISODate() : luxon.DateTime.now().toISODate();
// Obsidian uses moment.js; Luxon’s format strings differ!
var format = app['internalPlugins']['plugins']['daily-notes']['instance']['options']['format'] || 'YYYY-MM-DD';
var current = '(' + moment(t).format(format) + ')';
var nav = [];
var today = p.find(p => p[1] == t);
var next = p.find(p => p[1] > t);
var prev = undefined;
p.forEach(function (p, i) {
if (p[1] < t) {
prev = p;
}
});
nav.push(prev ? '[[' + prev[0] + ']]' : none);
//nav.push(today ? today[0] : none);
nav.push(today ? today[0] : current);
nav.push(next ? '[[' + next[0] + ']]' : none);
//dv.list(nav);
//dv.paragraph(nav.join(" · "));
dv.paragraph(nav[0] + ' ← ' + nav[1] + ' → ' + nav[2]);
Dataview Version
0.4.26
Obsidian Version
0.14.6
OS
Windows
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Common Obsidian bug and a frequent source of bugs filed on Dataview, sadly. Obsidian caches identical looking codeblocks for performance reasons, which ends up breaking some Dataview use cases if you have identical queries on different files. I am currently working with the Obsidian developers to find a permanent fix.
Good news - this is fixed in Obsidian v0.14.13!