Fork me on GitHub

How do you prevent checking for form validity using .checkValidity while a form/element is still rendering? I am running into an issue where react-dom logs an error to console when form.checkValidity() is called during render. I am attempting to validate fields of a form before allowing submission, via the following:

(let [form-id "create-category-form"
        ready-state #(. js/document -readyState)
        checkValidity #(when (= "complete" (ready-state))
                         (and (when (not (nil?
                                          (.getElementById js/document form-id)))
                                 (.getElementById js/document form-id)))))
        valid-form? #(and (.reportValidity (.getElementById js/document form-id)))]
             (when (and (checkValidity) (valid-form?))
               {:href (rfe/href :myProject.routes/categories)})
             {:on-click #(do
                           (when (valid-form?)
                             (re-frame/dispatch [:handler-with-http submit-params])))})
     "Add category"])
What is the correct way to use .checkValidity and .reportValidity without causing this error to be logged to the console?
Warning: unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering.
    in create-category-form (created by main-panel)
    in main-panel


I could use some enlightenment. Why doesn't the promise ever resolve here?

(defonce !counter (atom 1))

(js/setTimeout #(swap! !counter inc) 1000)

(defn counter-at-n?+ [n]
   (fn [resolve]
     (js/console.warn "counter currently at " @!counter)
     (if (= n @!counter)
       (resolve @!counter)
       (js/setTimeout #(counter-at-n?+ n) 1000)))))

(counter-at-n?+ 10)


Each call to counter-at-n?+ creates a new promise.


I'm aware. But each part of the promise chain derefs the atom. Shouldn't the value be derefed one second later due to the timeout, thus making the value accurate?


Just to be clear - the console log always returns the same value, as if the atom's value is cached for the whole promise chain. That's the part I don't understand


This is not a "promise chain", this is a promise within a promise without resolving anything. When the setTimeout is called from within the promise, you lose the reference to that resolve. Now you can never call it, thus never resolving that outer promise. Regarding the atom - you expect the value 10 but provide it with the value 1 that turns to 2 in a second. You never change the value of the atom, except for that second line. How do you expect 2 to become 10?


This shhould have been an interval of course


That's a good point about resolving, I think I get it


That only one problem. The memory leak with dangling promises is the other.


No problem.

Eamonn Sullivan10:04:06

Hi all, I have a small experimental Clojure library ( that I'd like to turn into a mono-repo that produces both a jar and an npm package (shadow-cljs), with some common code (.cljc). Is this possible? Has anyone tried this and can point me to an example I can study?


Is it possible to eval js in cljs?


(js/eval "js string")


ah, thanks!


Depending on what you’re doing, js* might be more suitable.


You did say “eval”, which implies runtime eval. But if you’re just wanting to emit raw javascript in your code, that’s what js* is for.


@potetm Yeah I think that’s more along the lines of what I’m looking for. Do you know where I can find docs / example usage?


(js* "alert('foo bar!')")


just plop whatever js you want in the string


though there are sometimes cases where you want that sort of thing, I should note that you can pretty much always accomplish it with cljs.


e.g. the above would be (js/alert "foo bar!")


Hi all, How to make Clojurescript compiler output multiple independent spec .js files for multiple specs written in clojurescript for Cypress to run test?


Very beginners question I'm afraid, but anyway: I made a simple clojure dummy "server-side web application" (thanks to this great idiot proof guide ) using ring and compojure. Now I'm trying to use cljs' cljs-http send a request from my front end to the server side api, without succes. I get the following:

app:cljs.user=> (go (let [response (<! (http/get ""))]
           #_=>                         (prn response)))
{:status 0, :success false, :body "", :headers {}, :trace-redirects ["" ""]
, :error-code :http-error, :error-text " [0]"}
Running curl in bash does work though (5 was the response I expected):
curl ""
Is there a difference between http-requests and curl I'm missing? Or am I using cljs-http incorrectly?


the requests aren’t exactly the same. what does

curl ""
respond with?


or alternatively:

(http/get "")


not sure if the trailing slash will make a difference. if that doesn’t help. I would check out the request in chrome’s network debugger


Thanks for the help! Unfortunately adding or deleting trailing slash doesn't make a difference. Looking at the chrome debugger gave me this though:

Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
So I guess the solution lays somewhere here:


It's headers. When you do a curl request, by default it doesn't add the current origin in, because it doesn't have one. When you do a request from your browser, it adds the origin in, and your webserver at localhost:8000 won't allow origin localhost:3449


So either you can add something to your server that allows localhost:3449, or alternatively open up the js on the something like