localhostclojurescriptread-eval-print-loopnreplshadow-cljs

How to make the browser connection to the shadow-cljs nREPL be longer?


I have been using Clojure, ClojureScript, lein, shadow-cljs, Emacs, and CIDER to work on a Clojure/ClojureScript dynamic web app project.

Usually, I build the project executing command cider-jack-in-cljs in Emacs, I choose shadow-cljs, then shadow for REPL type, and app for build option.

It works fine. I can watch changes on the UI on localhost:3005.

However, quite often the following happens:

enter image description here

Apparently, this phenomenon (not sure about the technical name) happens after some period of inactivity.

If I try something in the REPL, I get:

cljs.user> net-income
No available JS runtime.
See https://shadow-cljs.github.io/docs/UsersGuide.html#repl-troubleshootingnil

To make it work again, I need to refresh the browser. This is a little painful.

After refreshing the browser, the UI is back. However, I need to re-eval all variables previously defined in the REPL. This is big time painful.

For instance, if I did:

cljs.user> (def accounts @(re-frame.core/subscribe [:the-accounts sel]))

The "browser crash" which is caused by inactivity will erase all previous definitions.

1 - Is there some way to expand the time necessary for the browser to crash?

2 - Or, alternatively, is there a way to retrieve my previous variable definitions on the REPL without the need to re-eval one by one?

Obs.: in the same session, the REPL history works. I have the history, I just do not have the values inside the running lisp image.


Solution

  • I very much doubt that this has anything to do with shadow-cljs or CLJS in general. It seems far more likely that one of your extensions is causing this. Judging by the icons up top you seem to have a lot of them. They all can potentially interact with the page and they all can do all sorts of things. Maybe there is something in those leaking memory and eventually crashing. I'd try disabling them and see if you can isolate the problem.

    I personally have never had an issue with a Chrome tab crashing. I usually have my REPL connected for very long times (days or even weeks). It does reconnect fine after sleep, and it does sit there idle most of the time.

    The tab isn't supposed to ever crash, and there is no way to retrieve the previous state after such a crash.