mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-21 09:31:17 -08:00
fix pin concat crash (#848)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description <!-- Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change. --> Untested fix for #834 , just adds an additional check to make sure that we aren't trying to concat on an empty array which I think is likely what caused the crash. #### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. -->
This commit is contained in:
2 files changed
+24
-22
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Fixed crash when rendering some `m.room.pinned_events` timeline rows (old/malformed pin state edge case).
|
||||
@@ -1060,6 +1060,9 @@ export function useTimelineEventRenderer({
|
||||
const pinsRemoved =
|
||||
(prevPinned && pinned && prevPinned.filter((x: string) => !pinned.includes(x))) || [];
|
||||
|
||||
const pinPreviewIds = (pinsAdded ?? []).concat(...(pinsRemoved ?? []));
|
||||
const pinnedSet = new Set(pinned ?? []);
|
||||
|
||||
const timeJSX = (
|
||||
<Time
|
||||
ts={mEvent.getTs()}
|
||||
@@ -1104,28 +1107,22 @@ export function useTimelineEventRenderer({
|
||||
`has not changed the pins`) ||
|
||||
`:`}
|
||||
</Text>
|
||||
{(pinsAdded || pinsRemoved) &&
|
||||
pinsAdded
|
||||
.concat(...pinsRemoved)
|
||||
.slice(0, 4)
|
||||
.map((x: string) => (
|
||||
<Reply
|
||||
key={x}
|
||||
style={{ opacity: '80%' }}
|
||||
room={room}
|
||||
replyEventId={x}
|
||||
onClick={handleOpenReply}
|
||||
replyIcon={
|
||||
<>
|
||||
<Icon size="100" src={Icons.Pin} />
|
||||
<Icon
|
||||
size="100"
|
||||
src={pinned.includes(x) ? Icons.Plus : Icons.Minus}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
{pinPreviewIds.length > 0 &&
|
||||
pinPreviewIds.slice(0, 4).map((x: string) => (
|
||||
<Reply
|
||||
key={x}
|
||||
style={{ opacity: '80%' }}
|
||||
room={room}
|
||||
replyEventId={x}
|
||||
onClick={handleOpenReply}
|
||||
replyIcon={
|
||||
<>
|
||||
<Icon size="100" src={Icons.Pin} />
|
||||
<Icon size="100" src={pinnedSet.has(x) ? Icons.Plus : Icons.Minus} />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</Box>
|
||||
}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user