clojurescript

Jack Arrington 2026-02-11T09:54:21.812009Z

I'm writing a full-stack app with a lot of .cljc files, I I frequently find myself doing a lot of dialect-conditional requires:

#?(:cljs [reitit.frontend :as rf])
#?(:cljs [reitit.frontend.controllers :as rfc])
#?(:cljs [reitit.frontend.easy :as rfe])
Fine but a little verbose. I'm wondering if there's any way to pass multiple forms for the :cljs key? Something like:
#?(:cljs [reitit.frontend :as rf]
         [reitit.frontend.controllers :as rfc]
         [reitit.frontend.easy :as rfe])
?

cjohansen 2026-02-11T10:19:06.914149Z

Not really, unless you want to have separate :require for clj and cljs. I think the real solution to this problem is to use more libraries that are cljc compatible. If you have a lot of conditional requires, I'm sure you have equally lots of reader literals throughout your code. That kind of undermines the power of cljc in my mind.

liebs 2026-02-11T10:24:48.630909Z

Isn't there an unquote-splicing version of the reader conditional?

liebs 2026-02-11T10:25:25.598549Z

I don't know how to use it bc I avoid CLJC but pretty sure it's documented in the http://clojure.org guide on reader conditionals

thheller 2026-02-11T10:30:35.987529Z

(ns demo.dummy-cljc
  (:require
    [foo.all]
    #?@(:cljs
        [[reitit.frontend :as rf]
         [reitit.frontend.controllers :as rfc]
         [reitit.frontend.easy :as rfe]])))

☝️ 1
1
thheller 2026-02-11T10:30:38.996929Z

this works. bit ugly, but works an can have :clj branch as well. foo.all is example for require that is done in all variants in case you have something common

👍 1
cjohansen 2026-02-11T10:37:34.534919Z

Ah, right! My first thought was something along these lines, then I couldn't remember it and thought I'd hallucinated it 🙈

Jack Arrington 2026-02-11T10:42:58.296269Z

Thanks @thheller, that does the trick.

Craterfall 2026-02-11T18:32:18.197159Z

I am trying to get mui-tiptap to run I keep getting this error react-dom.development.js:12056 Uncaught RangeError: Adding different instances of a keyed plugin (plugin$) From what I understand its because the text-box or the extensions keeps getting loaded hence the the defonce, key, and the mounted logic to try and stop it Any ideas?

imports 
[reagent.core :as r]
["mui-tiptap" :as MuiTiptap]
["@tiptap/starter-kit" :as TiptapStarterKit]

(def rich-text-editor
  (r/adapt-react-class
    (or (.-RichTextEditor MuiTiptap)
        (.-default MuiTiptap))))
(defonce starter-kit-extension
         [(.configure
           (or (.-StarterKit TiptapStarterKit)
               (.-default TiptapStarterKit)))])
(defn tiptap-editor []
  (let [editor-ref (r/atom nil)
        mounted? (r/atom false)]
    (r/create-class
      {:display-name "tiptap-editor"
       :component-did-mount (fn []
                            (reset! mounted? true))
       :reagent-render
       (fn []
         (when @mounted?
           [:div {:style {:border "1px solid #ccc"
                        :padding "10px"
                        :border-radius "4px"
                        :color "black"}}
           [rich-text-editor
            {:editor-ref editor-ref
             :key "rte"
             :extensions starter-kit-extension
             :content "<p>Please show up</p>"}]]))})))
[:div [tiptap-editor]]

p-himik 2026-02-11T20:36:00.239419Z

I'd just check what's going on with a debugger. Find where the error is originally created/thrown and break right before the associated check to see what exactly goes down that code path.

schadocalex 2026-02-11T21:31:22.747479Z

Hi, looks like it's not related to reagent. You could try to reinstall/update all peer dependencies of mui-tiptap

Craterfall 2026-02-11T23:31:19.960079Z

It looks like it was an existing bug with an underlying library I swapped to https://github.com/niuware/mui-rte and seems to work. Thanks