Skip to content

Commit b1385ce

Browse files
committed
fix: app hang when opening "New Chat" dialog
...or when opening "Add Members". Closes #5724. This is a follow-up to 8c18aa9 (#5725), issue #5723.
1 parent 8c18aa9 commit b1385ce

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

packages/frontend/src/components/dialogs/AddMember/AddMemberDialog.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function AddMemberDialog({
2626
const {
2727
contactIds,
2828
contactCache,
29+
isContactLoaded,
2930
loadContacts,
3031
queryStrIsValidEmail,
3132
refreshContacts,
@@ -55,6 +56,7 @@ export function AddMemberDialog({
5556

5657
contactIds,
5758
contactCache,
59+
isContactLoaded,
5860
loadContacts,
5961
refreshContacts,
6062

packages/frontend/src/components/dialogs/AddMember/AddMemberInnerDialog.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function AddMemberInnerDialog({
3232

3333
contactIds,
3434
contactCache,
35+
isContactLoaded,
3536
loadContacts,
3637
refreshContacts,
3738

@@ -47,6 +48,7 @@ export function AddMemberInnerDialog({
4748

4849
contactIds: number[]
4950
contactCache: { [id: number]: T.Contact | undefined }
51+
isContactLoaded: (index: number) => boolean
5052
loadContacts: (startIndex: number, stopIndex: number) => Promise<void>
5153
refreshContacts: () => void
5254

@@ -230,14 +232,9 @@ export function AddMemberInnerDialog({
230232
// with wrong indices.
231233
// See `CreateChatMain` component.
232234
loadMoreItems={loadContacts}
233-
// perf: consider using `isContactLoaded` from `useLazyLoadedContacts`
234-
// otherwise sometimes we might load the same contact twice (performance thing)
235-
// See https://github.com/bvaughn/react-window/issues/765
236235
isItemLoaded={index => {
237236
const isExtraItem = index >= contactIds.length
238-
return isExtraItem
239-
? true
240-
: contactCache[contactIds[index]] != undefined
237+
return isExtraItem ? true : isContactLoaded(index)
241238
}}
242239
// minimumBatchSize={100}
243240
>

packages/frontend/src/components/dialogs/CreateChat/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ function CreateChatMain(props: CreateChatMainProps) {
173173
const {
174174
contactIds,
175175
contactCache,
176+
isContactLoaded,
176177
loadContacts,
177178
queryStrIsValidEmail,
178179
refreshContacts,
@@ -366,15 +367,17 @@ function CreateChatMain(props: CreateChatMainProps) {
366367
contactIds.indexOf(contactsAndExtraItems[stopInd])
367368
)
368369
}}
369-
// perf: consider using `isContactLoaded` from `useLazyLoadedContacts`
370-
// otherwise sometimes we might load the same contact twice (performance thing)
371-
// See https://github.com/bvaughn/react-window/issues/765
372370
isItemLoaded={index => {
373371
const isExtraItem = contactsAndExtraItems[index] < -100
374372
if (isExtraItem) {
375373
return true
376374
}
377-
return contactCache[contactsAndExtraItems[index]] != undefined
375+
// Again, the indices are shifted
376+
// due to the existence of extra items.
377+
const indInContactIds = contactIds.indexOf(
378+
contactsAndExtraItems[index]
379+
)
380+
return isContactLoaded(indInContactIds)
378381
}}
379382
// minimumBatchSize={100}
380383
>

0 commit comments

Comments
 (0)