Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label with Templater function will blink #198

Open
Moyf opened this issue Dec 5, 2024 · 21 comments
Open

Label with Templater function will blink #198

Moyf opened this issue Dec 5, 2024 · 21 comments
Assignees
Labels
bug Something isn't working the way it should, and the problem is reproducible in beta Available in the latest beta releases via BRAT

Comments

@Moyf
Copy link
Contributor

Moyf commented Dec 5, 2024

Description of the bug
When clicking in a note with toolbar with TP in the label, the text will blink.

Steps to reproduce

  1. Set the Note Toolbar for a note (by frontmatter)
    image

  2. Use templater as the label:
    image

  3. Click in other note, then click back note with NTB, the label will quickly flash from "<%xxx%>" to the result

Expected behavior
I hope it will not blink

Maybe if the tp render result didn't change, the result could be cached to avoid refreshing? 🤔

Screenshots (if you think it will help)
664bc4cc-5ffc-4469-ac9b-6359091a764e

In sandbox vault, the blinking will be much quicker, I guess it's related to Obsidian's performance:
https://github.com/user-attachments/assets/4d4b6d42-db3d-4688-bddb-0825ac91bb02

Desktop environment:

  • OS: Windows11
  • Obsidian version: 1.7.7
  • Note Toolbar version: 1.15.0

Additional context
I used to post a PR as "Global NTB Button", and I'm trying to use a Note in sidebar to do the similar work 😄
In that case, no matter what note I'm writing, I can always quickly interact with this "Toolbar Page" NTB 👍🏻


BTW, would it be possible to use mixed markdown text and templater?
for example, [[<%tp.date.now("YYYY.MM.DD")%>]] and render it as a link?

For now it seems I need to put all the text inside the <% %>, otherwise, the render will fail:
image
image

@chrisgurney
Copy link
Owner

@Moyf Thanks for reporting the bug! Let's dig into that first:

  1. Where is the toolbar positioned? Is looks like Top (fixed), is that right?
  2. Can you export the toolbar as a callout and paste it here, so I can try and reproduce the flicker locally, as you're experiencing it?

@chrisgurney chrisgurney added the bug Something isn't working the way it should, and the problem is reproducible label Dec 5, 2024
@chrisgurney
Copy link
Owner

chrisgurney commented Dec 5, 2024

@Moyf Regarding your suggestion, supporting a mix of fixed strings and variable expressions is a nice idea -- I'll add it to the roadmap.

As it stands, the entire label/tooltip/URI is evaluated as an expression/command, so any text to output must be part of the expression/command (as you noted). I've added a note to the docs about this.

@chrisgurney
Copy link
Owner

chrisgurney commented Dec 9, 2024

This issue has been noted in this discussion as well, per @amsam0

I was testing it out with <% tp.file.name %> as the label. When I switched between daily notes, the label showed the template for a small amount of time before switching to the result of the template.

@Moyf
Copy link
Contributor Author

Moyf commented Dec 10, 2024

@Moyf Regarding your suggestion, supporting a mix of fixed strings and variable expressions is a nice idea -- I'll add it to the roadmap.

As it stands, the entire label/tooltip/URI is evaluated as an expression/command, so any text to output must be part of the expression/command (as you noted). I've added a note to the docs about this.

Sorry I just came back from a vocation, here is an example of the blinking NTB toolbar.

> [!note-toolbar|border-even-sticky] ToolbarPage
> - [今天:12月10日]()<data data-ntb-command="quickadd:choice:6bfa5ca1-27fd-4068-a4e6-39d292624839"/>
> - [12月]()<data data-ntb-folder="PeriodicNote/晨间日记/12月"/>

But actually it's:
<% tp.date.now("今天:MM月DD日")%> and <% tp.date.now("MM月")%>, I think callout converted the tp format to normal text.
image

@Moyf
Copy link
Contributor Author

Moyf commented Dec 10, 2024

@Moyf Thanks for reporting the bug! Let's dig into that first:

  1. Where is the toolbar positioned? Is looks like Top (fixed), is that right?
  2. Can you export the toolbar as a callout and paste it here, so I can try and reproduce the flicker locally, as you're experiencing it?

Actually, I just tried different position settings and it would all blinks. (Below Properties/ Top Fixed)

I can also share it as a url so that it's easier to import with the original content:
https://chrisgurney.github.io/obsidian-note-toolbar/open.htm?uri=obsidian%3A%2F%2Fnote-toolbar%3Fimport%3D%3E%20%5B!note-toolbar%7Cborder-even-sticky%5D%20ToolbarPage%0A%3E%20-%20%5B%3C%25%20tp.date.now(%22%E4%BB%8A%E5%A4%A9%EF%BC%9AMM%E6%9C%88DD%E6%97%A5%22)%25%3E%5D()%3Cdata%20data-ntb-command%3D%22quickadd%3Achoice%3A6bfa5ca1-27fd-4068-a4e6-39d292624839%22%2F%3E%0A%3E%20-%20%5B%3C%25%20tp.date.now(%22MM%E6%9C%88%22)%25%3E%5D()%3Cdata%20data-ntb-folder%3D%22PeriodicNote%2F%E6%99%A8%E9%97%B4%E6%97%A5%E8%AE%B0%2F12%E6%9C%88%22%2F%3E%0A

@chrisgurney
Copy link
Owner

chrisgurney commented Dec 11, 2024

@Moyf I've released a fix that should improve the blinking, by not showing the expression first before replacing it.

I'm leaving this issue open as I think it can still be improved, by delaying rendering of the toolbar until all expressions can be resolved. But hopefully this should help for now.

@Moyf
Copy link
Contributor Author

Moyf commented Dec 12, 2024

@Moyf I've released a fix that should improve the blinking, by not showing the expression first before replacing it.

I'm leaving this issue open as I think it can still be improved, by delaying rendering of the toolbar until all expressions can be resolved. But hopefully this should help for now.

I just updated, and it did improve the experience much, thank you! : )

@chrisgurney
Copy link
Owner

chrisgurney commented Dec 13, 2024

@Moyf @amsam0 I've released a beta in which I've refactored how toolbar rendering is done, to hopefully improve even further.

If you get a chance, please give it a try and let me know how it goes.

@chrisgurney chrisgurney added the in beta Available in the latest beta releases via BRAT label Dec 14, 2024
@Moyf
Copy link
Contributor Author

Moyf commented Dec 16, 2024

@Moyf @amsam0 I've released a beta in which I've refactored how toolbar rendering is done, to hopefully improve even further.

If you get a chance, please give it a try and let me know how it goes.

It seems to me that the improvement is not significant, and the blinking appears to have intensified.

@chrisgurney
Copy link
Owner

It seems to me that the improvement is not significant, and the blinking appears to have intensified.

@Moyf Hmm, can you share the toolbar you're experiencing this with? Do you mean you're seeing blinking when expressions are being replaced? Or when switching between notes? Or something else?

@Moyf
Copy link
Contributor Author

Moyf commented Dec 16, 2024

It seems to me that the improvement is not significant, and the blinking appears to have intensified.

@Moyf Hmm, can you share the toolbar you're experiencing this with? Do you mean you're seeing blinking when expressions are being replaced? Or when switching between notes? Or something else?

No problem, I can provide the toolbar and the recording:
https://chrisgurney.github.io/obsidian-note-toolbar/open.htm?uri=obsidian%3A%2F%2Fnote-toolbar%3Fimport%3D%3E%20%5B!note-toolbar%7Cborder-even-sticky%5D%20ToolbarPage%0A%3E%20-%20%5B%3C%25%20tp.date.now(%22YYYY%22)%25%3E%5D()%3Cdata%20data-ntb-command%3D%22periodic-notes%3Aopen-yearly-note%22%2F%3E%0A%3E%20-%20%5B%3C%25%20tp.date.now(%22MM%E6%9C%88%22)%25%3E%5D()%3Cdata%20data-ntb-command%3D%22periodic-notes%3Aopen-monthly-note%22%2F%3E%0A%3E%20-%20%5B%3C%25%20tp.date.now(%22MM%E6%9C%88DD%E6%97%A5%22)%25%3E%5D()%3Cdata%20data-ntb-command%3D%22quickadd%3Achoice%3A6bfa5ca1-27fd-4068-a4e6-39d292624839%22%2F%3E%0A%3E%20-%20%5B%3C%25%20tp.date.now(%22%5C%5BW%5C%5DW%22)%25%3E%5D()%3Cdata%20data-ntb-command%3D%22periodic-notes%3Aopen-weekly-note%22%2F%3E%0A

bandicam.2024-12-16.21-37-45-983.mp4

I'm not sure if it's related but I'd like to share as much info as possible:
it's a note with property to indicate the Toolbar:
image

And I put the note in my left sidebar.

The setting of toolbar:
image

@Moyf
Copy link
Contributor Author

Moyf commented Dec 17, 2024

I encountered another issue that I believe may be related to the loading of the toolbar.

Here’s the scenario:
I use Templater to rename my newly created note.
For example, when I create a file named "new.md," it gets renamed to "241217_new.md" (with a date prefix) by Templater.

However, the Note Toolbar currently displays the message: no such file or directory, open 'new.md'.

image

bandicam.2024-12-17.20-49-35-647.mp4

@chrisgurney
Copy link
Owner

chrisgurney commented Dec 17, 2024

I use Templater to rename my newly created note.
For example, when I create a file named "new.md," it gets renamed to "241217_new.md" (with a date prefix) by Templater.

@Moyf Are you able to provide the template you use to do this (even just the part that renames the file)? And how exactly is that script/template triggered?

I tried assigning a hotkey to a template that renames a note, but wasn't able to recreate the issue.

@Moyf
Copy link
Contributor Author

Moyf commented Dec 18, 2024

I use Templater to rename my newly created note.
For example, when I create a file named "new.md," it gets renamed to "241217_new.md" (with a date prefix) by Templater.

@Moyf Are you able to provide the template you use to do this (even just the part that renames the file)? And how exactly is that script/template triggered?

I tried assigning a hotkey to a template that renames a note, but wasn't able to recreate the issue.

Obsidian Sandbox - TP and NTB.zip
I tried the TP in sandbox vault and didn't re-produce this issue, too.

Need more digging 🤔


Here is the calling stack:
image

I suspect it might be because my vault is too large (and with many plugins), and going through the processes of "creating a new tab, applying a template, renaming a file" takes several hundred milliseconds. During this time, NTB tries to add the toolbar or parse the template, but it is still processing the old note path from before the renaming, and the path is lost after the renaming.
The Sandbox vault processes very quickly (and doesn't have such a complex plugin environment), so I can't reproduce it?

I added a break point and found out that:
image

  1. The tp is from the Toolbar on my sidebar, it is trying to process "date_ test.md"
  2. The templater detects the date_ prefix and will rename the file to 241218_test.md
  3. While the file has been renamed, NTB's parse TP function cannot find the original file, and shows the Notice.

@chrisgurney
Copy link
Owner

It seems to me that the improvement is not significant, and the blinking appears to have intensified.

@Moyf I'm not sure what's causing this but I've added back in toolbar removal in 1.16-beta-02. Let me know how it goes and I may have to undo some other changes if you're still experiencing the intensified blinking.

@chrisgurney
Copy link
Owner

Update: I also found a case I missed when the metadata cache changes, so that may help as well.

@chrisgurney
Copy link
Owner

@Moyf When you have some time, would you be able to test the latest beta in your vault, and let me know how it performs?

I'd like to make sure there hasn't been a step back with respect to the flickering, before I release this version.

Thanks!

@Moyf
Copy link
Contributor Author

Moyf commented Dec 24, 2024

@Moyf When you have some time, would you be able to test the latest beta in your vault, and let me know how it performs?

I'd like to make sure there hasn't been a step back with respect to the flickering, before I release this version.

Thanks!

Of course!
Sometimes I might miss the messages, don't be hesitated to remind me! 🥺


Just tested with v1.16-beta-8 and... now the whole Toolbar would blink 😂

bandicam.2024-12-24.10-53-25-103.mp4

@chrisgurney
Copy link
Owner

chrisgurney commented Dec 24, 2024

@Moyf

Just tested with v1.16-beta-8 and... now the whole Toolbar would blink 😂

  • Remind me, how did you put that note in your sidebar?
  • Do you have another note open on the right side?
  • Are you just clicking in and out of the note when it flickers?

@Moyf
Copy link
Contributor Author

Moyf commented Dec 24, 2024

@Moyf

Just tested with v1.16-beta-8 and... now the whole Toolbar would blink 😂

Remind me, how did you put that note in your sidebar? Do you have another note open on the right side?

Are you just clicking in and out of the note?

Yes. I can record more space to let you know the layout:

bandicam.2024-12-24.11-25-53-377.mp4
  • I put a note with property notetoolbar: ToolbarPage
  • Yes
  • Yes

Additionally, in the same video, you can see a plugin called RichFoot — if we only consider the visual experience, perhaps we can refer to its approach - Add an animation transition with a fade-in effect ?
image

And, I'm not quite sure about the details, but it also offers a loading delay option:
image
I don't know would it be relevant, just for your information : )

@chrisgurney
Copy link
Owner

@Moyf Thanks, I'll see what I can recreate on my end.

The fade-in transition is interesting. I'll have to think where that might be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working the way it should, and the problem is reproducible in beta Available in the latest beta releases via BRAT
Projects
None yet
Development

No branches or pull requests

2 participants