Fork me on GitHub
#portal
<
2022-11-11
>
wilkerlucio13:11:09

@djblue hello, Im seeing some stack overflow errors when I try to log some maps to portal in the latest version

wilkerlucio13:11:55

I used to print those same structures without issues before, so I believe its something about the new version

wilkerlucio13:11:49

(this is a quite large map)

djblue15:11:01

Is this a regular clojure map or a custom type?

wilkerlucio15:11:46

the root is a regular map, but nested inside it has other custom types

wilkerlucio15:11:59

also volatiles and atoms

djblue15:11:20

Instead of lazily pr-str'ing objects, which was causing other issues, I do it up front. I remembered to exclude atoms, but forgot about volatiles. Those tend to not print well, especially because they can have cycles. This is my best guess :thinking_face:

djblue15:11:47

Should also be able to eval 👇 locally at the repl to try the fix

(in-ns 'portal.runtime)

(defn- to-object [buffer value tag rep]
  (if-not *session*
    (cson/tag buffer "remote" (pr-str value))
    (let [m (meta value)]
      (when (atom? value) (watch-atom value))
      (cson/tag
       buffer
       "object"
       (cond-> {:tag       tag
                :id        (value->id value)
                :type      (pr-str (type value))
                :protocols (cond-> #{}
                             (deref? value) (conj :IDeref))}
         m   (assoc :meta m)
         rep (assoc :rep rep)
         (not (deref? value))
         (assoc :pr-str (pr-str value)))))))

wilkerlucio16:11:22

I can confirm it fixes after I run the patch in my REPL 🙂

cjsauer16:11:50

Is portal compatible with shadow-cljs? I can't seem to get it working. My project runs in the browser, I have portal on my classpath, I use npx shadow-cljs watch :app to boot up a repl, open the web page, but portal.web/open throws Cannot set properties of null (setting 'onunload')

djblue16:11:25

If you look in the devtools, it's probably complaining about popups. Might need to enable popups to get the UI open.

cjsauer16:11:26

Oh pfff...sorry. I had to enable pop-ups, just like the docs say

cjsauer16:11:49

@djblue yep that was exactly it

cjsauer16:11:59

I didn't read the docs closely enough 😅

cjsauer16:11:56

Oh perfect, thanks!

cjsauer16:11:59

Will look at this

cjsauer17:11:18

So would something like this allow me to tap values from the web page and display them in the Intellij plugin? :thinking_face:

👍 1
cjsauer17:11:27

Hm...I kind of got it working. I can tap values from my shadow cljs app, and they appear in intellij portal viewer, but now when I want to deref the selected portal value I have to do so from the clj repl? So values are getting serialized via transit from cljs to clj. Might be too much context switching to be worth it.

cjsauer17:11:49

Seems only "pure data" values actually survive the trip as well, which the docs do mention.

👍 1
cjsauer18:11:11

The "in browser" setup is really cool tho. I put the portal setup code right in user.cljs and preloaded it from shadow, so now it auto-pops open the portal window when I start my app. And @p is easily accessible. Neat!!

💯 1
rschmukler19:11:12

Hey again! I think I may have found another bug: When implementing a custom nav protocol it seems like the metadata specifying the default view is ignored. Also if Slack isn't the best place for this stuff please let me know if you'd rather I move it into GH.

djblue19:11:58

Either works for me. Can you share some of the implementation?

djblue19:11:44

Portal will try to set the default viewer on the metadata of a value based on what's selected in the UI https://github.com/djblue/portal/blob/master/src/portal/ui/commands.cljs#L504, but existing metadata takes precedence

rschmukler20:11:43

Sure, I am doing something like this:

(tap>
  (with-meta
    {:foo 5}
    {`clojure.core.protocols/nav
     (fn [x _ _]
       (with-meta
         x
         {:portal.viewer/default :portal.viewer/pr-str}))}))

rschmukler20:11:47

I would expect that the metadata of value returned from nav (in this case identity, but in my actual case, some derived data) would also work

djblue22:11:39

I think this might be an edge case with propagating the viewer from the previous value 👌

djblue22:11:49

Should be an easy fix