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

Columns Sort Bug -> insertBefore Error #9368

Closed
igor-adzz opened this issue Oct 18, 2023 · 5 comments · Fixed by #9369
Closed

Columns Sort Bug -> insertBefore Error #9368

igor-adzz opened this issue Oct 18, 2023 · 5 comments · Fixed by #9369
Labels

Comments

@igor-adzz
Copy link

igor-adzz commented Oct 18, 2023

What you were expecting:
After upgrading to react admin 4.15.0, I'm trying to sort columns in datagrid via the Column button.
image

What happened instead:
Instead, when the sorted element hits any other one, I get an error message. The method that throws the error was added to ra-ui-materialui in version 4.14.6 (closest() instead of parentNode). Now list is null and dropItem is null too.

if (list === dropItem.parentNode.closest('ul')) {  // null === null
    dropIndex.current = dropItem.dataset.index;
    if (dropItem === selectedItem.nextSibling) {
        dropItem = dropItem.nextSibling;
    }
    list.insertBefore(selectedItem, dropItem);  // null.insertBefore
}

image

Steps to reproduce:

  • Create a List and add a DatagridConfigurable
  • Try to move the column to another place
  • React-admin version: 4.15.0
  • Last version that did not exhibit the issue (if applicable): 4.14.0
  • React version: 18.2.0
  • Browser: Google Chrome
  • Stack trace (in case of a JS error):
Uncaught TypeError: Cannot read properties of null (reading 'insertBefore')
    at handleDrag (FieldToggle.tsx:50:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
    at invokeGuardedCallback (react-dom.development.js:4277:1)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1)
    at executeDispatch (react-dom.development.js:9041:1)
    at processDispatchQueueItemsInOrder (react-dom.development.js:9073:1)
    at processDispatchQueue (react-dom.development.js:9086:1)
    at dispatchEventsForPlugins (react-dom.development.js:9097:1)
    at react-dom.development.js:9288:1
react-dom.development.js:4312 Uncaught TypeError: Cannot read properties of null (reading 'insertBefore')
    at handleDrag (FieldToggle.tsx:50:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
    at invokeGuardedCallback (react-dom.development.js:4277:1)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1)
    at executeDispatch (react-dom.development.js:9041:1)
    at processDispatchQueueItemsInOrder (react-dom.development.js:9073:1)
    at processDispatchQueue (react-dom.development.js:9086:1)
    at dispatchEventsForPlugins (react-dom.development.js:9097:1)
    at react-dom.development.js:9288:1
FieldToggle.tsx:63 Uncaught TypeError: Cannot read properties of null (reading 'getBoundingClientRect')
    at handleDragEnd (FieldToggle.tsx:63:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
    at invokeGuardedCallback (react-dom.development.js:4277:1)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1)
    at executeDispatch (react-dom.development.js:9041:1)
    at processDispatchQueueItemsInOrder (react-dom.development.js:9073:1)
    at processDispatchQueue (react-dom.development.js:9086:1)
    at dispatchEventsForPlugins (react-dom.development.js:9097:1)
    at react-dom.development.js:9288:1
react-dom.development.js:4312 Uncaught TypeError: Cannot read properties of null (reading 'getBoundingClientRect')
    at handleDragEnd (FieldToggle.tsx:63:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
    at invokeGuardedCallback (react-dom.development.js:4277:1)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1)
    at executeDispatch (react-dom.development.js:9041:1)
    at processDispatchQueueItemsInOrder (react-dom.development.js:9073:1)
    at processDispatchQueue (react-dom.development.js:9086:1)
    at dispatchEventsForPlugins (react-dom.development.js:9097:1)
    at react-dom.development.js:9288:1
@igor-adzz igor-adzz changed the title Column sort show an error Columns Sort -> insertBefore Error Oct 18, 2023
@igor-adzz igor-adzz changed the title Columns Sort -> insertBefore Error Columns Sort Bug -> insertBefore Error Oct 18, 2023
@djhi
Copy link
Collaborator

djhi commented Oct 18, 2023

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

@igor-adzz
Copy link
Author

igor-adzz commented Oct 18, 2023

@djhi
A link: https://stackblitz.com/edit/github-xknwec?file=src%2Fposts%2FPostList.tsx

I should also note that if you use a simple Datagrid, the columns are not displayed inside Columns at all.

image

@slax57
Copy link
Contributor

slax57 commented Oct 18, 2023

Reproduced, thanks for the report!

@slax57
Copy link
Contributor

slax57 commented Oct 18, 2023

Btw

I should also note that if you use a simple Datagrid, the columns are not displayed inside Columns at all.

This is expected. The <SelectColumnsButton> must be used in conjunction with <DatagridConfigurable>.

@slax57
Copy link
Contributor

slax57 commented Oct 18, 2023

Okay found it, actually the DatagridEditor works fine but we forgot to add component="ul" to the <Box> in <SelectColumnsButton>. PR incoming.

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.

3 participants