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

dataviewjs, embedded note disappears after 2 seconds

Open dany52 opened this issue 2 years ago • 17 comments

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

dany52 avatar Jan 14 '22 00:01 dany52

the same problem https://github.com/blacksmithgu/obsidian-dataview/issues/177#issuecomment-1008431153

dany52 avatar Jan 14 '22 07:01 dany52

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.

blacksmithgu avatar Jan 19 '22 22:01 blacksmithgu

It's happens in traditional edit/view modes. I try live preview but no luck

dany52 avatar Jan 21 '22 00:01 dany52

sometimes it not disappears

dany52 avatar Jan 21 '22 00:01 dany52

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.

blacksmithgu avatar Jan 21 '22 20:01 blacksmithgu

I have the same problem on mac

willypicard avatar May 31 '22 21:05 willypicard

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 avatar Oct 05 '22 07:10 jloh

@jloh can you give me steps to reproduce this problem?

AB1908 avatar Oct 08 '22 18:10 AB1908

@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.

jloh avatar Oct 09 '22 06:10 jloh

All good!

AB1908 avatar Oct 09 '22 07:10 AB1908

Recorded a gif showing behavior. I can reliably reproduce when

  1. opening a fresh instance of obsidian
  2. adding embedded image to front matter and attempting to render with dataviewjs
  3. render works
  4. go back to editor and change the dataviewjs content (add space or something)
  5. render again

Peek 2022-10-12 09-39

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).

scottTomaszewski avatar Oct 12 '22 13:10 scottTomaszewski

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: image

Error: error

Final result: image

ericbrook avatar Oct 12 '22 19:10 ericbrook

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");  `` `
  `` `

Screenshot 2022-12-02 at 06 58 05

Screenshot 2022-12-02 at 06 56 39

grosslarnakh avatar Dec 02 '22 02:12 grosslarnakh

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:

Screenshot 2022-12-02 at 07 07 02

At the first execution: Screenshot 2022-12-02 at 07 09 00

After 2-3 seconds after note reloaded in editor: Screenshot 2022-12-02 at 07 06 59

grosslarnakh avatar Dec 02 '22 03:12 grosslarnakh

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("&nbsp;");
dv.span(createButton("dataview:dataview-force-refresh-views"));
dv.span("&nbsp;");
dv.span(createButton("obsidian-reset-font-size:reset-font-size"));
dv.span("&nbsp;");
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.. image image

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.

GottZ avatar Aug 15 '23 17:08 GottZ

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?

Anarchtism avatar Feb 14 '24 18:02 Anarchtism

https://photos.app.goo.gl/agCVnobKEYhVfMSJ7

Anarchtism avatar Feb 14 '24 18:02 Anarchtism

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: image and after: image

ReLLoMine avatar Mar 13 '24 15:03 ReLLoMine