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

Duplicate keys warning generated when redirecting to List after saving in Edit form #1880

Closed
ashkart opened this issue Jun 6, 2018 · 8 comments

Comments

@ashkart
Copy link

ashkart commented Jun 6, 2018

When i save Edit form its all going ok untill redirect back in List of items. Redirect itself succeeds successfully, but in console there is warning generated. It seems App thinks that there Create operation was just performed, not Edit.

warning.js:33 Warning: Encountered two children with the same key, 32. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
in tbody (created by TableBody)
in TableBody (created by WithStyles(TableBody))
in WithStyles(TableBody) (created by DatagridBody)
in DatagridBody (created by shouldUpdate(DatagridBody))
in shouldUpdate(DatagridBody) (created by Datagrid)
in table (created by Table)
in Table (created by WithStyles(Table))
in WithStyles(Table) (created by Datagrid)
in Datagrid (created by WithStyles(Datagrid))
in WithStyles(Datagrid) (created by VacancyList)
in div (created by ListView)
in div (created by Paper)
in Paper (created by WithStyles(Paper))
in WithStyles(Paper) (created by Card)
in Card (created by WithStyles(Card))
in WithStyles(Card) (created by ListView)
in div (created by ListView)
in ListView (created by ListController)
in ListController (created by TranslatedComponent(undefined))
in TranslatedComponent(undefined) (created by Connect(TranslatedComponent(undefined)))
in Connect(TranslatedComponent(undefined)) (created by List)
in List (created by WithStyles(List))
in WithStyles(List) (created by VacancyList)
in VacancyList (created by WithPermissions)
in WithPermissions (created by Connect(WithPermissions))
in Connect(WithPermissions) (created by getContext(Connect(WithPermissions)))
in getContext(Connect(WithPermissions)) (created by Route)
in Route (created by Resource)
in Switch (created by Resource)
in Resource (created by Connect(Resource))
in Connect(Resource) (created by Application)
in Route (created by RoutesWithLayout)
in Switch (created by RoutesWithLayout)
in RoutesWithLayout (created by Route)
in div (created by Layout)
in main (created by Layout)
in div (created by Layout)
in div (created by Layout)
in Layout (created by WithStyles(Layout))
in WithStyles(Layout) (created by Connect(WithStyles(Layout)))
in Connect(WithStyles(Layout)) (created by LayoutWithTheme)
in MuiThemeProvider (created by LayoutWithTheme)
in LayoutWithTheme (created by Route)
in Route (created by CoreAdminRouter)
in Switch (created by CoreAdminRouter)
in div (created by CoreAdminRouter)
in CoreAdminRouter (created by Connect(CoreAdminRouter))
in Connect(CoreAdminRouter) (created by getContext(Connect(CoreAdminRouter)))
in getContext(Connect(CoreAdminRouter)) (created by Route)
in Route (created by CoreAdmin)
in Switch (created by CoreAdmin)
in Router (created by ConnectedRouter)
in ConnectedRouter (created by CoreAdmin)
in TranslationProvider (created by withContext(TranslationProvider))
in withContext(TranslationProvider) (created by Connect(withContext(TranslationProvider)))
in Connect(withContext(TranslationProvider)) (created by CoreAdmin)
in Provider (created by CoreAdmin)
in CoreAdmin (created by withContext(CoreAdmin))
in withContext(CoreAdmin) (created by Application)
in Application

Despite that warning, edited record is successfully updated in the List.

Here my dataProvider response data extraction code:

const extractDataFromHttpResponse = (response, type, resource, params) => {
        return response.json().then((json => {
            switch(type) {
                case GET_LIST:
                    let total = json.totalItems;
                    delete json.totalItems;

                    return {
                        data: Object.values(json),
                        total: total,
                    };

                case CREATE:
                    return {
                        data: Object.assign({}, params.data, { id: json.id })
                    };

                default:
                    return { data: json };
            }
        }));
    };

Here my Application class code:

const Application = () => (
    <Admin dataProvider={dataProvider}>
        <Resource name='vacancy' show={VacancyShow} list={VacancyList} edit={VacancyEdit} create={VacancyCreate} />
        <Resource name='user' list={UserList} />
    </Admin>
);

This is Edit form code:

export default class VacancyEdit extends React.Component {
    render() {
        return (
            <Edit {...this.props}>
                <SimpleForm>
                    <DisabledInput source="id" />
                    <LongTextInput source="position_name"/>
                    <RichTextInput source="requirements"/>
                    /*..other inputs.*/
                </SimpleForm>
            </Edit>
        );
    }
}

And the List:

export default class VacancyList extends React.Component {
    render() {
        return (
            <List {...this.props} perPage={10}>
                <Datagrid>
                    <TextField source="position_name" />
                    <TextField source="requirements" />
                    <TextField source="liabilities" />
                    <TextField source="conditions" />
                    <TextField source="description" />
                    <PaycheckField source="paycheck" />
                    <EditButton basePath="/vacancy" />
                </Datagrid>
            </List>
        );
    }
}
@fzaninotto
Copy link
Member

Can't reproduce it in the example app. Can you fork this CodeSandbox and tweak it until you manage to reproduce your issue?

@ashkart
Copy link
Author

ashkart commented Jun 7, 2018

i just tried to do that, but there isnt any warnings. It seems our react-admin versions a bit different.

https://codesandbox.io/s/w6r3x5nk6k

The warning itself generated in react-dom:
react-dom.development.js:7744
knownKeys = warnOnInvalidKey(child, knownKeys);

Seems we shouldnt get in this place at all.

@fzaninotto
Copy link
Member

OK, I'm closing the issue then. Feel free to reopen if you manage to reproduce the bug.

@swalihkdan
Copy link

I have this same issue, is there any solution for this

@ucefkh
Copy link

ucefkh commented Apr 9, 2023

@fzaninotto c'est toujours un bug en 2023!!!! is always happening cmon

here is a screenshot

image

@djhi
Copy link
Collaborator

djhi commented Apr 11, 2023

@ucefkh If you want us to investigate then provide a codesandbox showing the issue.

@ucefkh
Copy link

ucefkh commented Apr 12, 2023

Bro, use react admin-firebase and set lazyMode:true that's it!

I can't share my Firebase app publicly so you can try it

Look how bad this is!

image

It is affecting us so much and I knew this bug for a few years now that was never fixed

@ucefkh
Copy link

ucefkh commented Apr 12, 2023

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

No branches or pull requests

5 participants