Skip to content

Commit

Permalink
fix: autoreload: use correct context within onclose() handler
Browse files Browse the repository at this point in the history
Old code ran the `onclose()` handler in the context (`this`) of the
websocket.  This is unwanted because the handler access attributes of
the `Client` object.

Use arrow function to keep `this`.

Signed-off-by: Enrico Scholz <[email protected]>
  • Loading branch information
ensc committed Jan 12, 2025
1 parent d4d92c4 commit 4becf1b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/autoreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
break;
}
};
ws.onclose = this.onclose;
ws.onclose = () => this.onclose();
}

onclose() {
Expand All @@ -102,7 +102,7 @@
// rebuilt on restart)
const ws = new WebSocket(this.url);
ws.onopen = () => window.location.reload();
ws.onclose = this.onclose;
ws.onclose = () => this.onclose();
},
this.poll_interval);
}
Expand Down

0 comments on commit 4becf1b

Please sign in to comment.