Skip to content
New issue

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

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

Already on GitHub? # to your account

Edit component empty #5228

Closed
HamAndRock opened this issue Sep 3, 2020 · 6 comments · Fixed by #5373
Closed

Edit component empty #5228

HamAndRock opened this issue Sep 3, 2020 · 6 comments · Fixed by #5373
Assignees
Labels

Comments

@HamAndRock
Copy link

What you were expecting:
To render edit form

What happened instead:
Nothing rendered

Steps to reproduce:
Create new resource, add Edit component and add if in dataProvider.

Data provider implementation:
image

Edit form implementation:
image

Resource implementation:
image

Result:
image

Other information:
I can get data from dataProvider when I use useDataProvider().getOne it works, hovewer when I use just useGetOne it returns undefined again.

Request like create, list and even some other edits work.

Environment

  • React-admin version: 3.8.2
  • React version: 16.13.1
  • Browser: Chrome
  • Stack trace (in case of a JS error): none
@djhi
Copy link
Collaborator

djhi commented Sep 4, 2020

Thanks for reporting this. Please provide a sample application showing the issue by forking the following CodeSandbox (https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple).

@MicroJackson
Copy link

I have this exact same behaviour when my API call does not return an ID in his response described here:
https://marmelab.com/react-admin/DataProviders.html#example-implementation
So make sure there is an:
"id": 123 or something in your response. I do not see that in your response in the console.
An improvement for react-admin would be to notify the programmer of this fact.

@HamAndRock
Copy link
Author

Yes, and also the if you supply different id then in url it also doesn't work.
I took me 6 hours to figure out ....

Please can you add some kind of console warning ?

@fzaninotto
Copy link
Member

There is, indeed, a console warning if the return from dataProvider.getOne() doesn't contain an id key:

if (
fetchActionsWithRecordResponse.includes(type) &&
!response.data.hasOwnProperty('id')
) {
logger(
`The response to '${type}' must be like { data: { id: 123, ... } }, but the received data does not have an 'id' key. The dataProvider is probably wrong for '${type}'`
);
throw new Error('ra.notification.data_provider_error');
}

But it doesn't show up if your NODE_ENV variable is set to production. Could it be that problem?

@MicroJackson
Copy link

No, my NODE_ENV is in development mode, and I have never changed it in all 3 of my react-admin projects.
image
I tried to make a codesandbox to demonstrate it, but the DataProvider can not give the wrong id, or omit the id.

So I tried to create a simple example:
image
The dataProvider.getOne() fetches that.
image
Nothing shows, and there is no log in the console.
And it does do a valid request to my backend:
image
So I do not know when that piece of code needs to be triggered, but it is not being triggered for me. Do note that I am using my own dataprovider, same as OP.

@fzaninotto
Copy link
Member

Reproduced, thanks.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants