clojurescript

Zak Venter 2025-11-29T03:46:19.768539Z

I'm trying to use [this example](https://github.com/metosin/reitit/blob/master/examples/frontend/src/frontend/core.cljs) for building a simple router with reitit, however I'm running into cyclical dependency issues. The issue comes from the router importing views, a link component requiring the router, and then my views requiring the links. Any advice on how to do the links or further reading would be much appreciated!

thheller 2025-11-29T08:00:03.778519Z

IMHO most router libs are complete overkill for what you actually need in the frontend. I always just have one function that takes the URI string and turns it into a datastructure of some kind. that data I put into the "app-db" (using re-frame terms) and render based on that using a simple case (or equivalent)

thheller 2025-11-29T08:01:23.284229Z

so that can look something like this https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/cljs/ui/db/generic.cljs#L22-L100. notice the ::m/current-page value being set

thheller 2025-11-29T08:01:48.356769Z

that is then loaded and used like this https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/cljs/ui/main.cljs#L140-L159

thheller 2025-11-29T08:02:18.024389Z

granted the whole UI isn't all that complex, but I have never needed a more complex "router" for anything

thheller 2025-11-29T08:03:50.296019Z

but to address your question more practically. to prevent the circular dependency you use data, meaning not putting your view functions into your routing data directly like :view home-page, but instead :view :home-page and then using a case like above or a multi method to render it

➕ 1
wevrem 2025-11-29T16:07:31.816109Z

I use re-frame and I also use reitit, and Thomas is probably right that it could be overkill, but it is too late, I started years ago. I make use of :as-alias to deal with cyclical dependencies. These mostly arise when I need to refer to a re-frame event or subscription, or to a route name. All of these are namespaced keywords in my codebase, so :as-alias lets me refer to them properly without creating a cycle.

Zak Venter 2025-11-29T22:50:13.552399Z

Appreciate the responses

danielsz 2025-11-29T18:22:32.988519Z

In the Clojurescript REPL, editing source code triggers the built-in watch handler but results in an error "Watch compilation log available at: target/classes/js/watch.log" which amounts to Requested array size exceeds VM limit . It's a Clojurescript codebase with npm dependencies, target is bundle. Anyone saw this?

p-himik 2025-11-29T18:27:11.326529Z

> In the Clojurescript REPL, editing source code [...] What does it mean, how do you edit source code via REPL?

danielsz 2025-11-29T18:27:50.764329Z

Sorry, I meant after editing the source code in my editor (Emacs)

p-himik 2025-11-29T18:30:13.948119Z

Does that error not have any stack trace? Do any of the namespace attempt to do something at the top level, other than defining things? Especially interested whether there's any printing going on anywhere.

danielsz 2025-11-29T18:32:13.300119Z

[{:type java.lang.OutOfMemoryError :message Requested array size exceeds VM limit :at [java.util.Arrays copyOf Arrays.java 3537]}] :trace [[java.util.Arrays copyOf Arrays.java 3537] [java.lang.AbstractStringBuilder ensureCapacityNewCoder AbstractStringBuilder.java 282] [java.lang.AbstractStringBuilder append AbstractStringBuilder.java 897] [java.lang.StringBuffer append StringBuffer.java 422] [java.io.StringWriter write StringWriter.java 79] [java.io.StringWriter append StringWriter.java 213] [java.io.StringWriter append StringWriter.java 43] [clojure.core$fn__7430 invokeStatic core_print.clj 218] [clojure.core$fn__7430 invoke core_print.clj 212] [clojure.lang.MultiFn invoke MultiFn.java 234] [clojure.core$pr_on invokeStatic core.clj 3700] [clojure.core$pr_on invoke core.clj 3694] [clojure.core$print_sequential invokeStatic core_print.clj 66] [clojure.core$fn__7436 invokeStatic core_print.clj 225] [clojure.core$fn__7436 invoke core_print.clj 225] [clojure.lang.MultiFn invoke MultiFn.java 234] [clojure.core$pr_on invokeStatic core.clj 3700] [clojure.core$pr_on invoke core.clj 3694] [clojure.core$print_prefix_map$fn__7439 invoke core_print.clj 233] [clojure.core$print_sequential invokeStatic core_print.clj 66] [clojure.core$print_prefix_map invokeStatic core_print.clj 229] [clojure.core$print_map invokeStatic core_print.clj 238] [clojure.core$fn__7468 invokeStatic core_print.clj 266] [clojure.core$fn__7468 invoke core_print.clj 263] [clojure.lang.MultiFn invoke MultiFn.java 234] [clojure.core$pr_on invokeStatic core.clj 3700] [clojure.core$pr_on invoke core.clj 3694] [clojure.core$print_prefix_map$fn__7439 invoke core_print.clj 233] [clojure.core$print_sequential invokeStatic core_print.clj 66] [clojure.core$print_prefix_map invokeStatic core_print.clj 229] [clojure.core$print_map invokeStatic core_print.clj 238] [clojure.core$fn__7468 invokeStatic core_print.clj 266]]} Watching paths: /home/daniel/Clojure/experiment/src/cljs

p-himik 2025-11-29T18:34:54.307959Z

Ah, don't you just love stack traces that start nowhere. No idea what could be causing it but I'd try putting a break point in one of the printing-related functions in the stack trace. Won't help with the issue itself but at least it would give a clue where the printing happens.

thheller 2025-11-29T18:34:57.413779Z

looks like its trying to print something that is too large to print. could be something small that just has a reference to itself, e.g. an atom that contains itself.

danielsz 2025-11-29T18:40:31.824459Z

I am exploring the "@xyflow/react" library, I was trying to do something silly. I removed the component and it's good now. I'll try something else. Thanks, folks!