Laziness is the likely culprit. React forces things in dev but not prod.
I’m having some issues figuring out how to store upload percentage in the state db to be used by a component. The code uses amplify-js which takes a callback. I have no issues logging the percentage out but don’t know how to display it in the UI. Any suggestions?
(defn- calculate-upload-progress [progress]
(let [percentage (.floor
js/Math
(* 100
(/ (.-loaded progress)
(.-total progress))))]
(log/debugf "Upload Progress: %d" percentage)))
(defn upload-file
"supports the upload of a single file"
[{:keys [file real-id job-id string-columns job-name app]}]
(go (let [key-path (gstring/format "uploads/%s.json" job-name)
resp (<p! (.vault.put Storage key-path
(js/Blob. #js [file])
(clj->js
{:metadata {:string-columns string-columns
:job-id (str real-id)}
:progressCallback calculate-upload-progress})))]
(try
(comp/transact! app [(update-job-status {:id real-id :url "" :status "Converting..."})])
(comp/transact! app [(set-loading {:uploading false})])
(catch js/Error err (js/console.log (ex-cause err)))))))
Make a mutation for it and transact it from the callback, no?
(defn calculate-upload-progress [component pct]
...
(m/set-integer! component :ui/progress :value pct))
...
:progressCallback (partial calculate-upload-progress component)
...
and just propagate this
from the component that should display it. (Alternatively, use the global APP
and transact! with a mutation that will set the value where you want it.)Thank you. That makes sense.
I am investigating why cljs.pprint
is being included in a release build of an app I'm working on.
To start out with good known starting state, I cloned the fulcro template from (https://github.com/fulcrologic/fulcro-template)
and see that cljs.pprint is included in the release build for the :main
build of that template:
As far as I can tell pprint is not included anywhere directly in the codebase and there are no obvious indications of namespaces that would include it transitively.
I created the report by running:
./node_modules/.bin/shadow-cljs run shadow.cljs.build-report main report.html
I'm going to continue removing namespaces from requires to see if I can get pprint removed, but I'm wondering if anyone else ran into this?
I'm not sure, but I think fulcro itself may be including it. I put together a small reproduction here: https://github.com/dvingo/fulcro-release-build-incl-pprint
This is all on the TODO list. There is already a stubs file for guardrails that you can swap out via “resolve” cljs settings.
https://github.com/fulcrologic/guardrails/blob/develop/src/main/com/fulcrologic/guardrails/noop.cljc
It isn’t a super high priority for me, because the apps I work on really don’t care that much about hyper-optimizing build size. People put jpgs on their sites that are bigger than the diff between simple and the best optimizations possible, so it is very very very low on the TODO list to do anything more about this, other than accept very well-tested PRs.
yikes please don't use :resolve
for this. that this actually works (if it does) is a bug, it shouldn't affect how CLJS namespaces resolve. for CLJS you should use the :ns-aliases
option, same result really. see the example for re-frame-10x :build-options :ns-aliases
https://github.com/day8/re-frame-10x#easy-setup
I'd push back a little on the jpeg argument. while it is true that over-optimizing for size is not super relevant in many cases the extra JS is significantly more expensive and impactful than an extra oversized image. eliminating a lot of code that is unused anyways can noticeably affect load performance, especially on lower end hardware or mobiles/tablets.
I've done optimizations taking load times from 3sec to 500ms just by code splitting intelligently and removing unused code
Thanks for the reply @tony.kay I understand for some use cases this doesn't matter, but there are plenty of valid use cases where it does (I'm sure you're well aware https://web.dev/why-speed-matters/) Is this TODO list publicly visible? It would have been good to know about it before I spent the hours investigating this.
Thanks for the tip Thomas - I'll try out the stubs feature and see how it goes
@thheller thanks for looking. I thought that worked, but part of the reason that ns is marked alpha is because I wasn’t sure the comment was right, and hadn’t had time to research it again.
Docstring and README updated.
On load times. Yeah. 2.5s for an SPA you load once and run for hours. Just don’t care.
That is not the only use case of all uses of fulcro
And the optimization paths are available to you. Obviously I care enough that you are able to follow those paths. When I say I don’t care, I mean I don’t care for my personal use-cases, and 90% of the ppl I’ve seen optimizing for this shouldn’t either.
there are some cases where it matters, but too many people go down this rabbit hole on prod software while their users are screaming for real fixes to real problems they have, and I guarantee you no one has lost a customer for a 2.5s load delay on an app they run all day.
Unless “reloading” that app is something they have to do a lot for some reason. Not saying there are not valid cases. Just that most ppl don’t have them.
This kind of viewpoint would be good to document in the fulcro documentation "The author doesn't care about page load performance caveat lector". fwiw A https://www.ericsson.com/en/press-releases/2016/2/streaming-delays-mentally-taxing-for-smartphone-users-ericsson-mobility-report shows that the stress response to delays in mobile speed are similar to that of watching a horror movie or solving a mathematical problem, and greater than waiting in a checkout line at a retail store. Not everyone is building a a SPA that is loaded once and used all day. Please stop assuming that.
Please re-read what I said. I am neither assuming that nor limiting your ability to fix that. I have spent a lot of time…meh. I don’t have time for these kinds of discussions. Sorry I chimed in on this one, to be honest.
Yep. Agreed. Sorry to waste your time.
no worries. It happens. Esp on Monday morning 😛
do you expect expound to be there too? I think that may be coming from guardrails?
I do not expect that to be there -and spec.gen is probably not either. This is for a release build so guardrails should be disabled
cljs.pprint is not DCE capable so just requiring it will keep it in the build, even if otherwise unused
there's this section in the guardrails readme https://github.com/fulcrologic/guardrails#clojurescript-considerations
> > Doing so will prevent you from accidentally generating a release build with guardrails enabled in case you had a shadow-cljs server running in dev mode (which would cache that guardrails was enabled) and built a release target: >
You can try for yourself using that repo - I'd be happy to know if I'm doing something wrong, but there's one namespace in the project so it's hard to see what that would be
guardrails is not even in the dependency list (aside from fulcro including it transitively)
I would also expect other projects to see this showing up
what do you mean? fulcro directly requires guardrails, which means all the dependencies that has will be in your build
disabling guardrails does not change that, it only affects the code the macros generate
hi, newbie question here. is save-middleware the best place to insert business logic such as set the owner of the object to the currently-logged-in user? I want to avoid having to do that on the front end.
Not sure but it sounds reasonable to me 🙂
thanks
handled it that way and actually worked out nicely that I could do it as a more general save-middleware with actual actions taken pre/post/save specified via attribute options on the entity identity attribute
using RAD
I am seeing cljs.pprint and expound and fulcro.client-inspect etc show up in the shadow.cljs.build-report for a clojurescript project that uses fulcro. I do not understand why this is happening, so I posted the above git repository to make it easy for others to verify. Just requiring and rendering a fulcro application with one fulcro component results in those extra namespaces showing up in the build report.
Are you saying it is expected that cljs.pprint would show up then? That that is the cost of using fulcro?
if there is something requiring it in the build then yes it is fully expected. I don't know WHAT is requiring it but it seems like it is
you can reconstruct it from the compiler data but there is not function available currently do that for you
got it - thanks for the explanation. I believe a likely candidate is expound: https://github.com/bhb/expound/blob/46b5c84bfe578a81b07c39501a9ed60cfd6ed09f/src/expound/printer.cljc If there isn't much fulcro can do about this perhaps it can at least be documented. It would be good to know if it is intentional or not, or perhaps there is a way to prevent the inclusion of these with some code changes or config changes to one or all of fulcro, guardrails, and expound
my guess would be that it just hasn't been optimized yet, maybe just some namespace reordering would fix it already