-
-
Notifications
You must be signed in to change notification settings - Fork 127
Description
Thanks for your time and help and for the excellent work on this project!
Expected
- When running
org-roam-ui-mode, when the sqlite databases are empty (this occurs when the directory specified byorg-roam-directorycontains no org roam files), the UI renders without any visible frontend errors or console errors.
Actual
- In the browser console, I see an error:
Uncaught TypeError: e.nodes is null
- I receive this websocket data:
{"type":"graphdata","data":{"nodes":null,"links":null,"tags":null}}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
- The UI works with an empty DB / empty directory without any kind of error to reduce friction for brand new users
- In a perfect world, there might even be a UI notice / alert to the user that they have no notes created yet. IMO, this is outside of the scope here, but I'd be happy to work on this if anyone is interested.
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
Line 321 in b153f4f
| (websocket-send-text oru-ws (json-encode `((type . "graphdata") (data . ,response)))))) |
; response variable has this structure before we send it to the server when dbs are empty:
'((nodes) (links) (tags))
; this serializes like this:
(json-encode '((nodes) (links) (tags))
"{\"nodes\":null,\"links\":null,\"tags\":null}"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:
(json-encode '((nodes . []) (links . []) (tags . [])))
"{\"nodes\":[],\"links\":[],\"tags\":[]}"Repro steps
- Run the following Elisp snippet, which creates an empty directory, and then follows suggested org-roam setup and org-roam-ui setup, binding
org-roam-directoryto the empty directory.
(defun repro()
; org-roam
(require 'org-roam)
(let ((real-dir "~/Desktop/notes/org-roam") (empty-dir "~/Desktop/empty-dir"))
(make-directory empty-dir t)
(setq org-roam-directory empty-dir))
(setq org-roam-v2-ack t)
(org-roam-setup)
; org-roam-ui
(add-to-list 'load-path "~/code/org-roam-ui")
(load-library "org-roam-ui")
)
(repro)- Run
(org-roam-ui-mode)and navigate to the opened window. - See a blank screen with a console error at http://localhost:35901/
Related issues or PRs
- This is a similar type of issue as Biank Screen: Uncaught TypeError: Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method. #17 which happens when links are null
- Fixes #17 - Allow Graph rendering without tags or nodes jhhb/org-roam-ui#1 (comment)