Comments (9)
There was a typo in tempid remapping code that is supposed to fix tempids for non-application state (queues, etc.). Should be fixed in 3.5.19-SNAPSHOT and above. Needs testing.
from fulcro.
Breaks tempid->realid map in queues
; Server side resolver
(pco/defmutation something [env {:keys [id]}]
{::pco/op-name 'dosomething}
{:tempids {id "Resolved ID"}})
; Client side code
(defmutation dosomething [_]
(remote [env]
(m/with-server-side-mutation env 'dosomething))
(ok-action [{:keys [tempid->realid]}]
(println :tempid->realid tempid->realid)))
(dom/div {:onClick (fn []
(let [temp (tempid/tempid)]
(comp/transact! this [(dosomething {:id temp})]) ; (mutation 1)
(comp/transact! this [(dosomething {:id temp})]))}) ; (mutation 2)
Expected print result from ok-actions:
- {(tempid/tempid) "Resolved ID"}
- {(tempid/tempid) "Resolved ID"}
Actual print result from ok-actions:
- {(tempid/tempid) "Resolved ID"}
- {"Resolved ID" "Resolved ID"}
from fulcro.
Ah. Hm. Yeah, the first txn remaps that tempid everywhere, including in the queues. Going to need an exclusion for that.
from fulcro.
But what, exactly, got sent on the network by (2)? I think it doesn't matter, because the second one should have communicated with the server with the correct ID, which means there is no longer a tempid possible in anything.
from fulcro.
I think that the main problem is that the mutation's parameter is a tempid and that it is not possible to resolve the realid if you want to perform an ok-action.
(defmution something [{:keys [id]}] ; tempid here
(ok-action [{:keys [tempid->realid]}]
; not possible to know realid to trigger a load for example
))
You're correct that essentially there is no tempid resolution in the second remote mutation.
However, it would be ideal to have prior tempid resolutions available in queued mutations.
from fulcro.
Technically you are correct, but there are ways to work around it. For example, using returning
from a mutation is really the right way to "load" the result of a mutation.
If you wanted to take a stab at a fix, it's probably just changing the prewalk-replace in resolve-tempids
in algorithms.tempid. Basically you still need to find the tempids everywhere, but skip values where the key is :tempid->realid
. A bit fiddly given that that is supposed to work on general data structures, so the tempid could appear in a set, vector, map key, map value, or even list.
So, it would have to be rewritten very carefully with decent tests.
I'm not absolutely sure that's the internal value that you'd need to track.
from fulcro.
By the way, have you looked at the id in the second mutation's params? Technically it should have already been rewritten as well. The closure over that value when into the tx queue, and should have been rewritten...so I would not expect you to need to rewrite it.
from fulcro.
OK, I've verified what you're seeing, and I can confirm that it does not work in an ideal manner. There is no easy fix internally for this, but there is an easy workaround: put the follow-on transact call in the first mutation's ok-action.
For future reference, here is the issue (in case I get the energy to spend a couple of days reworking the internals):
- A mutation is just a multimethod that returns a map.
- That multimethod closes over the params, so they cannot be rewritten by the tempid system here:
- The tempid in the submitting second transaction is not closed over, so the remapped value gets returned to the server (correctly) but the param still has the tempid value. Thus, an ok or error action doesn't know the ID of the entity that was actually affected in app state. It could, if there's only one tempid, infer it from the tempids map, since both k and v and the actual real id....but this is an inconsistency that is annoying.
from fulcro.
After messing with it for some time I've decided there is no clean solution for making this work. The official fix is to submit the second transaction from the ok-action of the first. I'm not willing to rewrite the tx system for a minor inconvenience that I've never hit in 5 years of production use.
Remember that:
- Mutations can use
returning
to get back data about the thing on the server - Tempids are resolved in a distributed async fashion, so IMO if you have a combination of things you need to do to some new thing, then it should be part of a single mutation on the server, where the overall interaction can be managed. What if the second one failed due to network outage? Then you'd have a partially correct result on the server.
from fulcro.
Related Issues (20)
- Unnecessary re-rendering HOT 3
- Denormalize should not "detect loop" for leaf entities HOT 2
- Associate a list of components with a different instance of a state machine each HOT 1
- Warnings about missing initial state for anonymous components with a `:componentName` HOT 7
- `comp/get-query` not correct when using raw component and union query HOT 4
- Fix text area and table examples exploding width HOT 2
- Fulcro 3.6 w/React 18
- http error 404 on github-pages HOT 2
- Fulcro 3.6 use of React Context breaks shouldComponentUpdate optimizations HOT 9
- http-remote :status-code is always 500 on error HOT 6
- Potentially add "Accept: application/transit+json" header. HOT 1
- Potentially omitted :force-root in `schedule-render!` HOT 5
- dr/change-route-relative! -- denied route does not call :route-denied component option HOT 1
- Dependency issue with taoensso.encore/dissoc-in HOT 2
- fs/dirty-fields misses recursive field HOT 1
- Link/ident queries don't work with `false` values
- dynamic routing question HOT 1
- HTTP middleware for making load/mutations work easily with JSON http APIs.
- Hook-based defsc should also have their parent set
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fulcro.