Fork me on GitHub
#fulcro
<
2021-11-30
>
roklenarcic09:11:34

I am trying to release a client-only fulcro app, and the main problem I’m having is that routing changes browser URL and then hitting refresh doesn’t work (because the static content serving server doesn’t know what to do with that URL and to serve index.html in all cases). Is there some way around it?

Markus Hain10:11:25

You could implement hash-based routing. Anything that appears after # in the URL is ignored by the server. http://my-app.com/#/user/3 becomes http://my-app.com/ on the server and then the route can be applied on the client. You only need to change the two functions that parse and create the URL.

1
tony.kay17:11:44

You could also set your “error” page to have the content of index.html

zeitstein13:12:25

Can't find any info on how to set up such a page, @U0CKQ19AQ. Little more info, please?

tony.kay17:12:24

You have to make the serving server of your content server YOUR index.html for routes that are not found.

zeitstein10:12:05

Client-only, so using shadow's basic server. I guess I'll deal with this when I get to the server part. Heads up for anybody looking to implement hash-based routing – the library pushy doesn't support hash-based urls.

roklenarcic22:12:26

@U0CKQ19AQ I am hosting the compiled page as index.html + main.js on github pages, so I cannot (I think) really do that

tony.kay22:12:06

then you also cannot use path based routing, and will have to write a hash-based thing for yourself

tony.kay22:12:28

it’s not a terribly lot of code…this is why the system is so pluggable

tony.kay22:12:22

That ns uses low-level pushState etc, and just ignores libs like pushy…

xceno15:11:45

Sanity check please: I think I found a bug, that must have something todo with the pathom3 integration. You can replicate this in the fulcro-rad-demo on the pathom 3 branch. In the rad-demo go to Inventory->New and create a new Item. After saving the url should be rewritten to edit/<some-uuid>, instead it get's rewritten to edit/#fulcro/tempid["6617036a-5fd5-4864-868c-73a72aa8ee95"] and the state machine locks up in what seems to be an undefined state. I don't see an error in the server logs right now besides the one in the middle here:

I 2021-11-30T15:28:17.036Z           _rad.database-adapters.datomic:-367 - Running [:item/name {:item/category [:category/id]} :item/description :item/price :item/in-stock] on entities with  :item/id : [[:item/id #uuid "ac1d66fb-bcff-4705-ae5a-6f3fcf4f9419"]]


E 2021-11-30T15:28:17.038Z                             _rad.pathom3:- 31 - EQL query for :com.wsscode.pathom.core/errors cannot be resolved. Is it spelled correctly? Pathom error: {:com.wsscode.pathom3.error/cause :com.wsscode.pathom3.error/attribute-unreachable}


I 2021-11-30T15:28:17.038Z                       _rad.pathom-common:- 28 - Response:  {com.fulcrologic.rad.form/save-form {:item/id #uuid "ac1d66fb-bcff-4705-ae5a-6f3fcf4f9419", :item/name "asd", :item/category {:category/id #uuid "ffffffff-ffff-ffff-ffff-000000001003"}}}
I'm trying to find the correct spot to debug this now

tony.kay17:11:15

Ah, yes…someone mentioned (@UHA0AQZ2M?) that the tempids were not getting returned. I had not had a chance to look at it. Did you fix that with your xtdb stuff Piotr?

Jakub Holý (HolyJak)17:11:51

I guess you either need to add :tempids to the query manually on the Fulcro side using global- eql-transform or replicate the pathom2 plugin that did that on the P. side

tony.kay17:11:39

Right, but I thought we were adding :tempids to the query on client side

Piotr Roterski17:11:44

rad.pathom2 used pathom2's :com.wsscode.pathom.connect/mutation-join-globals attribute but maybe it shouldn’t be globally added to all queries - it seems to be only relevant for save-form mutations

tony.kay17:11:19

should be this on app side:

(defn global-eql-transform
  "Returns an EQL transform that removes `(pred k)` keywords from network requests."
  [pred]
  (fn [ast]
    (let [mutation?     (symbol? (:dispatch-key ast))
          has-children? (seq (:children ast))]
      (cond-> (-> ast
                (rad-app/elide-ast-nodes pred)
                (update :children conj (eql/expr->ast :com.wsscode.pathom.core/errors)))
        (and mutation? (not has-children?)) (update :children conj (eql/expr->ast '*))
        mutation? (update :children conj (eql/expr->ast :tempids))))))

tony.kay17:11:19

to get the correct behavior we need * as the mutation join if there isn’t one, and force include :tempids if there is

tony.kay17:11:49

the pathom 2 error key isn’t necessary here

tony.kay17:11:02

but the error story isn’t perfect…there is never a perfect story there

tony.kay17:11:09

ok, so could you try git sha 3135c5c157d1a15596951ac3bad734f32d07e538 on fulcro-rad dependency and see if that fixes it?

tony.kay17:11:40

that should not break the main branch either

tony.kay17:11:45

pushed as 1.1.0-RC8-SNAPSHOT as well

Piotr Roterski17:11:52

it did solve it for me, :tempids was added to the query on client side

xceno17:11:54

Sorry I was afk for a bit, I'll test it in my app now!

Jakub Holý (HolyJak)18:11:35

We considered adding tempids in Fulcro but using the pathom plugin turned out to be a simpler solution I believe

tony.kay18:11:15

probably makes sense to just use this basic GEQL handler in general in Fulcro

xceno18:11:27

Okay that has fixed it! Now back to my own bugs 🙃