From c9866fe6c7ec6f628d50cb0650706dc17acfa45d Mon Sep 17 00:00:00 2001 From: thecodrr Date: Tue, 21 Apr 2020 12:42:58 +0500 Subject: [PATCH] fix: crash when an item was removed from Virtuouso This was a pesky bug. Basically the `props.items.length` did not get updated which resulted in the `index` being always one greater than actual. Since `index[out-of-range]` is `undefined` in JS, the app crashed as it could not find any prop. Very pesky. Fixed it however. --- apps/web/src/components/list-container/index.js | 6 +++++- apps/web/src/components/note/index.js | 2 -- apps/web/src/views/Home.js | 9 +++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/web/src/components/list-container/index.js b/apps/web/src/components/list-container/index.js index 729dd820a..c23dff686 100644 --- a/apps/web/src/components/list-container/index.js +++ b/apps/web/src/components/list-container/index.js @@ -44,7 +44,11 @@ function ListContainer(props) { overflowX: "hidden", }} totalCount={props.items.length} - item={(index) => props.item(index, props.items[index])} + item={(index) => { + const item = props.items[index]; + if (!item) return null; + return props.item(index, item); + }} /> ) : null} diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js index fec23c352..cff0b6e2a 100644 --- a/apps/web/src/components/note/index.js +++ b/apps/web/src/components/note/index.js @@ -163,8 +163,6 @@ export default React.memo(Note, function (prevProps, nextProps) { const prevItem = prevProps.item; const nextItem = nextProps.item; - // do not update if the item was removed - if (!prevItem || !nextItem) return true; return ( prevItem.pinned === nextItem.pinned && prevItem.favorite === nextItem.favorite && diff --git a/apps/web/src/views/Home.js b/apps/web/src/views/Home.js index e279281ed..4a0f5cccc 100644 --- a/apps/web/src/views/Home.js +++ b/apps/web/src/views/Home.js @@ -42,11 +42,12 @@ function Home() { ); }} - item={(index, groupIndex) => - notes.groupCounts[groupIndex] && ( + item={(index, groupIndex) => { + if (!notes.groupCounts[groupIndex] || !notes.items[index]) return; + return ( - ) - } + ); + }} /> );