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

<ReferenceManyField /> passes non-consistent properties (loaded?) to child components #5054

Closed
wmwart opened this issue Jul 15, 2020 · 10 comments · Fixed by #5487
Closed

<ReferenceManyField /> passes non-consistent properties (loaded?) to child components #5054

wmwart opened this issue Jul 15, 2020 · 10 comments · Fixed by #5487
Assignees
Labels

Comments

@wmwart
Copy link

wmwart commented Jul 15, 2020

What you were expecting:
I was expecting the display of <Show /> page with <ReferenceManyField /> after the transition from <List> page.

What happened instead:
Application crashed

Steps to reproduce:
The bug stably appears with the following algorithm of actions:

  • open <List> page
  • Go straight to <Edit> page (you cannot be on the page for a long time because the data in the list is discarded)
  • save the record with a redirect to <List> page
  • while the <List> update loader is spinning, click on the line and go to <Show /> page with <ReferenceManyField />
  • the application crashes

image

I’m not sure, but the initial analysis says that useReferenceManyFieldController passes in <ListContext.Provider value = {controllerProps}> of <ReferenceManyField /> loaded property in the wrong order. As a result, in <DataGrid /> it is valid with loaded: true with ids: undefined

Other information:
YhhyHUwuHm

Environment

  • React-admin version: 3.7.1
  • Last version that did not exhibit the issue (if applicable): 3.6.2
@Luwangel
Copy link
Contributor

Hi,

Thank you for opening this issue and giving so many details 🙏

I need to reproduce the problem you describe on my side in order to fix it quickly. Could you create a CodeSandbox?

  1. Please fork the following template on CodeSandbox : React Admin Template
  2. Reproduce your bug. Remember to give us the clearest and simplest example possible.
  3. Reply to this issue with the link of your CodeSandbox, and extra information if it's necessary.

Regards,
Adrien

@wmwart
Copy link
Author

wmwart commented Jul 23, 2020

CodeSandbox does not work after updating react-admin dependency to version 3.7.1

@Luwangel
Copy link
Contributor

@MattWilliamsDev We made a fix recently #5068. It should work now.

@wmwart
Copy link
Author

wmwart commented Jul 30, 2020

I cannot repeat this in the CodeSandbox, because after saving the record and switching to the list, its optimistic loading does not start (the data is located locally). The problem appears exactly when I go to Show page while the List is loading

@fzaninotto
Copy link
Member

@wmwart Can you try now to build a CodeSandbox reproducing the problem?

@MicroJackson
Copy link

MicroJackson commented Sep 17, 2020

I think I have the same problem with my app, if not I will create a new issue.
I made a codesandbox for the first time here: https://codesandbox.io/s/loving-lovelace-d7zji?file=/src/data.js
What I changed was removing the authProvider and adding an extra field to the Users data called: "other_user_id"
Then created a ReferenceManyField in UserEdit.
image

How to reproduce:

  1. Go to Users
  2. Click on Annamarie Mayer
  3. Change Annamarie Mayer to Annamarie Mayers
  4. Save
  5. Quickly click Breanna Gibson
  6. React Admin crashes with "TypeError: Cannot read property 'map' of undefined"

How to fix this, is to either wait for it to save completely, or to go to Breanna Gibson before doing these steps.

Probably related problem, and steps to reproduce are (make sure you refreshed the page):

  1. Go to Users
  2. Click on Annamarie Mayer
  3. Use the reference to Breanna Gibson
  4. React Admin crashes with "TypeError: Cannot read property '2' of undefined"

This has the same fix, if you go to Breanna Gibson and Logan Schowalter before using the reference, it works fine.

I hope this helped, let me know if I should change something.

EDIT: @Luwangel, can you check out this post?
EDIT2: @fzaninotto, can you check out this post?

@MicroJackson
Copy link

Seems like pings with an edit do not work. So @Luwangel or @fzaninotto.
Any update on this issue? This completely breaks undoable/optimistic rendering with a ReferenceManyField.

@fzaninotto
Copy link
Member

Thanks, reproduced. I'm marking this as a bug.

@fzaninotto
Copy link
Member

So I'm making progress in understanding what happens:

  1. After editing a user, react-admin does an optimistic update and redirects to the list
  2. as the optimistic mode is turned on, the read queries are resolved immediately from the store
  3. If the user clicks on an user in the list before the end of the undo period, the getOne request resolves immediately from the store (no problem), and the getManyReference also resolves immediately from the store (problem, because the store is empty).

So the ListContext for the SingleFieldList contains loaded: true and ids: undefined until the end of the optimistic mode, which crashes the rendering.

I understand the cause, but I have yet to find a good solution.

@rreckonerr
Copy link

HI @fzaninotto ! Any news on this one?

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

Successfully merging a pull request may close this issue.

5 participants