Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimistic updates of references not working #12

Open
dlerman2 opened this issue Sep 12, 2018 · 3 comments
Open

Optimistic updates of references not working #12

dlerman2 opened this issue Sep 12, 2018 · 3 comments
Labels
bug Something isn't working

Comments

@dlerman2
Copy link

In the prisma e-commerce example, if you go to the product list screen, edit the first product, change the brand and hit save, you'll see in the list view that the brand shows the old value until 3 seconds later when the new data is refreshed and you see the updated value.

The same appears to be true anytime you update a reference using the opencrud data provider -- but if you switch to one of the rest data providers, the optimistic update works as expected. I haven't had time to fully investigate yet, but it looks like the use of the derived source.id field is somehow screwing up the optimistic update system -- if I hack it to use source_id instead, it fixes it...

@dlerman2
Copy link
Author

The problem does seem to be with the extra source.id field.

The Product returned from the data loader has both a brand member containing the full Brand object and a brand.id field containing just the linked id. When the optimistic update fires, the brand.id has been updated to the new value, but the brand object still refers to the old value.

screen shot 2018-09-12 at 10 26 11 am

If I comment out https://github.com/Weakky/ra-data-opencrud/blob/master/src/getResponseParser.js#L36 so the source.id field never gets created, it appears to fix the problem, but I'm not sure of the broader implications of that change...

dlerman2 pushed a commit to bouldercare/ra-data-opencrud that referenced this issue Sep 12, 2018
@Weakky
Copy link
Owner

Weakky commented Sep 13, 2018

Hey there,

Thanks for this issue! You're right about optimistic updates not properly working with reference.

However, your suggested fix doesn't work for me. I tried updating the brand of a product and it doesn't work either when removing the field brand.id.

To be honest, these generated field.id are part of the legacy from ra-data-graphcool, and I'm not sure yet either what are the usecases.

The n-to-many fields also have generated fields named fieldIds, but those are useful when using <ReferenceArrayInput />, because the source is expected to be an array of id.

I'm gonna dig further to understand what's going on.

EDIT: It doesn't work either with <ReferenceArrayInput /> fields.

@Weakky Weakky added the bug Something isn't working label Sep 13, 2018
@dlerman2
Copy link
Author

Thanks for taking a look, and for the overall project -- other than this one issue, it's been working great!

I see that the code is the same in ra-data-graphql-simple and ra-data-graphcool - wonder if it's worth asking over there why the dual representations of the data. Also, I wonder if it would simplify to just make the return value look more like the REST version and map the embedded object to brand_id instead of brand.id and brand. You'd have to update any Reference components to use "brand_id" as the source instead of "brand.id", but at least it would be guaranteed to work as long as the REST version works...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants