Open jhhb opened 3 years ago
Hey!
Thanks for your effort writing all the up!
I think the main obstacle here is that, for Elisp, an empty array and nil
are essentially the same thing, so it does make sense for json-encode to turn it into null
.
Now, for us JS devs it's not what we want or even expect.
Looking at the code, it feels to me like there's no elegant solution for that on the Elisp side. At the same time, I'm intuitively inclined towards some blatant in-your-face condition so that the behavior is very visible. But it's hard to come up with any.
Maybe we should encode "nodes", "links", and "tags" separately with some new stupid function (e.g. json-encode-or-empty-array) that would produce []
when the input is nil
-ish, otherwise, just call json-encode. And then we manually join them to produce a valid JSON string before sending it to the browser.
It's ugly AF but at least it's stupid in a good kind of way. :)
Or maybe there's a simpler solution which I don't know because I actually suck at Elisp.
Thanks for your time and help and for the excellent work on this project!
Expected
org-roam-ui-mode
, when the sqlite databases are empty (this occurs when the directory specified byorg-roam-directory
contains no org roam files), the UI renders without any visible frontend errors or console errors.Actual
I think this is something we could fix when serializing the data that we send via the websocket by ensuring that all alist entries have a non-nil value
Desired behavior
Suggested change
Thanks to @kirillrogovoy for suggesting a backend change as a good path. I'm happy to contribute any change; below is my thinking from looking at the code a bit:
Ideally, we prevent this state from ever occurring via Elisp changes. When we have an empty sqlite db, this is the value of the
response
variable at https://github.com/org-roam/org-roam-ui/blob/b153f4fee99e36dec0fb56d987026d53bf97a0e8/org-roam-ui.el#L321 :I was thinking we might be able to fix this issue by mapping over the
response
alist entries and sanitizing so that in the above example, we end up encoding this structure, instead of the original structure where nulls are possible:Repro steps
org-roam-directory
to the empty directory.(org-roam-ui-mode)
and navigate to the opened window.Related issues or PRs