Developer-Mike / obsidian-advanced-canvas

⚡ Supercharge your Obsidian.md canvas experience! Create presentations, flowcharts and more!
GNU General Public License v3.0
363 stars 16 forks source link

[BUG] json data re-arranges incosistently; Makes canvases not work well with version control #104

Open JulianNoel-Devhouse opened 2 months ago

JulianNoel-Devhouse commented 2 months ago

Whenever this plugin touches .canvas files, even when the user hasn't explicitly modified the canvas, the plugin appears to re-save the json data, and the order in which it arranges nodes seems to change each time, creating large and messy diffs in the json data that are difficult to resolve.

We're attempting to use Obsidian to act as the root souce of information for our teams and projects, and heavily make use of Advanced Canvas for diagrams of processes, system architectures, and even meeting notes. It's been difficult to keep things sycned when the canvas's json isn't being written to in a consistent way.

I'll likely be attempting to fix this myself in the meantime and will submit a PR if I make any progress

Information about any known workarounds would also be appreciated!

Developer-Mike commented 2 months ago

Because JavaScript objects don't have an order, the JSON.stringify function's order is arbitrary. Obsidian's inbuilt canvas does have another stringify method that might handle this inconvenience. But unfortunately it's broken (#82) and the Advanced Canvas plugin does override it with the JSON.stringify function. According to the Obsidian team, their stringify function is fixed in version 1.7.0 and Advanced Canvas might relay on the default behaviour. But I need to investigate this further. Feel free to open a pull request if you manage to fix this.

Developer-Mike commented 2 weeks ago

You may want to try this version which uses the json-stable-stringify library. I'm not sure yet if it will get added to the regular releases. I would appreciate a feedback if you end up trying this version.

stable-stringify.zip