zhaoshenzhai / obsidian-mathlinks

An Obsidian.md plugin to render MathJax in your links.
MIT License
60 stars 4 forks source link

MathLinks causes links to create new notes, and Page Preview to mostly not work #24

Closed MiquelJorquera closed 1 year ago

MiquelJorquera commented 1 year ago

When MathLinks is enabled, if I hover over a link, 80% of the time it usually won't show a page preview (but it sometimes will, I haven't figured out when).

Then, if I click the link too quicklysometimes randomly, Obsidian will think the link doesn't exist and create a new Untitled note. I need to be hovering for a few seconds, and then click.(Not true after more testing)

This happens even with all community plugins and themes disabled. It may be the same as issue #21 but I'm not sure what a non-focused leaf is.

Debug info:

SYSTEM INFO:
    Obsidian version: v1.3.5
    Installer version: v1.3.5
    Operating system: Windows 10 Home 10.0.19045
    Login status: logged in
    Catalyst license: none
    Insider build toggle: off
    Live preview: on
    Legacy editor: off
    Base theme: light
    Community theme: none
    Snippets enabled: 0
    Restricted mode: off
    Plugins installed: 7
    Plugins enabled: 1
        1: MathLinks v0.3.4
zhaoshenzhai commented 1 year ago

Thanks for leaving an issue!

From what I understand (from here and on discord), there seems to be three issues:

  1. Links are slow: As in, it takes a long time after you click for the link to be opened? Or does it cause a lag spike? Performance issues might occur when there are too many tabs open, or if there is a lot of files in your vault. It would be appreciated if you can provide more details.
  2. Page preview: What 'mode' does this occur in? As in, does it occur in reading/live-preview/editing mode? Or all? Or is it mostly random? Could you please go to Settings > Core Plugins > Page Preview and check whether ctrl is required for the preview to open on hover?
  3. Create new notes: Could you give a minimal reproducable example? I've tested this on my windows system and things seem to be okay. I realize this may be difficult, but its the only way for me to debug it properly.

Also, while testing, could you please test it in a brand new vault? I realize that you only have MathLinks enabled (as shown in your debug info), but there are other plugins installed and some might not clean up completely even when disabled. This probably doesn't matter, but just to be safe.

I'm also not sure how this relates to #21; that issue is when two tabs are open, one is focused (the one that is currently viewed/edited), and if you try to click on a link in the other tab, the link doesn't open because it is not focused.

zhaoshenzhai commented 1 year ago

Also, fyi, this might take a while to fix, so in the meantime you could downgrade to a previous version where this issue does not occur to continue working as usual. I've been gradually rewriting the plugin since around 0.2.7, so rolling back to 0.2.6 might work for now.

This might also be a good way to debug it, since it helps me identify when this issue first started appearing.

Do not roll back to 0.1.x, it works completely differently and will change your notes.

MiquelJorquera commented 1 year ago

Your interpretation of issue 1 is not quite right. It's not that Obsidian becomes laggy (I used that word loosely in Discord, which is why I didn't use it here). Issue 1 and issue 3 are actually the same: If I click a link, there's a good chance that a new note will be created instead. Please disregard me saying that hovering over a link for a few seconds makes it work. After further testing, that is not true.

Both issues 1/3 and 2 only occur in Live Preview mode. Not in Reading mode nor in Source mode. Ctrl for Live Preview is disabled for all modes. I very much suspect that the issues come from the same source: they never occur separately.

My vault is not that big, just 22 notes with a couple hundred words each. I make heavy use of block links.

I just tried to reproduce the issue in a new vault and was unable to do so. Either with just MathLinks installed, or having installed and enabled all other plugins I'm using. If it's worth anything, my installed plugins are: 1: Extended MathJax v0.4.1 2: Frontmatter Tag Suggest v0.4.1 3: Latex Suite v1.7.3 4: Paste image rename v1.6.1 5: Style Settings v1.0.6 6: Flashcards v1.6.5

The issue starts occurring from version 0.3.0. Version 0.2.9 works fine (although the link [[#$σ$-algebra|$σ$-algebra]] only renders MathJax in Reading mode, not in Live Preview mode). That makes some sense, since 0.3.0 sounds like a large update, with a merging and all.

zhaoshenzhai commented 1 year ago

Thanks for clarifying!

I just tried to reproduce the issue in a new vault and was unable to do so. Either with just MathLinks installed, or having installed and enabled all other plugins I'm using.

I tried reproducing as well, and the behaviour is quite random. Sometimes the page preview will pop up, other times not, but I never encountered a case where a new untitled note was created, even when page preview isn't working.

although the link [[#$σ$-algebra|$σ$-algebra]] only renders MathJax in Reading mode, not in Live Preview mode

Live-preview only works mostly properly after 0.3.0, so you'll lose that feature.

For the 'creating new note' issue, the only place in the code that could cause this is the following line: https://github.com/zhaoshenzhai/obsidian-mathlinks/blob/44e681da9eac6eacb557a79ebfd483a9a9b6b2ba/src/preview.ts#L29 If this.outLinkFileName is "", then an untitled note will be created. Could you please tell me the names of the notes involed with mathlinks (the note with the link, and the note linked to), and the mathLink alias itself?

MiquelJorquera commented 1 year ago

Oh I didn't mention. This doesn't affect only links that use mathLinks. It affects every single link randomly. I don't really want to reinstall the non-working version of MathLink, but some examples that I remember causing the issue are [[#^Topology|topology]], [[Set#set|set]], or[[Topology#^OpenSet|open set]]misremembered, with no mathLink alias whatsoever. The names of the notes doing the linking may be "Topology", "Set", or "Algebraic structure". Definitely not empty.

zhaoshenzhai commented 1 year ago

~Oh, thats very weird.~ On second thought, maybe its because the names of the notes contain # and/or ^, which are special characters. I'll look into it.

MiquelJorquera commented 1 year ago

Okay I just updated the plugin to the latest version, and it turns out that the links that are causing the issue are the ones that have the format [[#^block|name]] or [[#section|name]]. Not [[title|name]], nor [[title#section|name]], nor [[title#^block|name]], nor [[#^block]], nor [[#section]].

zhaoshenzhai commented 1 year ago

Yes! This seems to be the issue. I've never used links that link to certain parts of the notes though, so I'll need some time to learn its syntax to test all the cases.

zhaoshenzhai commented 1 year ago

I've implemented a fix in the 0.3.5 prerelease. Could you please try it out and see if everythings ok?

MiquelJorquera commented 1 year ago

The issue about creating new untitled notes is fixed! But Page Preview still works only sometimes, iff I enable MathLinks.

zhaoshenzhai commented 1 year ago

Right, I haven't done anything for the page preview issue yet, as I'm still not entirely sure whats causing it.

I think I'll hold this off for now, until I get a better idea of whats going on. I'll open a separate issue for this, and link #21 in case.

MiquelJorquera commented 1 year ago

I have an update that may help narrow down the Page Preview problem. I noticed that if you hover over an open link (as in, you can see both the link and the alias in [[link|alias]] or [link](alias) format), it always works in some cases:

image

I tested it several times and it's been consistent so far that open Wikilinks previews work if you hover over the alias or link, and that for Markdown links it only works when hovering over the alias (EDIT: In vanilla Obsidian that's the same. It seems like the only issue that MathLinks introduces is in the Page Preview of the "compact" link).