Skip to content

Commit da9cb86

Browse files
mariobuikhuizenmaartenbreddels
authored andcommitted
fix: echos from other clients are not unexpected
1 parent 04d5714 commit da9cb86

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

packages/base/src/widget.ts

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -233,33 +233,34 @@ export class WidgetModel extends Backbone.Model {
233233
if (msg.parent_header && data.echo) {
234234
const msgId = (msg.parent_header as any).msg_id;
235235
// for echoed attributes we ignore old updates
236-
data.echo.forEach((attrName: string) => {
237-
if (!Object.keys(this.attrLastUpdateMsgId).includes(attrName)) {
238-
console.error(`Kernel send unexpected echo for ${attrName}.`);
239-
}
240-
// we don't care about the old messages, only the one send with the
241-
// last msgId
242-
const isOldMessage =
243-
this.attrLastUpdateMsgId[attrName] !== msgId;
244-
if (isOldMessage) {
245-
// get rid of old updates
246-
delete state[attrName];
247-
} else {
248-
// we got our confirmation, from now on we accept everything
249-
delete this.attrLastUpdateMsgId[attrName];
250-
// except, we plan to send out a new state for this soon, so we will
251-
// also ignore the update for this property
252-
if (
253-
this._msg_buffer !== null &&
254-
Object.prototype.hasOwnProperty.call(
255-
this._msg_buffer,
256-
attrName
257-
)
258-
) {
236+
data.echo
237+
.filter((attrName: string) =>
238+
Object.keys(this.attrLastUpdateMsgId).includes(attrName)
239+
)
240+
.forEach((attrName: string) => {
241+
// we don't care about the old messages, only the one send with the
242+
// last msgId
243+
const isOldMessage =
244+
this.attrLastUpdateMsgId[attrName] !== msgId;
245+
if (isOldMessage) {
246+
// get rid of old updates
259247
delete state[attrName];
248+
} else {
249+
// we got our confirmation, from now on we accept everything
250+
delete this.attrLastUpdateMsgId[attrName];
251+
// except, we plan to send out a new state for this soon, so we will
252+
// also ignore the update for this property
253+
if (
254+
this._msg_buffer !== null &&
255+
Object.prototype.hasOwnProperty.call(
256+
this._msg_buffer,
257+
attrName
258+
)
259+
) {
260+
delete state[attrName];
261+
}
260262
}
261-
}
262-
});
263+
});
263264
}
264265
return (this.constructor as typeof WidgetModel)._deserialize_state(
265266
state,

0 commit comments

Comments
 (0)