Fork me on GitHub
#shadow-cljs
<
2022-10-04
>
barrell18:10:09

I’m using shadow.lazy/loadable to lazily load some modules. If I naviagte to the page localhost:4000/utils, it will properly load localhost:4000/js/routes.utils.js. If I navigate to localhost:4000/utils/example, it is failing to load because it’s looking for the file at localhost:4000/utils/js/routes.utils.js. I have asset path configured to /js - how do I configure the equivalent for lazily loaded modules?

thheller18:10:20

you sure you haven't configured it to js? it should be using the :asset-path "/js" if actually set like that

thheller19:10:47

should be fine

thheller19:10:00

how are you using the loader?

barrell19:10:45

(defn component [loadable]
  (let [lazy (react/lazy 
               #(-> (lazy/load loadable)
                    (.then (partial to-hot-react-component loadable))))]
    (fn [& props]
      (react/createElement lazy #js {:props props}))))

(defn get-lazy [namespace]
  `(captain.util.lazy/component (shadow.lazy/loadable ~namespace))))

thheller19:10:40

do you manually touch something from the shadow.loader ns somewhere?

barrell19:10:54

no - the only instance of loader in my codebase is :module-loader true in the config

thheller19:10:47

then I don't know. the behavior you described points to :asset-path "js", "/js" shouldn't do this

thheller19:10:44

maybe you have a service worker? or some bad cache?

barrell19:10:45

No service workers on this project yet, I reset shadow-cljs and ran it in a different browser and it’s the same problem

barrell19:10:08

Do you know which module builds the path from the module name? I’ll take a look but that could save some time hehe

thheller19:10:24

you can just look at the generated source and look for shadow$modules

thheller19:10:50

from your main module

barrell19:10:54

very weird. In my build directory, there is the expected structure. My console is somehow showing a bunch of sources available under /utils :thinking_face:

barrell19:10:05

$ tree build

build
├── 1664911033746
│   ├── captain.css
│   └── js
│       ├── captain.docs.routes.about.js
│       ├── captain.docs.routes.about.me.js
│       ├── captain.docs.routes.index.js
│       ├── captain.docs.routes.utils.$util.js
│       ├── captain.docs.routes.utils.index.js
│       ├── captain.docs.routes.utils.js
│       ├── captain.js
│       ├── cljs-runtime
│       │   ├── applied_science.js_interop.impl.js
│       │   ├── applied_science.js_interop.impl.js.map
│       │   ├── applied_science.js_interop.js
│       │   ├── applied_science.js_interop.js.map
│       │   ├── captain.app.js
│       │   ├── captain.app.js.map
..................................
│       │   ├── shadow.util.js
│       │   └── shadow.util.js.map
│       ├── manifest.edn
│       ├── module-loader.edn
│       ├── module-loader.json
│       ├── quartermaster.js
│       └── shared.js
├── index.html
└── index.html.clj

3 directories, 859 files

barrell19:10:30

does that make any sense to you? haha

barrell19:10:46

Oh. I think I know what I may have done. The asset path might be being overrun somewhere in the versioning pipeline facepalm

barrell19:10:34

Fixed! Thanks for asserting it was from asset-path, I would have been chasing ghosts for hours 😂 Still no idea how the browser was loading those files though? :thinking_face: but not important, it’s working!