Fork me on GitHub
#shadow-cljs
<
2023-01-15
>
Itay Dreyfus12:01:32

Perhaps an obvious question - I’m using the mapbox npm package, however on saving the page doesn’t render my component only when I evaluate it on the REPL, what’s the issue here?

thheller12:01:16

"saving the page" I assume you mean saving the file?

thheller12:01:57

otherwise need more specific code examples. don't know what you are doing, so can't give specific answers

Itay Dreyfus13:01:00

Sorry for being non informative enough 😉 Basically I render a map. When saving, hot reloading shows blank page, but evaluate the code on the REPL automatically renders the map on the page. My intializers are:

(defn home-page []
  [:<>
   [items-list]
   [map-container]])

;; -------------------------
;; Initialize app

(defn mount-root []
  (d/render [home-page] (.getElementById js/document "app")))

(defn ^:export init! []
  (mount-root))

Itay Dreyfus13:01:03

the map components look like this:

(ns coffee-tlv.components.map-container
  (:require ["mapbox-gl" :as mapbox]))


(defn map-container []
  [:div#map])


(set!
  (.-accessToken mapbox)
  "pk.eyJ1IjoiaXRheWRyZSIsImEiOiJja2RlczU5bmIwcDlzMnducmVuMDQ4cWlyIn0.BSyB9nVoIsnazX2PeUyPyg")

(def tlv-map
  (new
    (.-Map mapbox)
    #js
    {:container "map",
     :style "",
     :center #js [34.79 32.07],
     :zoom 15}))

thheller17:01:58

this is not how you use non-react things with react/reagent

thheller17:01:06

look up the docs for refs

thheller17:01:08

I created this example for pdfjs a while ago https://github.com/thheller/reagent-pdfjs

thheller17:01:17

its pretty much the same for mapbox

Itay Dreyfus18:01:40

Taking a look, thanks a lot!

valtteri17:01:59

Trying to use the latest https://github.com/openlayers/openlayers from npm and getting many this kind of warnings with realease builds: > Resource: node_modules/ol/layer/Layer.js:111:20 > Parse error. name not recognized due to syntax error. .. and the release builds are thus broken. In dev-mode all is working well. I guess the error is coming from Closure and it has hard time processing OpenLayers javascript..? My shadow-cljs.edn looks like this:

{:lein     true
 :dev-http {3449 "resources/public"}
 :builds
 {:app
  {:target     :browser
   :asset-path "js/compiled"
   :output-dir "resources/public/js/compiled"
   :compiler-options
   {:infer-externs :auto}
   :dev
   {:closure-defines
    {re-frame.trace.trace-enabled? true}}
   :modules
   {:app
    {:init-fn lipas.ui.core/init}}
   :devtools
   {:after-load lipas.ui.core/mount-root
    :preloads   [devtools.preload
                 day8.re-frame-10x.preload]}}}}

valtteri17:01:54

Just tried :output-feature-set :es8 and that seems to get rid of the warnings. :thinking_face:

valtteri17:01:06

..but bundle size is now 29MB 😄 It should be ~4-5MB

valtteri17:01:26

Argh. After manually deleting all cached files and previously generated output I still get these warnings with output-feature-set :es8 . Does someone have advice what to try next?

valtteri17:01:40

Ha! Among the aforementioned warnings there was also a single extern problem that caused the release build to blow up. I guess those errors from Closure don’t matter 🤷

valtteri18:01:57

Ok, I did more methodological tests and following seems to be the case • “Parse error. name not recognized due to syntax error.” happens when outputting < :es8 • With :es8 I don’t see the errors and my build & app works ◦ I had an unrelated extern problem which I was able to fix Last question is that are there any known problems with es8 as output feature set? I mean other than “doesn’t work with IE11". 😉

valtteri18:01:44

I checked from analytics and during past 3 months we’ve had one (1) IE11 visitor. Maybe the World is ready for es8..?

valtteri18:01:11

Also, thanks for shadow Thomas! I just migrated my main project from good old lein-figwheel + webpack and it’s been a joy to work with shadow. 🙏

👍 2
thheller18:01:52

not sure what would cause this error but in the past the closure compiler had issues processing some @ directives in comment blocks. the files from OL seem to be full of them. I'm guessing it has some issues with this

/***
     * @type {LayerOnSignature<import("../events").EventsKey>}
     */

thheller18:01:13

unsure how es8 is related to any of this though

valtteri18:01:33

Oh, interesting. Could be that my testing wasn’t methodological enough. 😅 I’ll try one more time with default :output-feature-set

thheller18:01:51

the default is :es2020, so dunno why downgrading fixes anything 😛

thheller18:01:08

but maybe it does something "more" that it otherwise doesn't

valtteri18:01:10

Ah 😄 Ok I had completely wrong assumption

valtteri18:01:20

I thought it was ES5 or something

valtteri18:01:39

But I’m probably remembering how CLJS is complied through Closure

thheller18:01:59

es5 is the default in regular CLJS, not in shadow-cljs

thheller18:01:11

doesn't feel right so use es5 in 2023 😛

valtteri18:01:24

I see. 😄 I should maybe just RTFM

thheller18:01:10

everything compiles just fine for me importing ol/layer/Layer

valtteri18:01:11

In the docs there’s > By default the generated JS output will be compatible with ES6 and all “newer” features will be transpiled to compatible code using polyfills. probably outdated?

thheller18:01:24

yeah outdated

valtteri18:01:09

I also upgraded shadow from 2.20.15 => 2.20.20 in the process. Dunno if this could explain some of the wierdness

thheller18:01:50

possible. that included a new closure compiler version.

valtteri18:01:59

Anyway, now it’s working and my code is running happily in production. 🙂 Thanks!

👍 2