Describe the bug
The MessageComposerProvider unmount cleanup calls messageComposer.clear() unconditionally. If the channel is already disconnected (current user removed / channel deleted), clear() throws You can't use a channel after client.disconnect() was called.
Offending code — src/components/MessageComposer/MessageComposer.tsx (v14.10.0, L58–62):
useEffect(() => () => {
messageComposer.createDraft().finally(() => messageComposer.clear());
}, [messageComposer]);
Why it throws
notification.removed_from_channel / channel.deleted → stream-chat runs activeChannels[cid]._disconnect() → channel.disconnected = true.
- App tears down the active channel → this cleanup runs →
clear() → initState() → LinkPreviewsManager.enabled getter → channel.getConfig() → getClient() throws.
Same class as #2393 (guarded in #3227 for ChannelInner/ChannelList), but this composer-unmount path was missed.
To Reproduce
- As a member, open a channel with
MessageInput mounted.
- Get removed from it / delete it (server emits
notification.removed_from_channel / channel.deleted).
- Tear down the active channel (unmounts
Channel/MessageInput).
- Uncaught error thrown from the composer unmount cleanup.
Stack (abridged): getClient ← getConfig ← LinkPreviewsManager.enabled ← initState ← MessageComposer.clear ← MessageComposerProvider unmount effect.
Expected behavior
Unmounting the composer for an already-disconnected channel should not throw. Guard the cleanup on channel.disconnected, consistent with #3227.
Suggested fix
useEffect(() => () => {
if (messageComposer.channel.disconnected) return;
messageComposer.createDraft().finally(() => {
if (!messageComposer.channel.disconnected) messageComposer.clear();
});
}, [messageComposer]);
Package version
- stream-chat-react: 14.9.0 (offending code still present at v14.10.0)
- stream-chat-js: 9.50.2
Desktop: macOS, Chrome (latest)
Not present in 14.4.1; introduced by the createDraft().finally(() => clear()) unmount effect.
Describe the bug
The
MessageComposerProviderunmount cleanup callsmessageComposer.clear()unconditionally. If the channel is already disconnected (current user removed / channel deleted),clear()throwsYou can't use a channel after client.disconnect() was called.Offending code —
src/components/MessageComposer/MessageComposer.tsx(v14.10.0, L58–62):Why it throws
notification.removed_from_channel/channel.deleted→ stream-chat runsactiveChannels[cid]._disconnect()→channel.disconnected = true.clear()→initState()→LinkPreviewsManager.enabledgetter →channel.getConfig()→getClient()throws.Same class as #2393 (guarded in #3227 for
ChannelInner/ChannelList), but this composer-unmount path was missed.To Reproduce
MessageInputmounted.notification.removed_from_channel/channel.deleted).Channel/MessageInput).Stack (abridged):
getClient ← getConfig ← LinkPreviewsManager.enabled ← initState ← MessageComposer.clear ← MessageComposerProvider unmount effect.Expected behavior
Unmounting the composer for an already-disconnected channel should not throw. Guard the cleanup on
channel.disconnected, consistent with #3227.Suggested fix
Package version
Desktop: macOS, Chrome (latest)
Not present in 14.4.1; introduced by the
createDraft().finally(() => clear())unmount effect.