This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-09
Channels
- # adventofcode (1)
- # aleph (2)
- # beginners (28)
- # boot (26)
- # boot-dev (8)
- # cider (10)
- # clara (10)
- # cljs-dev (130)
- # cljs-experience (1)
- # cljsrn (12)
- # clojure (118)
- # clojure-austin (40)
- # clojure-boston (1)
- # clojure-chicago (1)
- # clojure-dusseldorf (1)
- # clojure-estonia (11)
- # clojure-france (1)
- # clojure-greece (3)
- # clojure-italy (19)
- # clojure-nl (1)
- # clojure-russia (1)
- # clojure-spec (19)
- # clojure-uk (34)
- # clojurescript (62)
- # core-logic (7)
- # cursive (11)
- # datomic (35)
- # emacs (15)
- # fulcro (264)
- # jobs (4)
- # leiningen (5)
- # midje (4)
- # off-topic (74)
- # onyx (27)
- # planck (14)
- # protorepl (4)
- # re-frame (37)
- # reagent (62)
- # rum (2)
- # shadow-cljs (171)
- # slack-help (5)
- # spacemacs (6)
- # specter (9)
@juhoteperi what i get is React being included inline in my built JS file, and if I put react
and react-dom
in :exclusions
, it fails to compile not finding the namespace
if i use the empty-namespace trick that worked in 0.7.0, i get an artifact which doesn't actually refer to React
anywhere
Are you trying to use React from CDN?
Tricky, I think you can do this by overriding the foreign-lib entry from Cljsjs.
Try adding this to compiler-options:
:foreign-libs
[{:file "empty.js",
:provides ["react" "react-dom" "create-react-class"],
:requires [],
:global-exports '{react React, react-dom ReactDOM, create-react-class createReactClass}}]
that whould point all the namespaces required by Reagent to empty file, and create the mapping from namespace to the global vars provided by the bundle
and if I recall correctly, this hopefully overrides the foreign-libs from Cljsjs with same provides
problem with the empty namespaces is that foreign libs and node modules currently take precedence over Cljs namespaces... which might be wrong but that's how Cljs is currently implemented
still getting an error - do i need to actually create that empty.js and put it alongside project.clj?
oh and empty namespaces aren't quite enough because Reagent now uses React "like it were real namespace"
yeah, if i turn of advanced optimisations i can see it producing var react = {};
and then failing to find everything
@alex339 Yes, you'll need the empty file, in project.clj you shouldn't use '
and you need to add ReactDOMServer if you use reagent.dom.server
ok, this is weird. if i add the empty.js, i get
clojure.lang.ExceptionInfo: failed compiling file:target/cljsbuild-compiler-1/reagent/impl/component.cljs {:file #object[java.io.File 0x2464490e "target/cljsbuild-compiler-1/reagent/impl/component.cljs"]}
...<stacktrace>...
Caused by: java.lang.IllegalArgumentException: contains? not supported on type: clojure.lang.PersistentList
I have some problems with Figwheel testing this, but the output looks correct
remove '
before the hash-map if you still have tha
yeah, it is required if calling cljs-build-api/build from Clojure code, but not in project.clj as that is data not code
ahh! this seems to have nearly done it - however the lines like these don't survive advanced optimisations:
reagent.impl.component.global$module$react = goog.global.React;
It should keep the .React part? other names can be changed
Have you excluded Cljsjs deps? Those are needed to provide the externs
ah yes, i did - but if i don't exclude them, then the compiled artifact includes React inline, which is what i'm trying to avoid. š
No, adding this foreign-libs entry should override the files from Cljsjs but allow using the externs
gotta pack it in for today, thanks for your help @juhoteperi
@alex339 I extended this document to mention this environment: https://github.com/reagent-project/reagent/blob/master/docs/0.8-upgrade.md I'll try to get the config working myself later
this might be more of a reactjs question in general, but here goes! i have a fairly complex table component (reagent powered by re-frame) that does lots of things including io in the background. i have to show this component about 30 times on a report page and when i do it completely chokes the browser for a few seconds. is there a way to solve this problem internally rather than hiding tables until they're in view? maybe something to do with reagent.core/flush?
Sounds like you are creating a lot of new DOM
30 x tables
If so, I'd guess that creating all that DOM will be what's slow
Perhaps you might want to use the still-experimental re-frame-trace
. Maybe.
thanks, @mikethompson. i'm pretty sure you're right - there are loads of elements that end up trying to be painted at once. i wasn't sure if adding ^:flush-dom
to the event that stores the table data for viewing would help (about to test), but i have a feeling i'm barking up the wrong tree. i'll check out re-frame-trace
and see where it takes me.
@joshkh If the problem turns out to be actual dom performance, you can checkout the react virtualized library, which is an incredibly sophisticated library and is designed to solve just this kind of problem. Note, it takes some doing to get it integrated into your project, but it does work as advertised.
i'll check it out @lee.justin.m! thanks for the tip, i hadn't heard of it before now.
are there any up-to-date documentation on getting server side rendering working for reagent?
I really just want to get a node.js server up that runs (reagent.dom.server/render-to-string)
so far even just trying to require
reagent.core.server into a node.js application causes it to fail to build
That seems weird - I haven't tried it but I would expect it to work. Hopefully someone with some experience running it on node will come by and help.
so far even just trying to require
reagent.core.server into a node.js application causes it to fail to build
now Iām getting āorg.mozilla.javascript.EcmaError: TypeError: Cannot read property ārenderToStringā from undefined (rhino.clj#41)ā in the REPL
cljs.user> (reagent.dom.server/render-to-string [:div "Hello"])
org.mozilla.javascript.EcmaError: TypeError: Cannot read property "renderToString" from undefined (rhino.clj#41)
when I deploy it to AWS Lambda (which is adding an additional boatload of complexity to this), I get the error Unable to import module 'index': Error
@lilactown I don't have time to help now, but Reagent uses prerendering itself to build the demo site: https://github.com/reagent-project/reagent/blob/master/build-example-site.sh#L16-L18 https://github.com/reagent-project/reagent/blob/master/project.clj#L71 https://github.com/reagent-project/reagent/blob/master/demo/sitetools/prerender.cljs
Reagent uses Node, not Rhino
same thing in Node.js
cljs.user=> (reagent.dom.server/render-to-string [:div "hello"])
repl:13
throw e__8630__auto__;
^
TypeError: Cannot read property 'renderToString' of undefined
at reagent$dom$server$render_to_string (/Users/r627543/Code/fido/packages/functions/example/.cljs_node_repl/reagent/dom/server.js:22:62)