Skip to content

Commit d871de0

Browse files
committed
fix: improve channel options reattachment logic
This internal change makes the client more selective about which options provided to `channels.get` will be interpreted as requiring reattachment. More precisely, the channel params and modes will now be shallow compared to existing params and modes, and only if they differ will the call the `chnanels.get` throw an error (, provided of course that the channel is already attached or attaching).
1 parent a1271e5 commit d871de0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/common/lib/client/realtimechannel.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,20 @@ class RealtimeChannel extends Channel {
185185
}
186186

187187
_shouldReattachToSetOptions(options?: API.Types.ChannelOptions) {
188-
return (this.state === 'attached' || this.state === 'attaching') && (options?.params || options?.modes);
188+
if (!(this.state === 'attached' || this.state === 'attaching')) {
189+
return false;
190+
}
191+
if (options?.params) {
192+
if (!this.params || !Utils.shallowEquals(this.params, options.params)) {
193+
return true;
194+
}
195+
}
196+
if (options?.modes) {
197+
if (!this.modes || !Utils.arrEquals(options.modes, this.modes)) {
198+
return true;
199+
}
200+
}
201+
return false;
189202
}
190203

191204
publish(...args: any[]): void | Promise<void> {

0 commit comments

Comments
 (0)