Skip to content

fix: prevent deleteUserMessages crash when hard-deleting a self-quoting message#1741

Merged
oliverlaz merged 1 commit into
masterfrom
fix/delete-user-messages-self-quote-hard-delete-crash
May 12, 2026
Merged

fix: prevent deleteUserMessages crash when hard-deleting a self-quoting message#1741
oliverlaz merged 1 commit into
masterfrom
fix/delete-user-messages-self-quote-hard-delete-crash

Conversation

@oliverlaz
Copy link
Copy Markdown
Member

@oliverlaz oliverlaz commented May 12, 2026

Description of the changes, What, Why and How?

Closes #1736.

When the backend hard-deletes a user whose cached messages include one that quotes another message from the same user, deleteUserMessages was throwing Cannot read property 'cid' of undefined mid-loop, which aborted the rest of the dispatchEvent chain (silently dropping downstream listeners).

The loop has two branches:

  • A (message.user.id === user.id) replaces messages[i] with the stripped hard-delete shape, which intentionally has no quoted_message field.
  • B (message.quoted_message?.user?.id === user.id) then reads messages[i].quoted_message and hands it to toDeletedMessage.

When both fire on the same message (i.e. a self-quote on hard-delete), B was reading an undefined quoted_message left behind by A. Fix is a one-line guard so B only runs when the field is still there. Soft-delete and cross-user-quote paths are unaffected, they preserve messages[i].quoted_message and continue to work as before.

…ng message

When a hard-deleted user's cached messages include one that quotes another message
from the same user, deleteUserMessages threw "Cannot read property 'cid' of
undefined" mid-iteration and aborted the surrounding dispatchEvent chain. The first
loop branch replaced messages[i] with the stripped hard-delete shape (no
quoted_message field); the second branch then read messages[i].quoted_message
(now undefined) and passed it into toDeletedMessage.

Guard the second branch so it skips when the parent's quoted_message has already
been stripped. Every other code path stays byte-identical.

Closes #1736
@github-actions
Copy link
Copy Markdown
Contributor

Size Change: +21 B (+0.01%)

Total Size: 381 kB

📦 View Changed
Filename Size Change
dist/cjs/index.browser.js 127 kB +7 B (+0.01%)
dist/cjs/index.node.js 128 kB +7 B (+0.01%)
dist/esm/index.mjs 126 kB +7 B (+0.01%)

compressed-size-action

@oliverlaz oliverlaz merged commit b2a00bb into master May 12, 2026
6 checks passed
@oliverlaz oliverlaz deleted the fix/delete-user-messages-self-quote-hard-delete-crash branch May 12, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deleteUserMessages crashes with "Cannot read property 'cid' of undefined" when hard-deleting a message that quotes another message from the same user

2 participants