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

Fix ReferenceManyField throws error after insert #5877

Merged
merged 1 commit into from
Feb 6, 2021

Conversation

fzaninotto
Copy link
Member

This fixes a nasty bug that is hard to reproduce.

The bug occurs when a ReferenceManyField renders a second time after the reference data has been updated on the server-side, and if the children of the ReferencenceManyField don't work with an empty record. This causes a "Something Went Wrong" screen in production.

A more specific bug repro:

  • in PostEdit, change the final tab to
            <FormTab label="post.form.comments">
                <ReferenceManyField
                    reference="comments"
                    target="post_id"
                    addLabel={false}
                    fullWidth
                    perPage={2}
                >
                    <Datagrid>
                        <FooField label="foo" />
                    </Datagrid>
                </ReferenceManyField>
            </FormTab>

with

// this will fail if record is undefined
const FooField = ({ record }) => <span>{record.foo}</span>;
  • go to posts list
  • click on edit post 2
  • go to comment list
  • create 2 new comments on post 2
  • go to posts list
  • click on edit post 2
  • error

The cause is a lack of synchronization between the ids and the data in useGetManyReference, due to two Redux selectors working on one another (i.e. one after the other).

The fix is similar to #5577 on useGetList: we don't execute one selector after another, we execute them both at the same time.

@fzaninotto fzaninotto added the RFR Ready For Review label Feb 5, 2021
@fzaninotto fzaninotto added this to the 3.12.2 milestone Feb 5, 2021
@djhi djhi merged commit 0d91a96 into master Feb 6, 2021
@djhi djhi deleted the Fix-ReferenceManyField-throws-error-after-insert branch February 6, 2021 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants