Skip to content

Commit 521128d

Browse files
committed
fix(logstream): clear logstream reference on cleanup
Set the logstream property to undefined during cleanup to prevent potential memory leaks or stale references. Also, adjust the callback invocation in modify for clearer structure while keeping the same behavior.
1 parent 9ba6ce5 commit 521128d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app/modifiers/logstream-did-update.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface Signature {
1717
function cleanup(instance: LogstreamDidUpdateModifier) {
1818
if (instance.logstream) {
1919
instance.logstream.unsubscribe();
20+
instance.logstream = undefined;
2021
}
2122
}
2223

@@ -34,7 +35,10 @@ export default class LogstreamDidUpdateModifier extends Modifier<Signature> {
3435
modify(_element: HTMLElement, [callback, logstreamId]: Signature['Args']['Positional']) {
3536
cleanup(this);
3637

37-
this.logstream = new Logstream(logstreamId, this.actionCableConsumer, this.store, () => callback(this.logstream!));
38+
this.logstream = new Logstream(logstreamId, this.actionCableConsumer, this.store, () => {
39+
callback(this.logstream!);
40+
});
41+
3842
this.logstream.subscribe();
3943
}
4044
}

0 commit comments

Comments
 (0)