obsidian-dataview
obsidian-dataview copied to clipboard
dataviewjs, embedded note disappears after 2 seconds
What happened?
Firstly, in reading view I see embedded note. But after 2 seconds it suddenly disappears
DQL
JS
let names =
dv.pages("#bookmark")
.sort(p => p.file.name)
.file.name
for (let name of names) {
dv.el("n", "![["+name+"]]<br>")
}
No response
Dataview Version
0.4.21
Obsidian Version
0.13.19
OS
Linux
the same problem https://github.com/blacksmithgu/obsidian-dataview/issues/177#issuecomment-1008431153
Is this happening in live preview, out of curiosity? I've seen conflicting results on doing embeds in live preview versus the traditional edit/view modes.
It's happens in traditional edit/view modes. I try live preview but no luck
sometimes it not disappears
It's a little confusing; I'd had decent luck doing this in live preview but the old source/edit mode still does not support embedding, it seems.
I have the same problem on mac
I'm currently running into this on both OSX and mobile Obsidian. Both are running 0.16.4 (Insider) and the latest version of dataview.
@jloh can you give me steps to reproduce this problem?
@AB1908 I updated to 0.16.5 insider yesterday and now can't reliably reproduce the bug 😞 I managed to make it happen once randomly but now can't get it to happen on mobile or desktop. If it starts happening again I'll make sure to reach out. Apologies for the noise.
All good!
Recorded a gif showing behavior. I can reliably reproduce when
- opening a fresh instance of obsidian
- adding embedded image to front matter and attempting to render with dataviewjs
- render works
- go back to editor and change the dataviewjs content (add space or something)
- render again
Hopes this helps in debugging!
im on obsidian v0.15.9
and dataview v0.5.46
Console seems empty:
Obsidian Developer Console
plugin:dataview:20681 Dataview: version 0.5.46 (requires obsidian 0.13.11)
plugin:obsidian-timelines:37243 Loaded Timelines Plugin
plugin:obsidian-admonition:479 Obsidian Admonition loaded
plugin:obsidian-banners:28 Loading Banners...
plugin:obsidian-leaflet-plugin:2 Loading Obsidian Leaflet v5.0.4
plugin:obsidian-5e-statblocks:426 TTRPG StatBlocks loaded
plugin:obsidian-dice-roller:5731 DiceRoller plugin loaded
plugin:obsidian-dice-roller:5731 DataviewApi
plugin:obsidian-gallery:15166 Loaded Gallery Plugin
plugin:initiative-tracker:34243 Initiative Tracker v8.0.11 loaded
plugin:folder-note-plugin:9117 Loading Folder Note plugin.
plugin:table-editor-obsidian:23703 loading markdown-table-editor plugin
plugin:dataview:13951 Dataview: all 4167 files have been indexed in 2.117s (4167 cached, 0 skipped).
I tried using the exact same code as shown in the gif in the previous post. When I close my vault (while on that page) and reopen it, it briefly shows an error before showing the image name (but it never renders correctly).
Obsidian v0.15.9 Dataview v0.5.47
Code:
Error:
Final result:
I have the same problem. Mac OS 10.15.7, desktop app. Dataview 0.5.47, no more plugins enabled.
Editing mode.
After couple of seconds after execution, dataviewjs code block is executed again.
console.log in this example shows me the repeated execution after couple of seconds. And works correctly, but dv.el does not:
`` `dataviewjs
const pathToFiles = "attachments/folder";
let files = app.vault.getFiles().filter(f => f.path.includes(pathToFiles));
let randomFile = files[Math.floor(Math.random()*files.length)]
console.log(randomFile);
console.log("before dv.el");
dv.el("n", "![](" + randomFile.path + ")");
console.log("after dv.el"); `` `
`` `
UPD:
seems like at the same time
- dv.execute output will not render at the repeated event;
- but dv.list output is working fine:
Code:
At the first execution:
After 2-3 seconds after note reloaded in editor:
I think I found a hint.. I have this at the top of my homepage:
letzte Änderung am Index Template: `$= dv.current().file.mtime`
letzter run: `$= ""+(new Date())`
//```dataviewjs
globalThis.dv = dv;
const createButton = id => {
const command = dv.app.commands.commands[id];
if (!command) return dv.el("button", `command ${id} doesn't exist`);
const button = dv.el("button", command.name);
button.onclick = () => dv.app.commands.executeCommandById(command.id);
return button;
};
dv.span(createButton("dataview:dataview-drop-cache"));
dv.span(" ");
dv.span(createButton("dataview:dataview-force-refresh-views"));
dv.span(" ");
dv.span(createButton("obsidian-reset-font-size:reset-font-size"));
dv.span(" ");
dv.span(createButton("daily-notes"));
//```dataviewjs
const date = new Date();
const getDateString = date => ([
date.getFullYear(),
(""+(date.getMonth()+1)).padStart(2, "0"),
(""+(date.getDate())).padStart(2, "0"),
].join(""));
const path = "/Day Planners/Day Planner-";
let today = path + getDateString(date);
date.setDate(date.getDate() -1);
let yesterday = path + getDateString(date);
date.setDate(date.getDate() +2);
let tomorrow = path + getDateString(date);
[yesterday, today, tomorrow].forEach(day => {
const link = dv.sectionLink(day, "Day Planner", true);
dv.span(link);
});
This code is in PoC state. no need to tell me I could use momentjs..
Anyways..
I found a trace
so..
as you can see, the dates on top don't seem to change the moment I edit my codeblock.
I've not gone through debugging dataviewjs yet, but I assume the following:
After you edit a markdown file and go from editing to reading..
(does not matter if it's full editing or inline editing)
It will first render as you defined it and then trigger a forced refresh of all views.
when the views are refreshed, the embed goes away.
Also: It will only render correctly if you actually changed the dataviewjs code block, that embeds content.
So I assume, it is related to the logic behind refreshing views.
Just ran into this issue while trying to embed .gif files and center them with DataView.
dv.el("center", "![divider](dividercolors.gif)")
Usually they don't render when I first load the note, but if I browse to a different note and come back they work. Though some .gif files loop a few times and then disappear.
Anyone know a way to run something else if/when it fails to render? Something like a try and catch block?
https://photos.app.goo.gl/agCVnobKEYhVfMSJ7
Same here! Here's code
for (let file of dv.pages("#📰")
.filter((x) => { return x.file.name !== dv.current().file.name && x.file.name !== "daily template" })
.sort()) {
dv.span("# "+file.file.name);
dv.span("![[" + file.file.name + "|h1200px]]")
}
So problem occurs when file with the script is open and presented in top tab and then you change anything in any other file while file with script is open. Here is how it looks before changing: and after: