Skip to content

Commit

Permalink
fix: _shouldReattachToSetOptions implementation
Browse files Browse the repository at this point in the history
`_shouldReattachToSetOptions` used `this.params` and `this.modes` when checking channel options, but these fields are only set after the channel is attached. This created a bug when `RealtimeChannels.get()` is invoked during `attaching` state.
  • Loading branch information
ttypic committed Feb 5, 2024
1 parent a32e5cb commit a0b4fea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
12 changes: 6 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ module.exports = {
{
files: ["**/*.{ts,tsx}"],
rules: {
"comma-dangle": ["error", "only-multiline"],
"@typescript-eslint/no-unused-vars": ["error"],

// TypeScript already enforces these rules better than any eslint setup can
"no-undef": "off",
"no-dupe-class-members": "off",
"comma-dangle": ["error", "only-multiline"],
"@typescript-eslint/no-unused-vars": ["error", { "varsIgnorePattern": "^_" }],
// TypeScript already enforces these rules better than any eslint setup can
"no-undef": "off",
"no-dupe-class-members": "off",
"no-unused-vars": "off",
},
},
{
Expand Down
18 changes: 12 additions & 6 deletions src/common/lib/client/realtimechannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,20 @@ class RealtimeChannel extends Channel {
return false;
}
if (options?.params) {
// Don't check against the `agent` param - it isn't returned in the ATTACHED message
const requestedParams = Object.assign({}, options.params);
delete requestedParams.agent;
if (Object.keys(requestedParams).length !== 0 && !this.params) {
// Don't check against the `agent` param
const requestedParams = omitAgent(options.params);
const existingParams = omitAgent(this.channelOptions.params);

if (Object.keys(requestedParams).length !== Object.keys(existingParams).length) {
return true;
}

if (this.params && !Utils.shallowEquals(this.params, requestedParams)) {
if (!Utils.shallowEquals(existingParams, requestedParams)) {
return true;
}
}
if (options?.modes) {
if (!this.modes || !Utils.arrEquals(options.modes, this.modes)) {
if (!this.channelOptions.modes || !Utils.arrEquals(options.modes, this.channelOptions.modes)) {
return true;
}
}
Expand Down Expand Up @@ -1052,4 +1053,9 @@ class RealtimeChannel extends Channel {
}
}

function omitAgent(channelParams?: API.Types.ChannelParams) {
const { agent: _, ...paramsWithoutAgent } = channelParams || {};
return paramsWithoutAgent;
}

export default RealtimeChannel;

0 comments on commit a0b4fea

Please sign in to comment.