Fork me on GitHub
#reagent
<
2020-08-04
>
Hobgoblin08:08:48

Hello, I'm porting existing TSX code to CLJS and while mostly successful it seems I have a hard time writing this """<Route exact path="/" render={() => <Redirect to="/home" />} />""" in CLJS. I have already tried the following:

Hobgoblin08:08:06

[Route {:path "/" :render #(r/reactify-component [Redirect {:from "/" :to "/home"}]) :exact true}] [Route {:path "/" :render (fn [_] [:> js/Redirect {:to "/home"}]) :exact true}]]]])) [Route {:path "/" :render (fn [_] (r/reactify-component [#'react-router-dom/Redirect {:to "/home"}])) :exact true}] [Route {:path "/" :render (fn [_] [RootRedirectDerivedFromRedirect {:to "/home"}]) :exact true}] [:> react-router-dom/Route {:path "/" :render #([:> react-router-dom/Redirect {:to "/home"}]) :exact true}] [:> react-router-dom/Route {:path "/" :render (fn [_] [:> react-router-dom/Redirect {:to "/home"}]) :exact true}]

Hobgoblin08:08:20

at the same time this seems to work just fine

Hobgoblin08:08:32

[Route {:path "/home" :component (r/reactify-component Home) :exact true}]

Hobgoblin08:08:22

I have required ["react-router-dom" :as react-router-dom]

Hobgoblin08:08:39

and defined the following

Hobgoblin08:08:40

(def Redirect (r/adapt-react-class react-router-dom/Redirect)) (def Route (r/adapt-react-class react-router-dom/Route))

arttuka09:08:14

:render #(r/as-element [Redirect {:to "/home"}])

arttuka09:08:43

or :render #(r/as-element [:> Redirect {:to "/home"}]) if Redirect is a React component (and not a Reagent component)

EmmanuelOga09:08:59

not sure if the docs on teh doc/ folder are supposed to be deprecated or something

EmmanuelOga09:08:41

I wish someone knowledgeable would tidy up these docs 😞 Maybe in celebration of 1.0? 🙂

jsn10:08:12

It actually works for me even with reagent 0.10.0

jsn10:08:27

I'm having trouble coming up with an interpretation of "Appendix 2" that would not be hopelessly incorrect (but then again, I don't know much about Reagent)

EmmanuelOga06:08:12

yeah I feel some of the docs are just outdated, thing is, when learning, it is hard to determine which thing is wrong

jsn09:08:38

Well, my guess would be that that specific one at least is not just outdated, it seems just plain wrong (as in: I have doubts Reagent ever behaved that way).

EmmanuelOga23:08:15

right, I meant, maybe it was correct at some point, otherwise it would not had been written (I want to think) haha

EmmanuelOga23:08:48

would be awesome to have some sort of build for the docs: if you use a piece of code as an example, should be extracted from a test suite or something

EmmanuelOga23:08:04

maybe once I learn the thing I should try doing something like that 🙂

Hobgoblin13:08:21

@arttuka that worked. thx man!

andrea.crotti15:08:24

has anyone seen this error before?

[Figwheel] figwheel-main.edn is valid \(ツ)/
[Figwheel] Compiling build dev to "resources/public/cljs-out/dev-main.js"
internal/modules/cjs/loader.js:1088
  throw err;
  ^

Error: Cannot find module '@cljs-oss/module-deps'
Require stack:
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1085:15)
    at Function.Module._load (internal/modules/cjs/loader.js:928:27)
    at Module.require (internal/modules/cjs/loader.js:1145:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at [eval]:8:13
    at Script.runInThisContext (vm.js:132:18)
    at Object.runInThisContext (vm.js:315:38)
    at Object.<anonymous> ([eval]-wrapper:10:26)
    at Module._compile (internal/modules/cjs/loader.js:1256:30)
    at evalScript (internal/process/execution.js:98:25) {
  code: 'MODULE_NOT_FOUND',

andrea.crotti15:08:32

it seems to fail when it loads react-dom

andrea.crotti15:08:43

even if the dependency is there, and it's kind of a trivial project for now

lilactown15:08:59

I’ve seen this error many times and always forget how it’s fixed

andrea.crotti15:08:06

I found some references about this online but none of them seen to apply to my project

lilactown15:08:11

what version of figwheel/cljs are you using?

andrea.crotti15:08:13

the deps are just

:dependencies [[org.clojure/clojure "1.10.0"]
                 [org.clojure/clojurescript "1.10.773"]
                 [org.clojure/core.async  "0.4.500"]
                 [cljs-ajax "0.8.0"]
                 [reagent "0.10.0"]]
and
{:dependencies [[binaryage/devtools "1.0.2"]
                                  [com.bhauman/figwheel-main "0.2.11"]]

                   ;; need to add dev source path here to get user.clj loaded
                   :source-paths ["src" "dev"]
                   ;; need to add the compiled assets to the :clean-targets
                   :clean-targets ^{:protect false} ["resources/public/cljs-out"
                                                     :target-path]}

andrea.crotti16:08:05

the error I eventually get in the browse is just

dom.cljs:16 Uncaught TypeError: Cannot read property 'render' of undefined
    at reagent$dom$render_comp (dom.cljs:16)
    at Function.cljs$core$IFn$_invoke$arity$3 (dom.cljs:41)
    at reagent$dom$render (dom.cljs:27)
    at Function.cljs$core$IFn$_invoke$arity$2 (dom.cljs:36)
    at reagent$dom$render (dom.cljs:27)
but that's simply because react-dom was not imported properly I believe

lilactown16:08:15

sure if the loader isn’t compiling and running then it’s gonna have problems

lilactown16:08:19

I would try bumping all your deps

lilactown16:08:39

and clearing your build cache

lilactown16:08:45

maybe start with that first, actually

andrea.crotti16:08:11

mm looks like disablin [binaryage/devtools "1.0.2"] makes it work

andrea.crotti16:08:29

would be good to understand why

andrea.crotti16:08:58

ah no interesting now the first error is gone but the second is still there

andrea.crotti16:08:04

it still doesn't load react-dom properly, even if I cleaned already and hard reloaded, weird

lilactown16:08:57

are you excluding cljsjs/react-dom ?

andrea.crotti16:08:11

no no it's definitively there

[reagent "1.0.0-alpha2"]
   [cljsjs/react-dom-server "16.13.0-0"]
   [cljsjs/react-dom "16.13.0-0"]
   [cljsjs/react "16.13.0-0"]

andrea.crotti16:08:36

and I can see the react js file being fetched correctly in the network tab

lilactown16:08:57

probably worth asking in #figwheel-main

lilactown16:08:19

doesn’t sound like it’s a reagent problem tbh

lilactown16:08:41

I would investigate your build config

andrea.crotti16:08:28

yeah probably let me try to change a few things