Fork me on GitHub
#clojurescript
<
2022-02-10
>
ag01:02:49

I'm looking for a cljs lib/function that turns html in text into a hiccup structure, and I can't seem to find anything. Any suggestions?

tatut04:02:55

re-html-template also has that, but it is clj side functionality https://github.com/tatut/re-html-template/blob/master/src/re_html_template/parse.clj

tatut04:02:24

can be used as macro in cljs, but not runtime

ag01:02:59

... found this page http://github.com/weavejester/hiccup/wiki/Converting-html-to-hiccup I'll try the options listed there

xceno10:02:05

Can anyone confirm this exception please? When using clojurescript 1.10.914 and shadow-cljs 2.16.12 the following exception gets thrown at multiple places in cljc.java-time :

TypeError: Cannot read properties of undefined (reading 'get')
This happens in instant.cljs:2:11, day_of_week.cljs:2:16, etc.. so basically everytime goog.object/get is called somewhere. I'm using cljc.java-time:0.1.18as a transitive dependency

xceno10:02:47

It's pulled in by fulcro-rad, which has the exact same deps I just updated to: https://github.com/fulcrologic/fulcro-rad/blob/develop/deps.edn So something weird must be going on here

p-himik10:02:53

Some libraries might still be using goog.object without requiring it, relying on it implicitly being there. A recent version of CLJS has removed that, but there's a flag to restore that feature if you need it: https://github.com/clojure/clojurescript/blob/master/changes.md#changes-1

p-himik10:02:30

Also, just in case - don't specify CLJS version when using shadow-cljs. Instead, use the version that shadow-cljs provides - this way, you'll avoid potential conflicts which can be rather hard if not impossible to circumvent.

xceno10:02:43

Thank you 🙂, this is indeed the issue! Adding :global-goog-object&array true to the shadow-cljs compiler options fixes it. So it's a bug in cljc.java-time:0.1.18 introduced by clojurescript:1.10.914. For others finding this later, here are some additional links: • https://ask.clojure.org/index.php/11274/cljs-3330-has-broken-goog-object-gethttps://clojurescript.org/news/news#_google_closure_library_goog_module_global_accesshttps://clojurescript.org/news/2021-11-04-release#_google_closure_library_goog_module_global_accesshttps://clojurescript.org/reference/compiler-options#global-goog-object-ampersand-arrayhttps://shadow-cljs.github.io/docs/UsersGuide.html#compiler-options

👍 1
henryw37410:02:03

I think you must be pulling in an older version bc cljc.java-time:0.1.18 was released to address this issue ( goog.object is explicitly required)

xceno10:02:29

huh, fair enough. sorry for the confusion. I just realized it's even stated in the commit message of fulcro here: https://github.com/fulcrologic/fulcro-rad/commit/d0bd026afc4a3281294cbb952c141d2d8762337b. Maybe something else is overriding this with an older version, I'll check the dependency tree

henryw37410:02:56

no worries. probably the first time cljs upgrade causes such issues. and hopefully last

xceno11:02:25

well, you were totally right. even though the latest fulcro-rad pulls in cljc-java-time 0.1.18 it doesn't end up in my classpath. so the old version is still there. Guess I try to wipe the .m2 cache and see if that makes a difference

p-himik11:02:00

Better yet, inspect a proper dependency tree and see what overrides the dependency. If you're using deps.edn, you can use clj with -Stree or, if that doesn't give enough details, with -Strace and check the resulting trace.edn. Also, clj has its own cache - it's more likely to blame than ~/.m2, unless someone replaced some artifact without changing the version or you yourself put something in .m2, maybe via some tool.

xceno11:02:07

Yeah, I'm on it, .m2 wasn't to blame. I see in my trace.edn the same thing as in the picture above, the latest fulcro-rad pulls in the wrong/old java-time for some reason. So .cpcache in my project is my next target. Thanks for your help guys, this is getting weird

p-himik11:02:52

I think it's an issue with fulcro-rad. Compare this line: https://github.com/fulcrologic/fulcro-rad/blob/develop/deps.edn#L12 to this line: https://github.com/fulcrologic/fulcro-rad/blob/develop/pom.xml#L119 In other words, they didn't regenerate their pom.xml after changing deps.edn. Feel free to submit an issue to their repo. :)

xceno11:02:16

well, deleting .cpcache didn't do anything as well. So i guess the issue is somewhere else

xceno11:02:33

Ah damn, i didn't notice @U2FRKM4TW, that must be it!

p-himik11:02:37

(I assume that pom.xml takes precedence over deps.edn when you use tools.deps - I don't actually know that for sure)

xceno12:02:27

Finally! Updating the pom.xml in a local fork of fulcro-rad fixed it. Now the correct version is pulled in. So yes, the pom.xml takes precedence over a deps.edn . (I just found it mentioned here for Local jar attributes: https://clojure.org/reference/deps_and_cli#_dependencies) What a journey, I learned a lot today

p-himik12:02:03

As a guess - if you use git coords, perhaps the pom file is not used. Unless fulcro-rad has some necessary build process, you could try that instead of having to use a local fork.

xceno16:02:47

I made a small PR with the updated pom and it's already released :) But I'll try the git cords, cause now I'm curious! Thanks again for your help, and sorry again to @U051B9FU1 for jumping to conclusions at first

🎉 1
henryw37416:02:45

hey no worries. glad you got it sorted

javahippie12:02:39

Hi! We are using lambdaisland/fetch (https://github.com/lambdaisland/fetch) to send HTTP Requests from a React Native App. We have custom Transit Handlers for some formats, but if I read the code correctly, there is no way of adding them to the cljs lib, is there?

(def transit-json-writer
  (delay (transit/writer :json)))
imho the custom handlers would be passed as the second parameter to transit/writer. https://github.com/lambdaisland/fetch/blob/f63858363816069b9e6208e0a7e43366edd8e0d2/src/lambdaisland/fetch.cljs#L34 Can you think of any workaround, or a different CLJS library that uses js/fetch as a HTTP client?

oxalorg (Mitesh)12:02:54

IIRC all option you pass to the request will be passed along to transit/writer

🙌 1
oxalorg (Mitesh)12:02:22

Try doing that, it should mostly work!

oxalorg (Mitesh)12:02:13

If not, please create an issue and I'll be happ y to look into it 🙂

javahippie12:02:39

That was quick 🙂 We will try that, thanks!

javahippie12:02:17

From looking at the code, I get that if in the opts there is no value for the key `:transit-json-writer `, it uses the default writer I linked, else you can provide your own. Still validating, but looking good, thanks again!

💯 1
oxalorg (Mitesh)12:02:37

Yeah just checked the code, to be more precise: pass in your custom transit-json-writer in the request body like a key :transit-json-writer (t/writer :json {:handlers....}

👍 1
oxalorg (Mitesh)12:02:18

I'll add it to the docs thanks!

👍 1
Paul Hempel12:02:44

Awesome 🙂

1
Alex Miller (Clojure team)14:02:17

fyi, there is now a #transit channel ...

👍 2
javahippie14:02:59

Already joined 😉

Paul Hempel19:02:37

Btw. Your solution worked for us Mitesh like a charm. After some fixes and learning on our side. Thanks ✌️:skin-tone-3:

💚 1
oxalorg (Mitesh)20:02:18

Glad to hear that! bowtie nyantocat

fogus (Clojure Team)14:02:00

If I want to point someone to an online CLJS REPL, is https://clojurescript.io the one that I should point to?

p-himik14:02:33

I would look for a more recent one. That one uses a quite old version of CLJS:

cljs.user=> *clojurescript-version*
"1.8.40"

p-himik14:02:09

With that being said, I couldn't really find one...

p-himik15:02:09

Actually, if you aren't in a hurry, I might deploy one soon, assuming the process isn't too rough.

isak15:02:08

I've used this one: http://app.klipse.tech/ (It is on version "1.10.520")

isak15:02:50

I guess that isn't a REPL though

p-himik17:02:41

Oh, it uses 1.10.520. Neat, thanks!

borkdude17:02:11

This is a REPL that runs interpreted CLJS via SCI: https://babashka.org/xterm-sci/ So not the official one, hopefully still cool. Just updated to the latest shadow release.

👍 1
p-himik21:02:13

Just published a self-hosted ClojureScript 1.10.914 REPL at https://cljs.io/ by updating the dependencies of https://clojurescript.io/ and changing a few things there. My first attempt at self-hosted CLJS, so please do tell if something doesn't work.

👍 7
🎉 9
1
Drew Verlee17:02:09

how would you add a feature that required routing that was only known at runtime? That is, when the browser loads, the server is going to need to inform the browser client of some set of routes? I assume this means making the routing state full through the use of an atom and then updating it. Does it make sense to store that state in something like a reagent atom? In the re-frame database? What have people done in the past?

p-himik17:02:12

Two ways: • Request the routes with AJAX • Embed the routes in a static resource that you serve - I usually use some <meta> or <script type="text/transit+json"> in my index.html for that, which I later read in CLJS code Regarding where to store it - unless the routes change after you have set them up, I don't think you need to store them. Just get them and set them up like you do it usually.

👀 1
achikin18:02:46

Are there any ready made components that visualize clojure data structures, allow to filter them, fold/unfold and etc.?

p-himik18:02:50

I would look at how other projects do it, like djblue/portal, re-frisk, cjls-devtools, re-frame-10x,...

achikin18:02:06

@U2FRKM4TW thank you, portal looks great

👍 1
p-himik19:02:16

Is there an obvious reason for why things like defn, def, fn are not available in a self-hosted CLJS?

thheller19:02:24

cljs.core analyzer data not loaded?

p-himik19:02:40

Is that the one in core.cljs.cache.aot.json? Should be loaded, let me check.

p-himik19:02:14

There's data that looks like this.

p-himik19:02:01

And the original data in the core.cljs.cache.aot.edn doesn't have a mention of defn.

p-himik19:02:17

To give more details - I'm trying to port the code of to a modern version of ClojureScript. Originally, it uses Boot with some ancient plugins, so I decided to also migrate it to shadow-cljs. Given that the REPL there is the source of CLJS code, it sounds like a :target :bootstrap build is not needed. And everything seems to be buildable with just :target :browser.

thheller19:02:09

what gave you that impression? :target :bootstrap AND :browser are both most definitely needed

p-himik19:02:55

Yeah, I think I misunderstood that article... Do you have any clue how the original code at https://github.com/Lambda-X/cljs-repl-web works at all then? It just extracts the core.cljs.cache.aot.edn from the CLJS jar and loads it via cljs/load-analysis-cache! in the browser. And yet stuff like defn works.

p-himik19:02:39

Alright, the method you describe in the article worked immediately, thanks. :) Still wonder why their original code works though... Maybe things were different in the age of CLJS 1.8.40.

thheller20:02:49

things are different in plain cljs yes. but it inlines cljs.core analyzer data as code which makes it about 2x larger and slower to load

thheller20:02:17

plus :bootstrap solves the issue of pre-compiling other namespaces as well. and providing the ability to access react and stuff

p-himik21:02:38

Actually, it doesn't inline it! It loads it via XHR. Having other namespaces does sound useful.

p-himik21:02:13

Just published a self-hosted ClojureScript 1.10.914 REPL at https://cljs.io/ by updating the dependencies of https://clojurescript.io/ and changing a few things there. My first attempt at self-hosted CLJS, so please do tell if something doesn't work.

👍 7
🎉 9
1