Fork me on GitHub
#re-frame
<
2021-12-21
>
Pavel Klavík19:12:07

Hi, my ClojureScript project is failing on Safari when compiled in advanced mode but not when in development. The error is the following which happens in Re-frame:

emccue19:12:40

@pavel.klavik can you share your compiler output? any warnings?

Pavel Klavík19:12:42

shadow-cljs - config: C:\Shared\orgpad\shadow-cljs.edn shadow-cljs - socket connect failed, server process dead? NPM dependency "react" has installed version "^16.14.0" "16.13.0" was required by jar:file:/C:/Users/pavel/.m2/repository/reagent/reagent/0.10.0/reagent-0.10.0.jar!/deps.cljs NPM dependency "react-dom" has installed version "^16.14.0" "16.13.0" was required by jar:file:/C:/Users/pavel/.m2/repository/reagent/reagent/0.10.0/reagent-0.10.0.jar!/deps.cljs [:client] Compiling ... [:client] Build completed. (1220 files, 405 compiled, 0 warnings, 87.43s)

lilactown21:12:29

to help debug, compiling your project in debug release mode can help

lilactown21:12:43

you can do that from the CLI with shadow-cljs release client --debug

lilactown21:12:54

this will ensure that pretty names are printed.

lilactown21:12:03

I don't see any reference to intersects in re-frame's code. it could be an error in one of your handlers

Pavel Klavík23:12:32

It is likely unrelated to Reframe, it was just also throwing stack traces here as well.

Pavel Klavík23:12:11

It is bizzare behavior of Safari which somehow changes nil to 0 when passing it into another function. I have no explanation for that.

kennytilton23:12:14

I often hear people ask about using subscriptions in weird places and then be warned "You can do it, but you will leak subscriptions." And the FAQ https://github.com/day8/re-frame/blob/master/docs/FAQs/UseASubscriptionInAJsEvent.md has "might create a memory leak (the subscription might not be "freed". btw, why does it say "might not be freed"? Why the uncertainty? Put another way,how does re-frame know when it can GC subscriptions? I am working on a new r/f project and seeing subscriptions created and immediately deref-ed just to read the app DB, outside the usual view function, and I have to guess these fall in the leaked category. Or might. :) In cases like these, is it better to just access the app DB directly? I do not see a need for reactive data flow, usually: they are just pulling data from static state loaded with the page.

p-himik23:12:57

> why does it say "might not be freed"? Why the uncertainty? Because subscriptions that are used in a reactive context (view functions, reactions, as signals to other subs) will be registered for cache cleanup when their context no longer needs them, via reagent.ratom/add-on-dispose!. Re-frame code is rather easy to follow here. > In cases like these, is it better to just access the app DB directly? If it's something completely outside of a view, then yes - IIRC that's one of the things that re-frame documentation recommends. If it's something within a view but outside of a reactive context (a JS event handler), then you can simply create and deref such a sub in the view and then use the concrete value to create the JS event handler function.

kennytilton23:12:37

OK, but in the example from the FAQ, unless I misunderstand, the subscription established by (subscribe [:something]) will never be freed, because the anonymous event handler function is not dynamically in the reactive context. In which case, "might" is the wrong word. Maybe? :thinking_face:

p-himik23:12:17

It will never be freed if it's not used in any reactive context. If it's used once and exactly as in the example, it will indeed not be freed.

👍 1
steveb8n22:12:21

interesting. does that mean that this lib has a leak in it’s design? https://github.com/gadfly361/re-pressed/blob/master/src/main/re_pressed/impl.cljs#L179

p-himik07:12:45

Indeed. And I have a few other gripes with that codebase. But I'm not invested in that project in any way to get involved.