Obsidian-Code-Styler
Obsidian-Code-Styler copied to clipboard
Bug: Code styler not rendering properly
Describe the bug
I have to reload Obsidian multiple times to get the plugin to render code properly.
Steps to reproduce
- Create a new note with a code snippet inside.
- Create a new canvas card and link that note to it.
- Rendering issue occurs.
A = {1, 2, 3, 4}
B = {"A", "B"}
C = {"Apple", "Banana", "Orange"}
print({(a, b, c) for a in A for b in B for c in C})
Expected behavior
(after multiple reloads it finally rendered)
Current behaviour
(what usually happens during rendering)
Environment
- Plugin Version: 1.1.7
- Obsidian Version: 1.7.7
- Platform: Desktop
- OS: Windows
- Theme: Dark Mode
- CSS Snippets: None
Additional context
This issue occurs on my computer but does not occur on my laptop. If you need to see the issue happening in real time, contact me on Discord (username: inanotoxin).
UPDATE
I have found the issue. I believe that my computer is rendering the code block too fast and not waiting enough time before applying the new formatting. To fix the issue, I have replaced await sleep(2) with await sleep(50).
while(!codeblockCodeElement.classList.contains("is-loaded"))
await sleep(50);
it work fine for my system
Eurgh, that delay was set for a specific reason, I can't recall at the minute (trade off between initial lag and needing time for obsidian to render the codeblock in the first place. One of the first things I intend to do working on this is refactor how this works so will definitely keep in mind that this issue varies across computers. (2ms was the perfect trade off on my laptop but not tested across different systems). Thanks for the very helpful report.
I'll leave this open as this is still an issue that needs resolving even though you've found a local fix.
@mayurankv seems like you have a lot to work. I can help. I have experience in Typescript, react, javascript. But I don't know how will I test the changes since it's an obisidian plugin.
Happy for any assistance, feel welcome to look at the outstanding issues (a few have gone stale so need to do some cleaning of those too) and submit a PR. The first place to look for testing Obsidian plugins would be The sample plugin and the documentation. Additionally using Hot Reload and BRAT.
This issue is stale because it has been open 60 days with no activity.