obb icon indicating copy to clipboard operation
obb copied to clipboard

Don't use enable-console-print in projects built with shadow

Open borkdude opened this issue 3 years ago • 5 comments

https://github.com/babashka/obb/blob/d8e5245dc3927527e89ce793f7fb2c57266e47f1/src/obb/impl/core.cljs#L62

See: https://github.com/BetterThanTomorrow/calva/issues/1468#issuecomment-1014781194

I still have to read the entire issue to find out why, when I have time.

borkdude avatar Jan 18 '22 09:01 borkdude

That comment is all there is to read about it on this issue (which is about other, also interesting things). In fact you don't even need to read the full comment. Only this part, from Thomas Heller:

Never call this with shadow-cljs anywhere. It is never required in any setup and it will interfere with printing.

PEZ avatar Jan 18 '22 09:01 PEZ

Sure, but why? I'd like to understand the details. Is there a way to have the same code behave well in both shadow and cljs.main?

borkdude avatar Jan 18 '22 09:01 borkdude

I mainly wanted to hep you not have to read the whole issue. 😄 I don't know the details and haven't found any further info on this. Ping @thheller.

PEZ avatar Jan 18 '22 09:01 PEZ

Fair enough :)

borkdude avatar Jan 18 '22 09:01 borkdude

If you look at the implementation of enable-console-print! you'll see that it unconditionally sets *print-fn* and *print-err-fn*. shadow-cljs does set its own print-fn on load which will not only print to the console but also send all messages back to the shadow-cljs instances so it can send them futher along to the nrepl client or so.

As a safeguard I actually replace enable-console-print! with a noop. I actually forgot that I did that but I did it because too many people called this and wondered why they were getting no more prints in the REPL. ;)

In essence you can call it but you shouldn't.

thheller avatar Jan 18 '22 17:01 thheller