Obsidian-Code-Styler icon indicating copy to clipboard operation
Obsidian-Code-Styler copied to clipboard

Bug: Code styler not rendering properly

Open dylan-daniel opened this issue 1 year ago • 5 comments

Describe the bug

I have to reload Obsidian multiple times to get the plugin to render code properly.

Steps to reproduce

  1. Create a new note with a code snippet inside.
  2. Create a new canvas card and link that note to it.
  3. 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) image

Current behaviour

(what usually happens during rendering) image

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

src\ReadingView.ts

while(!codeblockCodeElement.classList.contains("is-loaded"))
    await sleep(50);

dylan-daniel avatar Nov 21 '24 23:11 dylan-daniel

it work fine for my system

Image

Mandeep56Singh avatar Jan 21 '25 15:01 Mandeep56Singh

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 avatar Jan 21 '25 16:01 mayurankv

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

Mandeep56Singh avatar Jan 21 '25 18:01 Mandeep56Singh

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.

mayurankv avatar Jan 21 '25 23:01 mayurankv

This issue is stale because it has been open 60 days with no activity.

github-actions[bot] avatar Nov 18 '25 02:11 github-actions[bot]