This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-22
Channels
- # beginners (240)
- # boot (23)
- # bristol-clojurians (3)
- # cider (101)
- # cljs-dev (52)
- # cljsrn (17)
- # clojure (212)
- # clojure-dusseldorf (2)
- # clojure-greece (2)
- # clojure-italy (9)
- # clojure-russia (1)
- # clojure-spec (91)
- # clojure-uk (33)
- # clojurescript (164)
- # community-development (23)
- # core-async (24)
- # core-logic (9)
- # cursive (18)
- # datavis (1)
- # datomic (119)
- # emacs (13)
- # events (1)
- # figwheel (2)
- # fulcro (86)
- # graphql (1)
- # immutant (5)
- # jobs-discuss (6)
- # leiningen (19)
- # lumo (46)
- # nyc (7)
- # off-topic (23)
- # parinfer (15)
- # pedestal (3)
- # planck (32)
- # re-frame (48)
- # reagent (75)
- # ring-swagger (13)
- # rum (32)
- # shadow-cljs (402)
- # spacemacs (5)
- # specter (3)
- # tools-deps (11)
- # unrepl (20)
- # vim (135)
- # yada (3)
I'm venturing into using shadow-cljs. Everything seems to just work right up until I try to apply styles. Not sure how I would go about it from here.
(ns starter.browser
(:require [rum.core :as rum]
[react-native-web :as react-native :refer (View Text)]))
(rum/defc hello-world []
[:div
[Text "hello there"]
[:h3 {:style {:color "blue"}} "Edit this and watch it change!"]])
I'd like to apply style to the Text
element
@grounded_sage that shouldn’t have anything to do with shadow
Yea I've been playing around with it. Can get things to work with Reagent. It appears it's to do with React component interop with Rum
are you saying that the Text element imports and displays but it doesn’t style the way you expect?
That snippet of code works as is. However when it comes to styling I can't style it.
I never got interop to work right with rum which is why I switched to reagent, honestly. I quite liked rum otherwise. It was just never clear how to pass back and forth between react components.
When using Reagent I can do this and then it works
(def Text (r/adapt-react-class Text))
(defn app []
[:div
[Text {:style {:color "blue" :font-size "40px"}} "hello"]
Yea my preference is Rum however this is making me think otherwise 😞
as a general matter, it doesn’t make sense to do that--I assume this is some kind of react native thing
There appears to be some cache stuff going on. I'm getting old errors and code rendering that no longer exists in the file.
one thing that can catch me: make sure your stuff is compiling. sometimes the heads-up-display will disappear and your old code will just be sitting there while your existing code has a compile error
For some reason shadow-cljs is flat out not working anymore lol. Have no idea what I've done now 😛
How do you restart?
It says it is a server error
I've retried downloading the quickstart
It doesn't work. On my old one it just throws a heap of errors that no longer exist. On my reagent one no changes to the file are being reflected but it is serving it as it was before
I've just been using this from the quickstart npx shadow-cljs clj-repl
No I've stopped and started on different files
I've done a full restart of computer. This is the error I am getting on the Rum on
[:app] Build failure:
The required namespace "starter.browser" is not available.
[2018-03-22 13:31:05 - WARNING] stale websocket client, please reload client :app
[2018-03-22 13:31:23 - WARNING] stale websocket client, please reload client :app
[2018-03-22 13:31:40 - WARNING] stale websocket client, please reload client :app
the issue is that it can’t find your source code, I think. the build failure is causing all of these issues
Weird thing is that the namespace was there. Making a change in the file and saving seems to have fixed it by triggering it to recompile
I don’t really understand what’s going on. thomas is asleep so he won’t be back online for a while. actually you’re behind me so you’ll probably still be up when he gets up
Ok seems that calling [Text ....
inside the Rum one was throwing a warning in the console. But it was still rendering
@grounded_sage The required namespace "starter.browser" is not available.
is it possible your ns
form is busted?
I'm not sure what the error was. Everything seemed fine. I've actually moved past this error and am currently trying to adapt React classes to be used with Rum.
ok. I don't know anything about rum but it should work identically as in other tools. if it doesn't please let me know.
Yea rum is working and so is reagent. It's just there isn't a standard way to interop with React components in Rum. So I'm searching the web for solutions. I actually feel like I am getting somewhere with Shadow CLJS over all the other options. Thanks!'
@grounded_sage you might be able to just create the React Element directly? don't know how Rum deals with this but (:require ["react" :refer (createElement)])
then (createElement Text #js {:foo "bar"} ...)
Hi. If I add a new file and namespace in a shadow-cljs project, should that file be picked up without restarting a shadow-cljs watch
session?
I’m not really seeing this. so I have x.cli requiring x.foo that now requires x.api (this last one is new). I can’t seem to get it to try to compile this one
hmm did you require before creating the file? that might result in a situation where the worker gets stuck
it’s nodejs: The required namespace "permafrost.api" is not available, it was required by "permafrost/health.cljs".
hm. a restart of the watch has same thing. could the state be messed up in .shadow-cljs ?
just to be sure you have a src/permafrost/api.cljs
directly next to src/permafrost/health.cljs
?
» ll src/cljs/permafrost/api.clj src/cljs/permafrost/health.cljs 09:32:53
Permissions Size User Group Date Modified Name
.rw-r--r-- 704 sundbp staff 22 Mar 9:28 src/cljs/permafrost/api.clj
.rw-r--r-- 1.6Ki sundbp staff 22 Mar 9:21 src/cljs/permafrost/health.cljs
[:pf] Build failure:
The required namespace "permafrost.api" is not available, it was required by "permafrost/health.cljs".
[:pf] Compiling ...
[:pf] Build completed. (168 files, 59 compiled, 0 warnings, 42.48s)
[:browser] Build failure:
The required namespace "demo.run-test" is not available, it was required by "demo/browser.cljs".
"demo/run_test.clj" was found on the classpath. Should this be a .cljs file?
Does shadow cljs do dead code elimination? I feel like I am accumulating too many libraries just for small pieces of functionality.
Ok cool.
Is it possible to do something like this?
Rum will call sablono.compiler/compile-html in its macro. You could add a sablono.compiler namespace (a .clj file) into your project and create a compile-html function which calls Hicada with the config you like. This namespace will take precedence over any CLJ namespace on your classpath.
I feel like I am muddying the waters a lot here lol. I would love it if I could just somehow use React Native Web with Rum library and be able to have it all built in Node on Netlify xD
I feel like I need to get my Clojure foo a lot better and hack my own version of Rum together 😕
The problem is Rum uses Sablono internally. Which doesn't work with self hosted.
(html/div
(html-section-header (name build-id))
(html/div
(html/button
{:onClick #(conv/transact! this (watch-start! build-id))
:disabled (any? worker)}
"watch start")
(html/button
{:onClick #(conv/transact! this (watch-stop! build-id))
:disabled (nil? worker)}
"watch stop")
(html/button {:onClick #(conv/transact! this (db/compile! build-id))} "compile")
(html/button {:onClick #(conv/transact! this (db/release! build-id))} "release"))
(html/pre {:ref (::dom-ref this)}
(with-out-str
(pprint data))))
React native for web uses View
Text
TouchableOpacity
etc
Hmm i see. So shadow has markup etc.
the point is to call functions instead of this hiccup-ish datastructure that needs to be compiled to be performant
Exception: No namespace: sablono.core found
clojure.core/the-ns (core.clj:4128)
clojure.core/ns-publics (core.clj:4155)
clojure.core/ns-publics (core.clj:4155)
shadow.build.macros/find-macros-in-ns (macros.clj:32)
shadow.build.macros/find-macros-in-ns (macros.clj:30)
That was when I attempted to overwrite the sablono.compiler using Hicada
But in all honesty I'm really looking a solution I can run entirely in one VM be is JVM or Node so that I can deploy to Netlify.
Compiling
I'm kind working on creating some holy grail JAMstack solution in Clojurescript.
They have docker images with common build tools and allow others to provide build tool solutions.
So you can basically pick your build tool. Set what command is required to build it. Then point them at a github/gitlab repo.
Then any changes you push they run the build and autodeploy to global CDN
Poor mans devops
I think it is a great solution for front ends even for larger productions. You cleanly separate front and backend.
if java is available you can just run npx shadow-cljs release my-app
and then have it copy your :output-dir
to wherever?
I don't know I'm confused as I don't know enough about all the processes. I am assuming that most options with netlify would just have one option in the docker images. So like either Node, JVM/Leiningen, JVM/Boot etc
you have a repo that should run some command, create a .js file that is then copied somewhere and loaded in a webpage?
Have some kind of build process where I can output everything into some target folder (html, css, js, images, svg etc) Whilst using React Native for Web so that I can write code the same way (as close as possible) between doing a web app and native app.
ok shadow-cljs currently only supports JS and doesnt do the rest. but you can use whatever other tool you want for those
I think shadow cljs could work.
I really think my main issue is how I get Rum to come to the party lol.
FWIW (:require [shadow.markup.react :as html :refer ($)] ["react-native" :as rn :refer (Text View)])
then in render ($ Text {:style style-obj} "hello world")
I could add a shadow.markup.react-native :as rn
then (rn/text {:style ...} "foo")
would just work
Just normal React components
React Native for Web creates normal react components. https://github.com/necolas/react-native-web
It's just a way to create code that can work on React Native or React (web)
So you aren't writing View
for one codebase and Div
for the other when it's exactly the same thing visually.
yeah so the problem is getting that to work with rum? I can guarantee that the above shadow.markup example I posted will just work
Anyways this works fine in Reagent and I believe Shadow-cljs is the right tool. No point me cluttering this channel with an issue that is basically unrelated:)
I don't think Shadow.markup does it for me because it does defstyled approach. All good. I will continue plugging away at this Rum problem haha
I guess I don't understand how react-native-web
works if there code example doesn't have a single reference to react-native-web
Yea haha. Tripped me up as well. I was like WHERE IS THIS COMING FROM. haha
Well this works flawlessly
(ns starter.core
(:require [reagent.core :as r]
[react-native-web :as react-native :refer (Text View)]))
(def Text (r/adapt-react-class Text))
(def View (r/adapt-react-class View))
(defn app []
[:div
[View {:style {:background-color "red" :height "100px" :width "100px"}
:accessibility-role "main"}
[Text {:style {:color "blue" :font-size "40px"}} "hello"]].....
But that is using Reagent 🙂
I find Rum to be much nicer. Except this not working with React components is making me think otherwise haha
and in your build config :js-options {:resolve {"react-native" {:target :npm :require "react-native-web"}}}
😉
ah nice!
basically all that does is rewrite ["react-native" :as react-native :refer (Text View)]
to ["react-native-web" :as react-native :refer (Text View)]
Well at the moment it's just a learning exercise. My focus is all web but this should help me bridge that.
Yea awesome. So much better than a babel plugin haha
doesn't do anything to the reagent/rum situation but might make things cleaner if you actually have a second build for a RN app
cheers
Ah now I see where I am running up against. I tried this ages ago which is what was causing issues I first brought up in this channel. https://github.com/tonsky/rum/issues/20#issuecomment-282471141
sablono is clj. So I was calling clj in cljs haha. So it seems all solutions would require me to do some clj if I am to use Rum.
Not quite sure whether this could solve my problem but do you think I could use this https://shadow-cljs.github.io/docs/UsersGuide.html#clj-run
Just needing to run some clj to do the class adapting in Rum.
It looks like if I could use sablono.util and adapt them I could then just pull them in.
I'm sorry I really don't understand what you are trying to do. Do you have some code I can look at?
but no clj-run
is only meant to call clojure core directly. not as part of a build or anything.
Ah ok. Yea it probably won't work then. That comment #20
has the code I am referring to.
Thank you for your time! I think my best bet is just go with Reagent and move along. 🙂
If you create a full repo with an example of what you are trying to do I can look at it
> When you write [(.-Route js/ReactRouter) {:name "home"} ] sablono tries to parse it as tag, something of form [:div attrs & children]. > Just create component with interop syntax, e.g. (js/ReactRouter.Route #js {:name "home"}). Do not put in a vector as first element (but as child — in sablono terms — it’s ok)
I believe that is just shorthand for adapt-react-class
which Rum doesn't have as a utility built in.
seems like a pretty big issue if rum/sablono doesn't support any native react components/classes
Definitely
Ok, here goes. I’m spending part of the day trying shadow and hopefully documenting the cider setup, if I can get it working.
So, just to clarify where I left off… if I have a project with a backend serving a re-frame SPA, I’m still better off as one project, right? Even with shadow?
I’m already excited about the browser caching fix. FF drives me nuts with that sometimes, and now Chrome does it as well.
First, I’d like to fix the broken clojars link.
But I’m not sure what to do with the link to the image
Actually, the image below it
I see ‘the artifact can be found at’ and a broken image link below that.
oh you are talking about the broken images in the README? wonder why they are broken
it appears to be something on githubs end. https://img.shields.io/npm/v/shadow-cljs.svg this source link works
The original gave me a plain text error message.
its broken in the README here too https://github.com/thheller/shadow-cljs
I just added [thheller/shadow-cljs] to my project.clj, and :lein true
in shadow-cljs.edn
and then I run lein run -m shadow.cljs.devtools.cli compile
and I’m getting class not found….
I’ll dig some more
Hold on…
you should really start out without the lein integration. so much simpler to just leave lein in its own world and not mess with it
It went farther this time, not sure why…
Let’s go back to no lein…
I do have separate clj cljc and cljs files under src… hopefully that won’t bite me just yet.
ok, so I got the deps installed and the build succeeded.
I’m looking at a ‘shadow-cljs’ page with release snapshots links….
I guess I need to serve up some other assets…
if you want to get a webserver for your build you can configure it here: https://shadow-cljs.github.io/docs/UsersGuide.html#browser-http-server
Ok, so I added a line for :main :entries, but the build is not finding that namespace.
Do I need an entrypoint first?
It works under the lein build, but maybe shadow isn’t finding it?
you lein config probably has a some :source-paths
configured. those need to be configured in shadow-cljs.edn
as well
I’m up and running!
I had to comment out 2 npm react components… I’ll get to that part next.
Once I import those components successfully, do I use the [:> foo]
notation for Reagent component creation?
So here’s what I’m seeing when I load my page with the react components I’ve imported…
GET
And there’s a whole list of other components.
And I’m also using a minified react for dev… that’s giving me a warning.
Let me turn it off
Though it’s never been an issue before.
Wait, those classes are not found in my local directory….
js/cljs-runtime/module$node_modules$….
A lot of them are, but not the 2 I required.
Well, some other things might… but I did discover that neither of these 2 components are in the manifest.edn.
Though the react components and many others are.
First of all, I’m removing code related to this component, doing a hard refresh, and I’m still seeing warnings related to it in the code. The page refuses to render. After a trivial change and hot reload, the page renders (with the components disabled)
But there’s a handful of components that are not in the manifest, but are required by the 2 that I need. And of course, those 2 are missing as well.
But they are in the package.json.
hold on..
package.json doesn't matter .. only thing that matters is things you actually reference in your code
ok. I built your project, and it works. Thanks for that. I see differences in versions, so I bumped mine up, and everything broke.
it is absolutely possible that your node_modules
directory is messed up. npm does that frequently.
I’m reverting to my versions, and I’m going to try that. Then I’ll revert yours to the same as mine, and try that
I just blew that away and reinstalled. Let’s see how far I get…
just in case you should kill the shadow-cljs process and delete the .shadow-cljs/builds
directory
I was about to ask how to clean
So the manifest (and cljs-runtime dir) still does not have the modules I need
I don’t get it….
Hold on…
Pretty sure…
The path is… public/js/cljs-runtime/
I'm still suspicious about the NET_ABORTED
. that is usually caused by some browser extension.
ok, problem solved. All my fault, lol.
I tried to make my shadow config mirror my lein cljs-build config, and I got them out of sync. So the build directories were incorrect.
I tremendously appreciate the time you took to whip up that demo. That helped me narrow it down.
Did you see my PR for cider docs? 😁
i just read through the whole user guide and one thing I didnt see mentioned was devdependencies. in lein, for example, I can specify a dev profile that has its own dependencies for things like binaryage/devtools
and piggieback
. how does shadowcljs handle this scenario?
doesn't have to. the builds control what is used. having :dependencies
on the classpath does not affect what a build does.
Is there a way to use a debug React build, or else squash the warning I see in the console? @thheller
note that it will probably get support for this at some point because it becomes relevant when packaging libraries
@jmckitrick the warning is a bit annoying yes but unfortunately no. everything is correct though. it just complains because it doesn't understand what shadow-cljs is doing. still need to bug the react people about their bad detection method
Not a problem.
shadow-cljs release
will use their proper release version so the warning will go away then
Now that I have this working, I’m wondering if I should try lein
integration…
is there a way to suppress warnings that stem from not-my-code? for example, something requires cuerdas and cuerdas uses NaN
instead of js/NaN
but in general, is there a way to make these disappear? I don’t really know who is requiring some of these transitive deps, and I really dont want to do manual one-off updates and pray that I dont break some api, ya know?
since figwheel and other tools only show warnings once they tend to get ignored and forgotten
i see your premise, but if the third-party code is out of my control it will be incredibly annoying to have those warnings always visible and obfuscating issues within my own app code
I do see your point. I'll think about it. Maybe just not repeat the warnings on recompile, just show them once on watch start or so.
So I’ve just converted a colleague (at a different shop) to shadow-cljs. But he’s asking if there’s a way to alias ‘preact’ as a replacement for ‘react’ and ‘react-dom’ dependencies.
Perfect. I knew I saw something like that somewhere. Let me give it a shot…
Correct.
‘preact-compat’
resolve: {
alias: {
'react': 'preact-compat',
'react-dom': 'preact-compat',
// Not necessary unless you consume a module using `createClass`
'create-react-class': 'preact-compat/lib/create-react-class'
}
}
:js-options
{:resolve
{"react" {:target :npm :require "preact-compat"}
"react-dom" {:target :npm :require "preact-compat"}}}
I’m running it now… fingers crossed
@jmckitrick there might be a cache issue. I don't think :resolve
currently invalidates the cache
Ok… I’m seeing errors, yes.
so blow away .shadow-cljs/builds?
I’m seeing an error message about forceUpdate
@kanwei blow away your .shadow-cljs/builds directory
I did not.. let’s see…
:js-options
{:resolve
{"react" {:target :npm :require "preact-compat"}
"react-dom" {:target :npm :require "preact-compat"}
"create-react-class" {:target :npm :require "preact-compat/lib/create-react-class"}}}
I’m up and running!
2. I'm struggling to understand why the advanced compiled files are so much smaller than boot-cljs
so the problem with as I outlined here https://code.thheller.com/blog/shadow-cljs/2017/09/15/js-dependencies-the-problem.html
(cljs :optimizations :advanced
:compiler-options {:output-wrapper true
:pseudo-names true
:pretty-print true})
I rely on closure :simple
removing the conditional and only leaving one of the requires
otherwise your page would load the production and dev versions. it would only use the dev version but I still don't like loading stuff I don't need
but yeah I optimize due to conditional requires .. and its basically free so why not
https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/build/closure.clj#L1831-L1847
well cljs isn't much better if you think about it. can't do conditional require either but sometimes you just want to.
every new js module proposal reminds me of https://xkcd.com/927/
:js-options {:resolve {"react" {:target :npm :require "inferno-compat"}
"react-dom" {:target :npm :require "inferno-compat"}
"create-react-class" {:target :npm :require "inferno-create-class"}}}
and copy the file above and just remove the create-react-class require and set below
(ns cljsjs.react
(:require ["react" :as react]))
(js/goog.exportSymbol "React" react)
there is no create-class reference in https://github.com/reagent-project/reagent/blob/master/src/reagent/impl/util.cljs
ah but there used to be https://github.com/reagent-project/reagent/blob/18cb1468a671f5a96a912d2e3ccc13bbdbf3a68e/src/reagent/impl/util.cljs
hmm inferno-create-class
does not export a function it exports inferno-create-class/createClass
so the :resolve
trick won't work since that differs from what create-react-class
exports
that might do it but I have never used inferno so I don't know what else is hiding in there
@thheller i seem to have gotten my shadow into a bad state. shadow-cljs server start
never returns and it doesn’t seem to finish a compile or recompile. if i kill that and do a single build, that works. i’ve already blown away .shadow-cljs
but i’m not sure where else there may be state lurking
oh sorry I guess you have to run a watch command separately in addition to the server. still it is weird that server start
does not return
Woot. Got things working. Nearly built a whole website now using React Native for Web.