Skip to content

bug: MessageComposerProvider unmount cleanup calls messageComposer.clear() on a disconnected channel → "You can't use a channel after client.disconnect() was called" #3248

Description

@minhth1529

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 codesrc/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

  1. As a member, open a channel with MessageInput mounted.
  2. Get removed from it / delete it (server emits notification.removed_from_channel / channel.deleted).
  3. Tear down the active channel (unmounts Channel/MessageInput).
  4. 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.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions