question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataVewJS will not update if opening a new page with an identical query

See original GitHub issue

What 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:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
blacksmithgucommented, May 14, 2022

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.

0reactions
blacksmithgucommented, May 25, 2022

Good news - this is fixed in Obsidian v0.14.13!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Arbitrary Code Execution via JavaScript Queries (CVE-2021 ...
I discovered a way to craft malicious markdown files that will cause the obsidian-dataview plugin to execute arbitrary commands on users' ...
Read more >
How to get started with Obsidian Dataview and DataviewJS
1. Click the cog (settings icon) in the bottom left. ; 2. Click Community Plugins, in the window that opens, and turn off...
Read more >
DataviewJS Deep Dive and Ecosystem Updates - YouTube
Open App. Obsidian Office Hours - DataviewJS Deep Dive and Ecosystem Updates. 13K views · 1 year ago ...more. BenCodeZen. 5.21K. Subscribe.
Read more >
DataviewJS Snippet Showcase - Obsidian Forum
Since the Dataview plugin snippet showcase is getting huge, I thought we start a new—DataviewJS-only— snippet showcase here. With great power ...
Read more >
Dataview - GitHub Pages
If the built in query language is insufficient for your purpose, you can run ... [Another Inline Field On The Same Line:: With...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found