Skip to content

[BUG] Code injection & pre/post execution leads to duplication/stacking. #417

@MathiasSven

Description

@MathiasSven

Describe the bug

  • When code injection is present, code keeps getting injected repeatedly.
  • When using pre and post, subsequent runs of code stack.

To me, it seems both of these issues stem from the same bug.

Tangentially, it also seems that {post} blocks aren't executed the first time around.

NOTE: While the examples here are for JavaScript and Python, which support Notebook mode (which is disabled here), the same behaviour is present with Rust for example, where we set Inject Rust code, that code will be readded on multiple runs, leading to unused warnings, since we keep redefining the same functions over and over. So the issue is not just with languages with Notebook support mode.

See video for full behaviour.

Software Version

OS: Linux 6.12.13, NixOS, 25.05 (Warbler)
Plugin Version: 2.1.2
Obsidian Version: 1.8.4

To Reproduce

``\`python {pre}
if "var" in globals():
    var += 1
else:
    var = 0
print("Hello")
``\`

``\`python
print("Nice too meet you", var)
``\`

``\`python {post}
print("Goodbye!")
``\`

Expected behavior

The entire code is reconstructed each time Run is pressed.

Screenshots/Video

obsidian-2025-04-08_20.11.07.mp4

Additional Context

General Settings

  • Timout (In seconds): 10
  • Allow Input: True
  • [Experimental] Persistnent Output: False

Python Settings:

  • Embed Python Plots: True
  • Python path: ../bin/python3
  • Python arguments:
  • Run Python in Notebook mode: False
  • Inject Python Code:

Javascript Settings:

  • Node path: .../bin/node
  • Node arguments:
  • Run Javascript blocks in Notebook mode: False
  • Inject Javascript code:
console.log("Hello")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions