Skip to content

Commit ebba994

Browse files
committed
Add cleanup function to registering the message listener
This cleanup function would never be called in normal operation, but if we do decide to add a dependency to this `useEffect`, this will ensure that only one listener is registered at a time.
1 parent d18e3dd commit ebba994

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

extensions/ql-vscode/src/view/variant-analysis/VariantAnalysis.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function VariantAnalysis({
6565
const [repoResults, setRepoResults] = useState<VariantAnalysisScannedRepositoryResult[]>(initialRepoResults);
6666

6767
useEffect(() => {
68-
window.addEventListener('message', (evt: MessageEvent) => {
68+
const listener = (evt: MessageEvent) => {
6969
if (evt.origin === window.origin) {
7070
const msg: ToVariantAnalysisMessage = evt.data;
7171
if (msg.t === 'setVariantAnalysis') {
@@ -89,7 +89,12 @@ export function VariantAnalysis({
8989
const origin = evt.origin.replace(/\n|\r/g, '');
9090
console.error(`Invalid event origin ${origin}`);
9191
}
92-
});
92+
};
93+
window.addEventListener('message', listener);
94+
95+
return () => {
96+
window.removeEventListener('message', listener);
97+
};
9398
}, []);
9499

95100
if (variantAnalysis?.actionsWorkflowRunId === undefined) {

0 commit comments

Comments
 (0)