Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix issue when one of a children is undefined #189

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

Merged
andresin87 merged 3 commits into SortableJS:master from exentrich:patch-1
Jan 14, 2022

Conversation

Copy link

@exentrich exentrich commented Oct 7, 2020

Firstly huge thanks for such amazing module!
In some edge cases (like in my own) there can be a undefined React child. Easy to reproduce:

<ReactSortable>
 {some_var ? <li>123</li> : undefined}
 <li>123</li>
</ReactSortable>

In such case crash happen because code can't read property of undefined object.
Just check changes that I made into react-sortable.tsx file you will understand what I'm trying to achieve.

I also changed this line from const item = list[index]; to const item = list[index] || {}; , just to be sure that if list doesn't have particular index, whole code not fail.
This two changes are made to prevent edge case crashes. In my own app I spend a lot of time to find out why sometime app is crashing.

Please, please approve this pull request!

dawnlunacy, cosadmin, teaarte, and andresin87 reacted with thumbs up emoji dawnlunacy and cosadmin reacted with hooray emoji cosadmin reacted with rocket emoji
Firstly huge thanks for such amazing module!
In some edge cases (like in my own) there can be a `undefined` React child. Easy to reproduce:
```js
<ReactSortable>
 {some_var ? <li>123</li> : undefined}
 <li>123</li>
</ReactSortable>
```
In such case crash happen because code can't read property of undefined object.
Just check changes that I made into `react-sortable.tsx` file you will understand what I'm trying to achieve.
I also changed this line from `const item = list[index];` to `const item = list[index] || {};` , just to be sure that if list doesn't have particular index, whole code not fail.
This two changes are made to prevent edge case crashes. In my own app I spend a lot of time to find out why sometime app is crashing.
Please, please approve this pull request!
Copy link
Member

@@ -110,7 +110,9 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
const dataid = dataIdAttr || "data-id";
/* eslint-disable-next-line */
return Children.map(children as ReactElement<any>[], (child, index) => {
const item = list[index];
if (!child) return undefined
Copy link
Member

@andresin87 andresin87 Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if child is nullish?

@andresin87 andresin87 merged commit 8a7cb54 into SortableJS:master Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@andresin87 andresin87 andresin87 approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /