shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
currentoor 2020-10-12T15:15:59.383800Z

Has anyone used apollo client with shadow-cljs? Or does lack of webpack prevent that from working.

thheller 2020-10-12T15:23:35.384100Z

does it explicitely depend on webpack?

zilti 2020-10-12T15:40:45.385200Z

Are there really libs that actually do? I've seen some libs that claim to require webpack (by mentioning it as part of their install) but none of these actually did. Actually depending on it sounds like terrible design...

thheller 2020-10-12T16:01:48.385600Z

some are rather webpack specific yes but not that common in popular libs

flyboarder 2020-10-12T17:51:29.386300Z

Anyone using dynamic loading (shadow.loader) with or without shadow.lazy?

thheller 2020-10-12T17:53:33.386500Z

I do

flyboarder 2020-10-12T17:54:59.387600Z

I have a module with an init-fn that fn loads a module dynamically, but im having issues calling things from the loaded module

flyboarder 2020-10-12T17:56:07.388400Z

:module-loader true
:modules {:base   {:entries [app.debug app.auth]}
          :common {:entries [app.index]
                   :depends-on #{:base}}
          :app {:init-fn app.main/init!
                :depends-on #{:common}}
          :cloud {:entries [app.main.cloud]
                  :depends-on #{:app}}}

thheller 2020-10-12T17:57:37.389100Z

I'm assuming this doesn't actually say :cloud {:entities?

flyboarder 2020-10-12T17:58:45.389500Z

that could very well be a typo

flyboarder 2020-10-12T17:58:54.389700Z

I was tired lastngiht

flyboarder 2020-10-12T17:59:31.390Z

I had that module as an init-fn as well as a test

flyboarder 2020-10-12T18:00:32.390600Z

when using it as an init-fn it loaded - but I got a whole bunch of errors that things were already declared

flyboarder 2020-10-12T18:02:58.391Z

;; app/main.cljs
(defn init! []
  (loader/with-module :cloud
    (fn []
      (let [cloud (resolve 'app.main.cloud/dashboard)]
        (cloud)))))

flyboarder 2020-10-12T18:03:27.391500Z

failed to load clojure.set.js Error: Namespace "clojure.set" already declared.

thheller 2020-10-12T18:08:09.393Z

hmm don't use with-module?

thheller 2020-10-12T18:08:38.393500Z

(-> (loader/load :cloud) (.then (fn [] ...))

thheller 2020-10-12T18:09:28.393800Z

I can't remember what with-module is for

thheller 2020-10-12T18:09:54.394400Z

also just use shadow.lazy. much better API and doesn't involve dealing with resolve issues

flyboarder 2020-10-12T18:09:56.394600Z

Ideally I want to use shadow.lazy but It couldnt find the modules

thheller 2020-10-12T18:10:31.395400Z

what does that mean?

flyboarder 2020-10-12T18:10:35.395600Z

when I give it the symbol the compiler throws an error about not finding the app.main.cloud module

flyboarder 2020-10-12T18:10:48.395800Z

to the loadable

flyboarder 2020-10-12T18:12:50.396400Z

(def components
  (lazy/loadable {:cloud app.main.cloud/dashboard)})

(defn init! []
  (-> (lazy/load components)
      (.then
        (fn [{:keys [cloud]}]
            (cloud)))))

thheller 2020-10-12T18:13:22.397Z

well if you actually had the typo from earlier that may have been the cause?

thheller 2020-10-12T18:13:42.397400Z

I mean if the ns isn't actually included in the build?

flyboarder 2020-10-12T18:17:33.398100Z

So the block above does work, but I still get the same console errors

flyboarder 2020-10-12T18:18:10.398600Z

ill check the manifest again

thheller 2020-10-12T18:20:04.399200Z

also note that if you are loading the module directly on init it would be better to have your HTML load it immediately instead

thheller 2020-10-12T18:20:35.399700Z

but otherwise this looks fine

flyboarder 2020-10-12T18:20:44.399900Z

base.js:2226 failed to load goog.dom.inputtype.js Error: Namespace "goog.dom.InputType" already declared.

flyboarder 2020-10-12T18:22:06.400600Z

is the depends-on correct? should the dynamic modules “depend” on the main loader module, or the other way around?

flyboarder 2020-10-12T18:22:35.400900Z

this seems to be thrown by the dynamic module

thheller 2020-10-12T18:24:19.401900Z

try triggering the load via some kind of async delay

thheller 2020-10-12T18:24:46.402200Z

(js/setTimeout (fn [] _here_ ) 0) or so

thheller 2020-10-12T18:24:59.402400Z

maybe its a race condition

flyboarder 2020-10-12T18:31:17.403Z

ok so i reduced the number of them by removing the module from the index file

thheller 2020-10-12T18:32:51.403400Z

don't know what that means

flyboarder 2020-10-12T18:33:13.403700Z

<!doctype html>
&lt;html&gt;
&lt;body&gt;
&lt;script src="./client/base.js"&gt;&lt;/script&gt;
&lt;script src="./client/common.js"&gt;&lt;/script&gt;
&lt;script src="./client/app.js"&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

flyboarder 2020-10-12T18:33:16.403900Z

thats the index file

flyboarder 2020-10-12T18:33:26.404200Z

I had the cloud.js in there

thheller 2020-10-12T18:34:28.404600Z

ah yeah if you do that you definitely need the timeout

thheller 2020-10-12T18:34:33.404800Z

otherwise it triggers the load twice

flyboarder 2020-10-12T18:35:05.405400Z

so im still getting some of them

thheller 2020-10-12T18:35:31.406Z

I don't like that you have ./client as the path. much more predictable if you use absolute paths with the proper absolute :asset-path as well

flyboarder 2020-10-12T18:35:54.406500Z

yeah thats an issue with the kubernetes ingress

thheller 2020-10-12T18:35:58.406600Z

but besides that I don't have enough information to help

thheller 2020-10-12T18:36:32.406900Z

it all looks fine from here

flyboarder 2020-10-12T18:44:49.407300Z

ok good to know im at least kinda understanding this 😅

flyboarder 2020-10-12T18:54:55.408Z

doing it with the lazy block as above seems to be working now, could very well have been a typo causing the issue with it last night