From fad823612d475f91d353163e3e7b76398ec57b64 Mon Sep 17 00:00:00 2001 From: Rustem Mussabekov Date: Wed, 7 Oct 2020 11:24:59 +0300 Subject: [PATCH 1/3] Fix issue when one of a children is undefined 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 {some_var ?
  • 123
  • : undefined}
  • 123
  • ``` 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! --- src/react-sortable.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/react-sortable.tsx b/src/react-sortable.tsx index 81dd0f5..8e23db1 100644 --- a/src/react-sortable.tsx +++ b/src/react-sortable.tsx @@ -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[], (child, index) => { - const item = list[index]; + if (!child) return undefined + + const item = list[index] || {}; const { className: prevClassName } = child.props; // @todo - handle the function if avalable. I don't think anyone will be doing this soon. From 631e2d08001f9e141209599433d209c30025fbda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 14 Jan 2022 09:05:16 +0100 Subject: [PATCH 2/3] Update src/react-sortable.tsx --- src/react-sortable.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/react-sortable.tsx b/src/react-sortable.tsx index 8e23db1..a5790a1 100644 --- a/src/react-sortable.tsx +++ b/src/react-sortable.tsx @@ -110,7 +110,7 @@ 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[], (child, index) => { - if (!child) return undefined + if (child===undefined) return undefined const item = list[index] || {}; const { className: prevClassName } = child.props; From 17878f737a2dbab93670487640b50c7854947cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 14 Jan 2022 09:06:39 +0100 Subject: [PATCH 3/3] Update src/react-sortable.tsx --- src/react-sortable.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/react-sortable.tsx b/src/react-sortable.tsx index a5790a1..2d505c1 100644 --- a/src/react-sortable.tsx +++ b/src/react-sortable.tsx @@ -110,7 +110,7 @@ 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[], (child, index) => { - if (child===undefined) return undefined + if (child === undefined) return undefined const item = list[index] || {}; const { className: prevClassName } = child.props;