prestancedesign / inertia-clojure

A Clojure adapter for Inertia.js
https://inertia.prestance-design.com/
Eclipse Public License 1.0
97 stars 3 forks source link

dev refresh takes you to home page #1

Closed eoliphan closed 3 years ago

eoliphan commented 3 years ago

This isn't really a bug per-se, but solutions will really help DX. I just hacked up the following for now in a reagent client. will obviously need to extend it to handle props, etc

(defonce cururl (atom nil))

(defn before-load
  []
  (reset! cururl (.. js/window -location -href)))

(defn mount-reload
  []
  (d/render [#'app] el)
  (.setTimeout js/window
    (fn []
      (.visit Inertia @cururl
        #js {:method   "get"}))
    1))

(defn after-load
  []
  (mount-reload))
prestancedesign commented 3 years ago

Hi and thanks for the feedback. 👍

I just push a new commit who use now createInertiaApp new helper and it fix this issue's behavior. https://github.com/PrestanceDesign/inertia-clojure/blob/main/examples/client-side/reagent-inertiajs/src/reagent/inertia.cljs#L36-L43

So we can close this. Best regards.

eoliphan commented 3 years ago

Hi, I updated my app to use createInertiaApp, etc. But calling the (start) from the :after-load causes the same issue, goes back to the home page. However, I created another method that calls (.reload Inertia) and called that from :after-load, and that seems to do the trick

prestancedesign commented 3 years ago

Strange you got the same issue, it works well on my side for these repo examples and the Ping CRM demo, in addition to another projects.

Anyway, I change the setup https://github.com/prestancedesign/inertia-clojure/commit/256dc2c6c2aa4341ff5dc54a0af6b7b74ce5dc18 to use Inertia.reload with the Shadow-cljs dev/after-load hook, to handle the refresh without using var.

This has the positive effect of decreasing the production bundle size and should fix the page redirect behaviour with some particular setup.